fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct polygon
  7. {
  8. int poly_no;
  9. vector<int> x;
  10. vector<int> y;
  11. double area;
  12. };
  13.  
  14. bool compareArea(polygon p1, polygon p2) //true is p1<p2
  15. {
  16. if(p1.area <= p2.area) return true;
  17. return false;
  18. }
  19.  
  20. int counter[100010];
  21.  
  22. int main()
  23. {
  24. ios_base::sync_with_stdio(false);
  25. int t, nopols, nopts;
  26. cin>>t;
  27. while(t--)
  28. {
  29. cin>>nopols;
  30. polygon poly[nopols];
  31. for(int i=0;i<nopols; i++)
  32. {
  33. poly[i].poly_no = i;
  34. cin>>nopts;
  35. poly[i].x.clear();
  36. poly[i].y.clear();
  37. int tx, ty;
  38. for(int j=0; j<nopts; j++)
  39. {
  40. cin>>tx>>ty;
  41. poly[i].x.push_back(tx);
  42. poly[i].y.push_back(ty);
  43. }
  44. double temparea=0;
  45. int k = nopts-1;
  46. for(int j=0; j<nopts; j++)
  47. {
  48. temparea += (poly[i].x[k] + poly[i].x[j])*(poly[i].y[j] - poly[i].y[k]);
  49. k=j;
  50. }
  51. poly[i].area = temparea/2.0;
  52. if(poly[i].area<0) poly[i].area = -poly[i].area;
  53. //cout<<poly[i].area<<" ";
  54. }
  55.  
  56. sort(poly, poly+nopols, compareArea);
  57.  
  58. for(int i=0; i<nopols; i++) counter[poly[i].poly_no]=i;
  59. for(int i=0; i<nopols; i++){ cout<<counter[i]<<" ";counter[i]=0;}
  60. cout<<"\n";
  61.  
  62. }
  63. return 0;
  64. }
Success #stdin #stdout 0s 3640KB
stdin
1
3
6
-2 2 -1 1 2 2 2 -1 1 -2 -2 -2
3
-1 -1 1 -1 1 1
4
3 3 -3 3 -3 -3 3 -3
stdout
1 0 2