AlexandruT

granita - infoarena.ro

Jan 27th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. struct interval
  7. {
  8.     int x, y;
  9. };
  10. interval a[16005];
  11.  
  12. inline bool cmp(const interval A, const interval B)
  13. {
  14.     if (A.x == B.x)
  15.         return A.y < B.y;
  16.     return A.x < B.x;
  17. }
  18.  
  19. int main()
  20. {
  21.     int n, i, cnt, x1, y1;
  22.     ifstream fin("granita.in");
  23.     fin >> n;
  24.     for(i = 1; i <= n; i++)
  25.         fin >> a[i].x >> a[i].y;
  26.     sort(a + 1, a + n + 1, cmp);
  27.     fin.close();
  28.     cnt = 0;
  29.     x1 = a[1].x;
  30.     y1 = a[1].y;
  31.     for(i = 2; i <= n; i++)
  32.     {
  33.         if(x1 < a[i].x && y1 > a[i].y) cnt++;
  34.         else
  35.         {
  36.             x1 = a[i].x;
  37.             y1 = a[i].y;
  38.         }
  39.     }
  40.     ofstream fout("granita.out");
  41.     fout << cnt << "\n";
  42.     fout.close();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment