#include #include #include #include using namespace std; struct Post; struct Cesta { Post* kam; bool pouzita; Cesta(Post *p):kam(p),pouzita(false){} }; struct Post { int x; int y; bool boltu; Post(int xx, int yy):x(xx),y(yy),boltu(false){} Cesta* cesta[2][2]; }; bool podla_xy(const Post* a, const Post* b) { if(a->x < b->x) return true; if(a->x == b->x && a->y < b->y) return true; return false; }; bool podla_yx(const Post* a, const Post* b) { if(a->y < b->y) return true; if(a->y == b->y && a->x < b->x) return true; return false; }; vector post; vector ukpost; int main() { while(1) { int p; cin>>p; if(p==0) return 0; post.clear(); ukpost.clear(); for(int i=0;i> x >> y; post.push_back(Post(x,y)); } for(int i=0;ix << " "<< ukpost[i]->y << ":" << endl; if(i>0 && ukpost[i-1]->x == ukpost[i]->x ) { ukpost[i]->cesta[0][0] = new Cesta(ukpost[i-1]); // cout<<"hore je"<cesta[0][0] = 0; if(ix == ukpost[i]->x ) { ukpost[i]->cesta[0][1] = new Cesta(ukpost[i+1]); // cout<<"dole je"<cesta[0][1] = 0; } sort(ukpost.begin(), ukpost.end(), podla_yx ); for(int i=0;ix << " "<< ukpost[i]->y << ":" << endl; if(i>0 && ukpost[i-1]->y == ukpost[i]->y ) { ukpost[i]->cesta[1][1] = new Cesta(ukpost[i-1]); // cout<<"vlavo je"<cesta[1][1] =0; if(iy == ukpost[i]->y ) { ukpost[i]->cesta[1][0] = new Cesta(ukpost[i+1]); // cout<<"vpravo je"<cesta[1][0] = 0; } sort(ukpost.begin(), ukpost.end(), podla_xy ); Post* kdesme = ukpost[0]; int smer = 1; int dlzka=0; while(1) { //cout << "Sme v "<< kdesme->x << " "<< kdesme->y ; Post *oldkdesme = kdesme; if( kdesme->cesta[smer][0] !=0 && kdesme->cesta[smer][0]->pouzita==false && kdesme->cesta[smer][0]->kam->boltu==false) { Post* kam = kdesme->cesta[smer][0]->kam; kdesme->cesta[smer][0]->pouzita=true; kam->cesta[smer][1]->pouzita=true; kdesme=kam; kam->boltu = true; //cout<< " ideme " << ((smer==0)?"hore":"doprava") <cesta[smer][1] !=0 && kdesme->cesta[smer][1]->pouzita==false && kdesme->cesta[smer][1]->kam->boltu==false) { Post* kam = kdesme->cesta[smer][1]->kam; kdesme->cesta[smer][1]->pouzita=true; kam->cesta[smer][0]->pouzita=true; kdesme=kam; //cout<< " ideme " << ((smer==0)?"dole":"dolava") <boltu = true; } else break; dlzka+=abs(oldkdesme->x - kdesme->x); dlzka+=abs(oldkdesme->y - kdesme->y); smer=(smer+1)%2; } cout<<"The length of fence will be "<