Pagini recente » Cod sursa (job #3121589) | Cod sursa (job #3137146) | Cod sursa (job #2449123) | Cod sursa (job #1029139) | Cod sursa (job #1386355)
#include<fstream>
#include<vector>
using namespace std;
typedef double var;
ifstream fin("poligon.in");
ofstream fout("poligon.out");
struct Punct {
var x, y;
Punct(var a, var b) {
x = a;
y = b;
}
};
bool intersect(Punct a, Punct b, Punct c, Punct d) {
var x1 = a.x, x2 = b.x, x3 = c.x, x4 = d.x;
var y1 = a.y, y2 = b.y, y3 = c.y, y4 = d.y;
var A1 = y2-y1, B1 = x1-x2, C1 = y1*x2-y2*x1;
var A2 = y4-y3, B2 = x3-x4, C2 = y3*x4-y4*x3;
//fout<<A1<<" "<<B1<<" "<<C1<<'\n';
//fout<<A2<<" "<<B2<<" "<<C2<<'\n';
var delta = B1*A2 - B2*A1;
if(delta == 0) return false;
var x = (C1*B2 - C2*B1)/delta;
var y = (C2*A1 - C1*A2)/delta;
if(x1 > x2) swap(x1, x2);
if(y1 > y2) swap(y1, y2);
if(x3 > x4) swap(x3, x4);
if(y3 > y4) swap(y3, y4);
return (y1 <= y && y <= y2 && x1 <= x && x <= x2 &&
y3 <= y && y <= y4 && x3 <= x && x <= x4);
//fout<<x<<" "<<y<<'\n';
//ecuatia dreptei ab
}
vector<Punct> Poligon;
int main() {
int n, m;
var x, y;
fin>>n>>m;
for(int i=1; i<=n; i++) {
fin>>x>>y;
Poligon.push_back(Punct(x, y));
}
Punct INF[] = {
Punct (666013, 100003),
Punct (3298712, 20983129),
Punct (2918242, 1230981)
};
int sum = 0;
for(int i=1; i<=m; i++) {
int count = 0;
fin>>x>>y;
Punct p(x, y);
for(int j=1; j<n; j++) {
int res = 0;
for(int t=0; t<3; t++) {
res += intersect(p, INF[t], Poligon[j], Poligon[j+1]);
}
count += (res >= 2);
}
int res = 0;
for(int t=0; t<3; t++) {
res += intersect(p, INF[t], Poligon[0], Poligon[n-1]);
}
count += (res >= 2);
sum += (count % 2);
}
fout<<sum;
return 0;
}