fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct point
  7. {
  8. int x;
  9. int y;
  10. };
  11. bool cmpx(point a,point b)
  12. {
  13. return a.x<b.x;
  14. }
  15. bool cmpy(point a,point b)
  16. {
  17. return a.y<b.y;
  18. }
  19. vector <point> vec;
  20. int szuk(double x,double y)
  21. {
  22. int max,min,tab[4]={0,0,0,0},i;
  23.  
  24. for(i=0;i<vec.size();i++)
  25. {
  26. if(vec[i].x<x) //cw1 i 2
  27. {
  28. if(vec[i].y>y)
  29. tab[0]++;
  30. else
  31. tab[1]++;
  32. }
  33. else //cw 3 i 4;
  34. {
  35. if(vec[i].y>y)
  36. tab[2]++;
  37. else
  38. tab[3]++;
  39. }
  40. }
  41. sort(tab,tab+4);
  42. min=tab[0]; max=tab[3];
  43.  
  44. //cout<<"max="<<max<<" "<<min<<endl;
  45. return max-min;
  46. }
  47. int main() {
  48. // your code goes here
  49. int t,i,j,maxx,maxy,minx,miny;
  50. double pomx1,pomx2,pomy1,pomy2;
  51. int pom,wyn,min=100000000;
  52. point pkt;
  53.  
  54. cin>>t;
  55. for(i=0;i<t;i++)
  56. {
  57. cin>>pkt.x>>pkt.y;
  58. vec.push_back(pkt);
  59. }
  60. sort(vec.begin(),vec.end(),cmpx); //sortuje po x;
  61. pom=t/2; //biore srodkowy elem
  62. //cout<<vec[pom].x<<endl;
  63. i=vec[pom].x;
  64. pomx1=vec[pom].x-0.5;
  65. pomx2=vec[pom].x+0.5;
  66. //-------------teraz dla y
  67. sort(vec.begin(),vec.end(),cmpy); //powtarzam dla y;
  68. pom=t/2;
  69. //cout<<vec[pom].y<<endl;
  70. i=vec[pom].y;
  71. pomy1=vec[pom].y-0.5;
  72. pomy2=vec[pom].y+0.5;
  73.  
  74. cout<<pomx1<<" "<<pomx2<<" "<<pomy1<<" "<<pomy2<<endl;
  75. //------------------------------------------teraz szukanie wyniku z 4 mozliwosci
  76. wyn=szuk(pomx1,pomy1);
  77. if(wyn<min) min=wyn;
  78. wyn=szuk(pomx1,pomy2);
  79. if(wyn<min) min=wyn;
  80.  
  81. wyn=szuk(pomx2,pomy1);
  82. if(wyn<min) min=wyn;
  83. wyn=szuk(pomx2,pomy2);
  84. if(wyn<min) min=wyn;
  85. cout<<min;
  86. return 0;
  87. }
Success #stdin #stdout 0.01s 5392KB
stdin
10
10 5
1 3
6 7
6 6
6 1
7 1
4 7
1 7
9 8
3 10
16
4 4
4 2
6 2
6 4
1 5
2 5
3 5
6 5
7 5
8 5
8 2
8 1
8 0
1 2
1 1
1 0
1 1
3 1
3 3
1 4
1 5
8
1 0
1 1
1 2
1 5
1 6
2 1
2 6
2 0
0 0
0 1
1 0
1 1
4 6
4 5
5 5
5 6
3 4
4 3
5 3
3 3 
4 4
3 1
3 3
1 5
stdout
5.5 6.5 6.5 7.5
3