Advertisement
Guest User

Untitled

a guest
Feb 8th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. /*
  2. ID: SkyHawk
  3. PROG: planting
  4. LANG: C++
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <iostream>
  9. #include <list>
  10. #include <string>
  11. #include <vector>
  12. #include <iterator>
  13. #include <algorithm>
  14. #include <cmath>
  15. #include <cstring>
  16. #include <set>
  17. #include <list>
  18. #include <queue>
  19.  
  20. using namespace std;
  21.  
  22. #define FOR(i,n) for(int i = 0;i < n;++i)
  23. #define PII pair<int,int>
  24.  
  25. vector<pair<PII ,PII > > rect;
  26.  
  27. int used[21];
  28.  
  29. int main(int argc, char** argv)
  30. {
  31.     freopen("planting.in","r",stdin);
  32.     freopen("planting.out","w",stdout);
  33.     int n;
  34.     cin >> n;
  35.     FOR(i,n)
  36.     {
  37.         int x1,y1,x2,y2;
  38.         cin >> x1 >> y1 >> x2 >> y2;
  39.         rect.push_back(make_pair(PII(x1,0), PII(y1,y2)));
  40.         rect.push_back(make_pair(PII(x2,1), PII(y1,y2)));
  41.     }
  42.     sort(rect.begin(),rect.end());
  43.     int h=0,x=-10001;
  44.     long long s = 0;
  45.     FOR(i,2*n)
  46.     {
  47.         if(rect[i].first.second == 0)
  48.         {
  49.             s+=h*(rect[i].first.first-x);
  50.             used[i] = 1;
  51.             h = 0;
  52.             for(int j = -10001;j<=10001;++j)
  53.                 FOR(k,n)
  54.                 {
  55.                     if((used[k]) && (j>=rect[k].second.second &&
  56.                         j<rect[k].second.first))
  57.                     {
  58.                         h++;
  59.                         break;
  60.                     }
  61.                 }
  62.             x = rect[i].first.first;
  63.         }
  64.         else
  65.         {
  66.             s+=h*(rect[i].first.first-x);
  67.             FOR(j,i)
  68.                 if(used[j] && rect[j].second == rect[i].second)
  69.                 {
  70.                     used[j] = 0;
  71.                     break;
  72.                 }
  73.             h = 0;
  74.             for(int j = -10001;j<=10001;++j)
  75.                 FOR(k,n)
  76.                 {
  77.                     if((used[k]) && (j>=rect[k].second.second &&
  78.                         j<rect[k].second.first))
  79.                     {
  80.                         h++;
  81.                         break;
  82.                     }
  83.                 }
  84.             x = rect[i].first.first;
  85.                
  86.         }  
  87.                
  88.     }
  89.     cout << s<< endl;
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement