Created
June 14, 2016 12:08
-
-
Save masyax/99a4cef17626bb1957b87c7da37cc235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <cmath> | |
#include <climits> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <fstream> | |
#include <iostream> | |
#include <list> | |
#include <map> | |
#include <queue> | |
#include <set> | |
#include <sstream> | |
#include <stack> | |
#include <string> | |
#include <vector> | |
#include <cassert> | |
#include <functional> | |
using namespace std; | |
#define LOG(...) printf(__VA_ARGS__) | |
//#define LOG(...) | |
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) | |
#define REP(i,n) for(int i=0;i<(int)(n);++i) | |
#define ALL(a) (a).begin(),(a).end() | |
#define RALL(a) (a).rbegin(),(a).rend() | |
#define EXIST(s,e) ((s).find(e)!=(s).end()) | |
#define SORT(c) sort((c).begin(),(c).end()) | |
#define RSORT(c) sort((c).rbegin(),(c).rend()) | |
#define CLR(a) memset((a), 0 ,sizeof(a)) | |
typedef long long ll; | |
typedef unsigned long long ull; | |
typedef vector<bool> vb; | |
typedef vector<int> vi; | |
typedef vector<ll> vll; | |
typedef vector<vb> vvb; | |
typedef vector<vi> vvi; | |
typedef vector<vll> vvll; | |
typedef pair<int, int> pii; | |
typedef pair<ll, ll> pll; | |
const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 }; | |
int main() { | |
int n; | |
while (cin >> n, n) { | |
vector<pair<long long, long long>> zahyo(n); | |
vector<ll> x; | |
vector<ll> y; | |
REP(i, n) { | |
cin >> zahyo[i].second >> zahyo[i].first; | |
x.push_back(zahyo[i].second); | |
y.push_back(zahyo[i].first); | |
} | |
vector<pair<long long, long long>> curtain(4); | |
REP(i, 4) { | |
cin >> curtain[i].second >> curtain[i].first; | |
x.push_back(curtain[i].second); | |
y.push_back(curtain[i].first); | |
} | |
SORT(x); | |
SORT(y); | |
x.erase(unique(x.begin(), x.end()), x.end()); | |
y.erase(unique(y.begin(), y.end()), y.end()); | |
map<ll, int> zipx; | |
map<ll, int> zipy; | |
REP(i, x.size()) | |
zipx[x[i]] = i; | |
REP(i, y.size()) | |
zipy[y[i]] = i; | |
vvb tate(y.size()-1,vb(x.size())); | |
REP(i, n) { | |
int sy = zipy[zahyo[(i + 1) % n].first] - zipy[zahyo[i].first]; | |
int sx = zipx[zahyo[(i + 1) % n].second] - zipx[zahyo[i].second]; | |
if (sx == 0) { | |
REP(j, abs(sy)) { | |
tate[min(zipy[zahyo[(i + 1) % n].first], zipy[zahyo[i].first]) + j][zipx[zahyo[(i + 1) % n].second]] = true; | |
} | |
} | |
} | |
int minx = 400; | |
int miny = 400; | |
int maxx = -400; | |
int maxy = -400; | |
REP(i, 4) { | |
minx = min(minx, zipx[curtain[i].second]); | |
miny = min(miny, zipy[curtain[i].first]); | |
maxx = max(maxx, zipx[curtain[i].second]); | |
maxy = max(maxy, zipy[curtain[i].first]); | |
} | |
long long ans = 0; | |
REP(i, y.size()-1) { | |
bool exbox = false; | |
int idx = 0; | |
REP(j, x.size()-1) { | |
if (tate[i][j]) { | |
exbox = !exbox; | |
idx++; | |
} | |
if (exbox && !(miny <= i&&i < maxy&&minx <= j&&j < maxx)) | |
ans += (x[j + 1] - x[j])*(y[i + 1] - y[i]); | |
} | |
} | |
cout << ans << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment