int main() { #if DEBUG freopen("E:\\nyist_008.in", "r" ,stdin); freopen("E:\\nyist_008.out", "w", stdout); #endif VR vec; Rect rt; int testCases, nNums; scanf("%d", &testCases); while (testCases--) { vec.clear(); scanf("%d", &nNums); for (int i = 0; i < nNums; ++i) { scanf("%d %d %d", &rt.number, &rt.length, &rt.width); if (rt.length < rt.width) swap(rt.length, rt.width); vec.push_back(rt); } sort(vec.begin(), vec.end(), compare_1); for (VR::size_type ix = 0; ix < vec.size(); ++ix) printf("%d %d %d\n", vec[ix].number, vec[ix].length, vec[ix].width); unique(vec.begin(), vec.end(), compare_2); /* for (VR::size_type ix = 0; ix < vec.size(); ++ix) printf("%d %d %d\n", vec[ix].number, vec[ix].length, vec[ix].width); */ }// End of while return 0; }
void split_route(vector<Segment> &vs,VR &nodes,int idx, int n1, int n2){ ParamEdge e=vs[idx].edge; debugline(e.from(),e.to(),255,0,0,true); double minp=DBL_MAX; int minidx=-1; for (int j=0,n=nodes.size();j<n;j++){ if (j==n1 || j==n2) continue; if (e.cross(nodes[j])){ if (nodes[j].contains(e.from())) continue; if (nodes[j].contains(e.to())) continue; double p=e.cross_param_smallest(nodes[j]); if (p<minp){ minp=p; minidx=j; } } } if (minidx<0) return ; Point dc=e.dist_vec(nodes[minidx].center()); if (dc.is_null()){ dc=to_left(e.unit(),PI/2); // minidxust choose a side } VP pts; Point r=e.dist_vec(nodes[minidx].TL()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TL()); r=e.dist_vec(nodes[minidx].TR()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].TR()); r=e.dist_vec(nodes[minidx].BL()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BL()); r=e.dist_vec(nodes[minidx].BR()); if (scalar(r,dc)<0) pts.push_back(nodes[minidx].BR()); if (pts.size()==0) { printf("Ups, no points on smaller side of edge/node cut area"); return; } if (pts.size()>2 ) throw "expected 1 or 2 points"; vector<Segment> vsnew; int idxlast=idx+1; if (pts.size()==1){ vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false)); vsnew.push_back(Segment(ParamEdge(pts[0],e.to()),false,vs[idx].last)); } else if (pts.size()==2) { if (norm(pts[0]-e.from())>norm(pts[1]-e.from())){ // do nearest point first swap(pts[0],pts[1]); } vsnew.push_back(Segment(ParamEdge(e.from(),pts[0]),vs[idx].first,false)); vsnew.push_back(Segment(ParamEdge(pts[0],pts[1]),false,false)); vsnew.push_back(Segment(ParamEdge(pts[1],e.to()),false,vs[idx].last)); idxlast++; } vs.erase(vs.begin()+idx); vs.insert(vs.begin()+idx,vsnew.begin(),vsnew.end()); split_route(vs,nodes,idxlast,minidx,n2); split_route(vs,nodes,idx,n1,minidx); // new overlaps could be introduced after makeing a kink into the line }