Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: SkyHawk
- PROG: planting
- LANG: C++
- */
- #include <stdio.h>
- #include <iostream>
- #include <list>
- #include <string>
- #include <vector>
- #include <iterator>
- #include <algorithm>
- #include <cmath>
- #include <cstring>
- #include <set>
- #include <list>
- #include <queue>
- using namespace std;
- #define FOR(i,n) for(int i = 0;i < n;++i)
- #define PII pair<int,int>
- vector<pair<PII ,PII > > rect;
- int used[21];
- int main(int argc, char** argv)
- {
- freopen("planting.in","r",stdin);
- freopen("planting.out","w",stdout);
- int n;
- cin >> n;
- FOR(i,n)
- {
- int x1,y1,x2,y2;
- cin >> x1 >> y1 >> x2 >> y2;
- rect.push_back(make_pair(PII(x1,0), PII(y1,y2)));
- rect.push_back(make_pair(PII(x2,1), PII(y1,y2)));
- }
- sort(rect.begin(),rect.end());
- int h=0,x=-10001;
- long long s = 0;
- FOR(i,2*n)
- {
- if(rect[i].first.second == 0)
- {
- s+=h*(rect[i].first.first-x);
- used[i] = 1;
- h = 0;
- for(int j = -10001;j<=10001;++j)
- FOR(k,n)
- {
- if((used[k]) && (j>=rect[k].second.second &&
- j<rect[k].second.first))
- {
- h++;
- break;
- }
- }
- x = rect[i].first.first;
- }
- else
- {
- s+=h*(rect[i].first.first-x);
- FOR(j,i)
- if(used[j] && rect[j].second == rect[i].second)
- {
- used[j] = 0;
- break;
- }
- h = 0;
- for(int j = -10001;j<=10001;++j)
- FOR(k,n)
- {
- if((used[k]) && (j>=rect[k].second.second &&
- j<rect[k].second.first))
- {
- h++;
- break;
- }
- }
- x = rect[i].first.first;
- }
- }
- cout << s<< endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement