poj2318
题意:把一个矩形划分成n部分,再给出一堆点,求每个部分内落入了多少点
sol attempt1:暴力
注意每个polygon中的点要按笔画的顺序排列好。还有就是有的点可能落在了upper or lower edge,稍微处理一下(ans==1 or 2都算)
TLE了 -_-||
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<climits>
#include<complex>
#define mp make_pair
#define pb push_back
#define MAXN 5010
using namespace std;
const double eps=1e-;
const double pi=acos(-1.0);
const double inf=1e20;
const int maxp=; //多边形内点的数量,注意按需求调整 int sgn(double x)
{
if (fabs(x)<eps) return ;
if (x<) return -;
else return ;
} int dblcmp(double d)
{
if (fabs(d)<eps)return ;
return d>eps?:-;
} inline double sqr(double x){return x*x;}
struct point
{
double x,y;
point(){}
point(double _x,double _y):
x(_x),y(_y){};
void input()
{
scanf("%lf%lf",&x,&y);
}
void output()
{
printf("%.2f %.2f\n",x,y);
}
bool operator==(point a)const
{
return dblcmp(a.x-x)==&&dblcmp(a.y-y)==;
}
bool operator<(point a)const
{
return dblcmp(a.x-x)==?dblcmp(y-a.y)<:x<a.x;
} point operator +(const point &b)const
{
return point(x+b.x,y+b.y);
}
point operator -(const point &b)const
{
return point(x-b.x,y-b.y);
}
point operator *(const double &k)const
{
return point(x*k,y*k);
}
point operator /(const double &k)const
{
return point(x/k,y/k);
}
double operator ^(const point &b)const
{
return x*b.y-y*b.x;
}
double operator *(const point &b)const
{
return x*b.x+y*b.y;
} double len()
{
return hypot(x,y);
}
double len2()
{
return x*x+y*y;
}
double distance(point p)
{
return hypot(x-p.x,y-p.y);
}
point add(point p)
{
return point(x+p.x,y+p.y);
}
point sub(point p)
{
return point(x-p.x,y-p.y);
}
point mul(double b)
{
return point(x*b,y*b);
}
point div(double b)
{
return point(x/b,y/b);
}
double dot(point p)
{
return x*p.x+y*p.y;
}
double det(point p)
{
return x*p.y-y*p.x;
}
double rad(point a,point b)
{
point p=*this;
return fabs(atan2(fabs(a.sub(p).det(b.sub(p))),a.sub(p).dot(b.sub(p))));
}
point trunc(double r)
{
double l=len();
if (!dblcmp(l))return *this;
r/=l;
return point(x*r,y*r);
}
point rotleft()
{
return point(-y,x);
}
point rotright()
{
return point(y,-x);
}
point rotate(point p,double angle)//绕点p逆时针旋转angle角度
{
point v=this->sub(p);
double c=cos(angle),s=sin(angle);
return point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
}
}; struct line
{
point a,b;
line(){}
line(point _a,point _b)
{
a=_a;
b=_b;
}
bool operator==(line v)
{
return (a==v.a)&&(b==v.b);
}
//倾斜角angle
line(point p,double angle)
{
a=p;
if (dblcmp(angle-pi/)==)
{
b=a.add(point(,));
}
else
{
b=a.add(point(,tan(angle)));
}
}
//ax+by+c=0
line(double _a,double _b,double _c)
{
if (dblcmp(_a)==)
{
a=point(,-_c/_b);
b=point(,-_c/_b);
}
else if (dblcmp(_b)==)
{
a=point(-_c/_a,);
b=point(-_c/_a,);
}
else
{
a=point(,-_c/_b);
b=point(,(-_c-_a)/_b);
}
}
void input()
{
a.input();
b.input();
}
void adjust()
{
if (b<a)swap(a,b);
}
double length()
{
return a.distance(b);
}
double angle()//直线倾斜角 0<=angle<180
{
double k=atan2(b.y-a.y,b.x-a.x);
if (dblcmp(k)<)k+=pi;
if (dblcmp(k-pi)==)k-=pi;
return k;
}
//点和线段关系
//1 在逆时针
//2 在顺时针
//3 平行
int relation(point p)
{
int c=dblcmp(p.sub(a).det(b.sub(a)));
if (c<)return ;
if (c>)return ;
return ;
}
bool pointonseg(point p)
{
return dblcmp(p.sub(a).det(b.sub(a)))==&&dblcmp(p.sub(a).dot(p.sub(b)))<=;
}
bool parallel(line v)
{
return dblcmp(b.sub(a).det(v.b.sub(v.a)))==;
}
//2 规范相交
//1 非规范相交
//0 不相交
int segcrossseg(line v)
{
int d1=dblcmp(b.sub(a).det(v.a.sub(a)));
int d2=dblcmp(b.sub(a).det(v.b.sub(a)));
int d3=dblcmp(v.b.sub(v.a).det(a.sub(v.a)));
int d4=dblcmp(v.b.sub(v.a).det(b.sub(v.a)));
if ((d1^d2)==-&&(d3^d4)==-)return ;
return (d1==&&dblcmp(v.a.sub(a).dot(v.a.sub(b)))<=||
d2==&&dblcmp(v.b.sub(a).dot(v.b.sub(b)))<=||
d3==&&dblcmp(a.sub(v.a).dot(a.sub(v.b)))<=||
d4==&&dblcmp(b.sub(v.a).dot(b.sub(v.b)))<=);
}
int linecrossseg(line v)//*this seg v line
{
int d1=dblcmp(b.sub(a).det(v.a.sub(a)));
int d2=dblcmp(b.sub(a).det(v.b.sub(a)));
if ((d1^d2)==-)return ;
return (d1==||d2==);
}
//0 平行
//1 重合
//2 相交
int linecrossline(line v)
{
if ((*this).parallel(v))
{
return v.relation(a)==;
}
return ;
}
point crosspoint(line v)
{
double a1=v.b.sub(v.a).det(a.sub(v.a));
double a2=v.b.sub(v.a).det(b.sub(v.a));
return point((a.x*a2-b.x*a1)/(a2-a1),(a.y*a2-b.y*a1)/(a2-a1));
}
double dispointtoline(point p)
{
return fabs(p.sub(a).det(b.sub(a)))/length();
}
double dispointtoseg(point p)
{
if (dblcmp(p.sub(b).dot(a.sub(b)))<||dblcmp(p.sub(a).dot(b.sub(a)))<)
{
return min(p.distance(a),p.distance(b));
}
return dispointtoline(p);
}
point lineprog(point p)
{
return a.add(b.sub(a).mul(b.sub(a).dot(p.sub(a))/b.sub(a).len2()));
}
point symmetrypoint(point p)
{
point q=lineprog(p);
return point(*q.x-p.x,*q.y-p.y);
}
}; struct Vector:public point
{
Vector(){}
Vector(double a,double b)
{
x=a; y=b;
}
Vector(point _a,point _b) //a->b
{
double dx=_b.x-_a.x;
double dy=_b.y-_a.y;
x=dx; y=dy;
}
Vector(line v)
{
double dx=v.b.x-v.a.x;
double dy=v.b.y-v.a.y;
x=dx; y=dy;
}
double length()
{
return (sqrt(x*x+y*y));
}
Vector Normal()
{
double L=sqrt(x*x+y*y);
Vector Vans=Vector(-y/L,x/L);
return Vans;
}
}; struct circle
{
point p;
double r;
circle(){}
circle(point _p,double _r):
p(_p),r(_r){};
circle(double x,double y,double _r):
p(point(x,y)),r(_r){};
circle(point a,point b,point c)//三角形的外接圆
{
p=line(a.add(b).div(),a.add(b).div().add(b.sub(a).rotleft())).crosspoint(line(c.add(b).div(),c.add(b).div().add(b.sub(c).rotleft())));
r=p.distance(a);
}
circle(point a,point b,point c,bool t)//三角形的内切圆
{
line u,v;
double m=atan2(b.y-a.y,b.x-a.x),n=atan2(c.y-a.y,c.x-a.x);
u.a=a;
u.b=u.a.add(point(cos((n+m)/),sin((n+m)/)));
v.a=b;
m=atan2(a.y-b.y,a.x-b.x),n=atan2(c.y-b.y,c.x-b.x);
v.b=v.a.add(point(cos((n+m)/),sin((n+m)/)));
p=u.crosspoint(v);
r=line(a,b).dispointtoseg(p);
}
void input()
{
p.input();
scanf("%lf",&r);
}
void output()
{
printf("%.2lf %.2lf %.2lf\n",p.x,p.y,r);
}
bool operator==(circle v)
{
return ((p==v.p)&&dblcmp(r-v.r)==);
}
bool operator<(circle v)const
{
return ((p<v.p)||(p==v.p)&&dblcmp(r-v.r)<);
}
double area()
{
return pi*sqr(r);
}
double circumference()
{
return *pi*r;
}
//0 圆外
//1 圆上
//2 圆内
int relation(point b)
{
double dst=b.distance(p);
if (dblcmp(dst-r)<)return ;
if (dblcmp(dst-r)==)return ;
return ;
}
int relationseg(line v)
{
double dst=v.dispointtoseg(p);
if (dblcmp(dst-r)<)return ;
if (dblcmp(dst-r)==)return ;
return ;
}
int relationline(line v)
{
double dst=v.dispointtoline(p);
if (dblcmp(dst-r)<)return ;
if (dblcmp(dst-r)==)return ;
return ;
}
//过a b两点 半径r的两个圆
int getcircle(point a,point b,double r,circle&c1,circle&c2)
{
circle x(a,r),y(b,r);
int t=x.pointcrosscircle(y,c1.p,c2.p);
if (!t)return ;
c1.r=c2.r=r;
return t;
}
//与直线u相切 过点q 半径r1的圆
int getcircle(line u,point q,double r1,circle &c1,circle &c2)
{
double dis=u.dispointtoline(q);
if (dblcmp(dis-r1*)>)return ;
if (dblcmp(dis)==)
{
c1.p=q.add(u.b.sub(u.a).rotleft().trunc(r1));
c2.p=q.add(u.b.sub(u.a).rotright().trunc(r1));
c1.r=c2.r=r1;
return ;
}
line u1=line(u.a.add(u.b.sub(u.a).rotleft().trunc(r1)),u.b.add(u.b.sub(u.a).rotleft().trunc(r1)));
line u2=line(u.a.add(u.b.sub(u.a).rotright().trunc(r1)),u.b.add(u.b.sub(u.a).rotright().trunc(r1)));
circle cc=circle(q,r1);
point p1,p2;
if (!cc.pointcrossline(u1,p1,p2))cc.pointcrossline(u2,p1,p2);
c1=circle(p1,r1);
if (p1==p2)
{
c2=c1;return ;
}
c2=circle(p2,r1);
return ;
}
//同时与直线u,v相切 半径r1的圆
int getcircle(line u,line v,double r1,circle &c1,circle &c2,circle &c3,circle &c4)
{
if (u.parallel(v))return ;
line u1=line(u.a.add(u.b.sub(u.a).rotleft().trunc(r1)),u.b.add(u.b.sub(u.a).rotleft().trunc(r1)));
line u2=line(u.a.add(u.b.sub(u.a).rotright().trunc(r1)),u.b.add(u.b.sub(u.a).rotright().trunc(r1)));
line v1=line(v.a.add(v.b.sub(v.a).rotleft().trunc(r1)),v.b.add(v.b.sub(v.a).rotleft().trunc(r1)));
line v2=line(v.a.add(v.b.sub(v.a).rotright().trunc(r1)),v.b.add(v.b.sub(v.a).rotright().trunc(r1)));
c1.r=c2.r=c3.r=c4.r=r1;
c1.p=u1.crosspoint(v1);
c2.p=u1.crosspoint(v2);
c3.p=u2.crosspoint(v1);
c4.p=u2.crosspoint(v2);
return ;
}
//同时与不相交圆cx,cy相切 半径为r1的圆
int getcircle(circle cx,circle cy,double r1,circle&c1,circle&c2)
{
circle x(cx.p,r1+cx.r),y(cy.p,r1+cy.r);
int t=x.pointcrosscircle(y,c1.p,c2.p);
if (!t)return ;
c1.r=c2.r=r1;
return t;
}
int pointcrossline(line v,point &p1,point &p2)//求与线段交要先判断relationseg
{
if (!(*this).relationline(v))return ;
point a=v.lineprog(p);
double d=v.dispointtoline(p);
d=sqrt(r*r-d*d);
if (dblcmp(d)==)
{
p1=a;
p2=a;
return ;
}
p1=a.sub(v.b.sub(v.a).trunc(d));
p2=a.add(v.b.sub(v.a).trunc(d));
return ;
}
//5 相离
//4 外切
//3 相交
//2 内切
//1 内含
int relationcircle(circle v)
{
double d=p.distance(v.p);
if (dblcmp(d-r-v.r)>)return ;
if (dblcmp(d-r-v.r)==)return ;
double l=fabs(r-v.r);
if (dblcmp(d-r-v.r)<&&dblcmp(d-l)>)return ;
if (dblcmp(d-l)==)return ;
if (dblcmp(d-l)<)return ;
}
int pointcrosscircle(circle v,point &p1,point &p2)
{
int rel=relationcircle(v);
if (rel==||rel==)return ;
double d=p.distance(v.p);
double l=(d+(sqr(r)-sqr(v.r))/d)/;
double h=sqrt(sqr(r)-sqr(l));
p1=p.add(v.p.sub(p).trunc(l).add(v.p.sub(p).rotleft().trunc(h)));
p2=p.add(v.p.sub(p).trunc(l).add(v.p.sub(p).rotright().trunc(h)));
if (rel==||rel==)
{
return ;
}
return ;
}
//过一点做圆的切线 (先判断点和圆关系)
int tangentline(point q,line &u,line &v)
{
int x=relation(q);
if (x==)return ;
if (x==)
{
u=line(q,q.add(q.sub(p).rotleft()));
v=u;
return ;
}
double d=p.distance(q);
double l=sqr(r)/d;
double h=sqrt(sqr(r)-sqr(l));
u=line(q,p.add(q.sub(p).trunc(l).add(q.sub(p).rotleft().trunc(h))));
v=line(q,p.add(q.sub(p).trunc(l).add(q.sub(p).rotright().trunc(h))));
return ;
}
double areacircle(circle v)
{
int rel=relationcircle(v);
if (rel>=)return 0.0;
if (rel<=)return min(area(),v.area());
double d=p.distance(v.p);
double hf=(r+v.r+d)/2.0;
double ss=*sqrt(hf*(hf-r)*(hf-v.r)*(hf-d));
double a1=acos((r*r+d*d-v.r*v.r)/(2.0*r*d));
a1=a1*r*r;
double a2=acos((v.r*v.r+d*d-r*r)/(2.0*v.r*d));
a2=a2*v.r*v.r;
return a1+a2-ss;
}
double areatriangle(point a,point b)
{
if (dblcmp(p.sub(a).det(p.sub(b))==))return 0.0;
point q[];
int len=;
q[len++]=a;
line l(a,b);
point p1,p2;
if (pointcrossline(l,q[],q[])==)
{
if (dblcmp(a.sub(q[]).dot(b.sub(q[])))<)q[len++]=q[];
if (dblcmp(a.sub(q[]).dot(b.sub(q[])))<)q[len++]=q[];
}
q[len++]=b;
if (len==&&(dblcmp(q[].sub(q[]).dot(q[].sub(q[])))>))swap(q[],q[]);
double res=;
int i;
for (i=;i<len-;i++)
{
if (relation(q[i])==||relation(q[i+])==)
{
double arg=p.rad(q[i],q[i+]);
res+=r*r*arg/2.0;
}
else
{
res+=fabs(q[i].sub(p).det(q[i+].sub(p))/2.0);
}
}
return res;
}
}; struct polygon
{
int n;
point p[maxp];
line l[maxp];
void input(int X)
{
n=X;
for (int i=;i<n;i++)
{
p[i].input();
}
}
void add(point q)
{
p[n++]=q;
}
//注意:点必须按顺序读入,否则在getline的时候会混乱掉
void getline()
{
for (int i=;i<n;i++)
{
l[i]=line(p[i],p[(i+)%n]);
}
}
struct cmp
{
point p;
cmp(const point &p0){p=p0;}
bool operator()(const point &aa,const point &bb)
{
point a=aa,b=bb;
int d=dblcmp(a.sub(p).det(b.sub(p)));
if (d==)
{
return dblcmp(a.distance(p)-b.distance(p))<;
}
return d>;
}
};
void norm()
{
point mi=p[];
for (int i=;i<n;i++)mi=min(mi,p[i]);
sort(p,p+n,cmp(mi));
}
void getconvex(polygon &convex)
{
int i,j,k;
sort(p,p+n);
convex.n=n;
for (i=;i<min(n,);i++)
{
convex.p[i]=p[i];
}
if (n<=)return;
int &top=convex.n;
top=;
for (i=;i<n;i++)
{
while (top&&convex.p[top].sub(p[i]).det(convex.p[top-].sub(p[i]))<=)
top--;
convex.p[++top]=p[i];
}
int temp=top;
convex.p[++top]=p[n-];
for (i=n-;i>=;i--)
{
while (top!=temp&&convex.p[top].sub(p[i]).det(convex.p[top-].sub(p[i]))<=)
top--;
convex.p[++top]=p[i];
}
}
bool isconvex()
{
bool s[];
memset(s,,sizeof(s));
int i,j,k;
for (i=;i<n;i++)
{
j=(i+)%n;
k=(j+)%n;
s[dblcmp(p[j].sub(p[i]).det(p[k].sub(p[i])))+]=;
if (s[]&&s[])return ;
}
return ;
}
//3 点上
//2 边上
//1 内部
//0 外部
int relationpoint(point q)
{
int i,j;
for (i=;i<n;i++)
{
if (p[i]==q)return ;
}
getline();
for (i=;i<n;i++)
{
if (l[i].pointonseg(q))
{
//cout<<"222: "<<i<<" "<<l[i].a.x<<","<<l[i].a.y<<"---"<<l[i].b.x<<","<<l[i].b.y<<endl;
return ;
}
}
int cnt=;
for (i=;i<n;i++)
{
j=(i+)%n;
int k=dblcmp(q.sub(p[j]).det(p[i].sub(p[j])));
int u=dblcmp(p[i].y-q.y);
int v=dblcmp(p[j].y-q.y);
if (k>&&u<&&v>=)cnt++;
if (k<&&v<&&u>=)cnt--;
}
return cnt!=;
}
//1 在多边形内长度为正
//2 相交或与边平行
//0 无任何交点
int relationline(line u)
{
int i,j,k=;
getline();
for (i=;i<n;i++)
{
if (l[i].segcrossseg(u)==)return ;
if (l[i].segcrossseg(u)==)k=;
}
if (!k)return ;
vector<point>vp;
for (i=;i<n;i++)
{
if (l[i].segcrossseg(u))
{
if (l[i].parallel(u))
{
vp.pb(u.a);
vp.pb(u.b);
vp.pb(l[i].a);
vp.pb(l[i].b);
continue;
}
vp.pb(l[i].crosspoint(u));
}
}
sort(vp.begin(),vp.end());
int sz=vp.size();
for (i=;i<sz-;i++)
{
point mid=vp[i].add(vp[i+]).div();
if (relationpoint(mid)==)return ;
}
return ;
}
//直线u切割凸多边形左侧
//注意直线方向
void convexcut(line u,polygon &po)
{
int i,j,k;
int &top=po.n;
top=;
for (i=;i<n;i++)
{
int d1=dblcmp(p[i].sub(u.a).det(u.b.sub(u.a)));
int d2=dblcmp(p[(i+)%n].sub(u.a).det(u.b.sub(u.a)));
if (d1>=)po.p[top++]=p[i];
if (d1*d2<)po.p[top++]=u.crosspoint(line(p[i],p[(i+)%n]));
}
}
double getcircumference()
{
double sum=;
int i;
for (i=;i<n;i++)
{
sum+=p[i].distance(p[(i+)%n]);
}
return sum;
}
double getarea()
{
double sum=;
int i;
for (i=;i<n;i++)
{
sum+=p[i].det(p[(i+)%n]);
}
return fabs(sum)/;
}
bool getdir()//1代表逆时针 0代表顺时针
{
double sum=;
int i;
for (i=;i<n;i++)
{
sum+=p[i].det(p[(i+)%n]);
}
if (dblcmp(sum)>)return ;
return ;
}
point getbarycentre()
{
point ret(,);
double area=;
int i;
for (i=;i<n-;i++)
{
double tmp=p[i].sub(p[]).det(p[i+].sub(p[]));
if (dblcmp(tmp)==)continue;
area+=tmp;
ret.x+=(p[].x+p[i].x+p[i+].x)/*tmp;
ret.y+=(p[].y+p[i].y+p[i+].y)/*tmp;
}
if (dblcmp(area))ret=ret.div(area);
return ret;
}
double areaintersection(polygon po)
{
}
double areaunion(polygon po)
{
return getarea()+po.getarea()-areaintersection(po);
}
double areacircle(circle c)
{
int i,j,k,l,m;
double ans=;
for (i=;i<n;i++)
{
int j=(i+)%n;
if (dblcmp(p[j].sub(c.p).det(p[i].sub(c.p)))>=)
{
ans+=c.areatriangle(p[i],p[j]);
}
else
{
ans-=c.areatriangle(p[i],p[j]);
}
}
return fabs(ans);
}
//多边形和圆关系
//0 一部分在圆外
//1 与圆某条边相切
//2 完全在圆内
int relationcircle(circle c)
{
getline();
int i,x=;
if (relationpoint(c.p)!=)return ;
for (i=;i<n;i++)
{
if (c.relationseg(l[i])==)return ;
if (c.relationseg(l[i])==)x=;
}
return x;
}
void find(int st,point tri[],circle &c)
{
if (!st)
{
c=circle(point(,),-);
}
if (st==)
{
c=circle(tri[],);
}
if (st==)
{
c=circle(tri[].add(tri[]).div(),tri[].distance(tri[])/2.0);
}
if (st==)
{
c=circle(tri[],tri[],tri[]);
}
}
void solve(int cur,int st,point tri[],circle &c)
{
find(st,tri,c);
if (st==)return;
int i;
for (i=;i<cur;i++)
{
if (dblcmp(p[i].distance(c.p)-c.r)>)
{
tri[st]=p[i];
solve(i,st+,tri,c);
}
}
}
circle mincircle()//点集最小圆覆盖
{
random_shuffle(p,p+n);
point tri[];
circle c;
solve(n,,tri,c);
return c;
}
int circlecover(double r)//单位圆覆盖
{
int ans=,i,j;
vector<pair<double,int> >v;
for (i=;i<n;i++)
{
v.clear();
for (j=;j<n;j++)if (i!=j)
{
point q=p[i].sub(p[j]);
double d=q.len();
if (dblcmp(d-*r)<=)
{
double arg=atan2(q.y,q.x);
if (dblcmp(arg)<)arg+=*pi;
double t=acos(d/(*r));
v.push_back(make_pair(arg-t+*pi,-));
v.push_back(make_pair(arg+t+*pi,));
}
}
sort(v.begin(),v.end());
int cur=;
for (j=;j<v.size();j++)
{
if (v[j].second==-)++cur;
else --cur;
ans=max(ans,cur);
}
}
return ans+;
}
int pointinpolygon(point q)//点在凸多边形内部的判定
{
if (getdir())reverse(p,p+n);
if (dblcmp(q.sub(p[]).det(p[n-].sub(p[])))==)
{
if (line(p[n-],p[]).pointonseg(q))return n-;
return -;
}
int low=,high=n-,mid;
while (low<=high)
{
mid=(low+high)>>;
if (dblcmp(q.sub(p[]).det(p[mid].sub(p[])))>=&&dblcmp(q.sub(p[]).det(p[mid+].sub(p[])))<)
{
polygon c;
c.p[]=p[mid];
c.p[]=p[mid+];
c.p[]=p[];
c.n=;
if (c.relationpoint(q))return mid;
return -;
}
if (dblcmp(q.sub(p[]).det(p[mid].sub(p[])))>)
{
low=mid+;
}
else
{
high=mid-;
}
}
return -;
}
}; struct polygon PL[MAXN];
struct point PO[MAXN];
int num[MAXN];
int n,m;
double X1,Y1,X2,Y2;
double L[MAXN],U[MAXN]; int main()
{
while(scanf("%d",&n))
{
if(n==) break;
scanf("%d%lf%lf%lf%lf",&m,&X1,&Y1,&X2,&Y2);
for (int i=; i<n; i++)
scanf("%lf%lf",&U[i],&L[i]);
for (int i=; i<m; i++)
PO[i].input(); sort(U,U+n);
sort(L,L+n); for (int i=; i<=n; i++)
{
int ya=Y1,yb=Y2,yc=Y2,yd=Y1;
int xa,xb,xc,xd;
if (i==)
{
xa=X1,xb=X1;
xc=L[],xd=U[];
}
else if (i==n)
{
xa=U[n-],xb=L[n-];
xc=X2,xd=X2;
}
else
{
xa=U[i-],xb=L[i-];
xc=L[i],xd=U[i];
}
PL[i].n=;
PL[i].p[]=point(xa,ya);
PL[i].p[]=point(xb,yb);
PL[i].p[]=point(xc,yc);
PL[i].p[]=point(xd,yd);
PL[i].getline();
}
//PL[0..n]:polygon memset(num,,sizeof(num));
for (int i=;i<=n;i++)
{
polygon PY=PL[i];
PY.getline();
/*
cout<<"PL ";
for (int j=0;j<=3;j++)
cout<<PY.p[j].x<<","<<PY.p[j].y<<" ";
cout<<endl;
*/
for (int j=;j<m;j++)
{
point PPP=PO[j];
int ans=PY.relationpoint(PPP);
//cout<<PPP.x<<","<<PPP.y<<" "<<ans<<endl;
if ((ans==)||(ans==))
num[i]++;
} } for (int i=; i<=n; i++)
printf("%d: %d\n",i,num[i]);
//cout<<i<<": "<<num[i]<<endl;
}
return ;
}
sol attemp2:可以二分啊
对于每一个点,判断当前线段在点的左边还是右边
poj2318的更多相关文章
- POJ2318 TOYS[叉积 二分]
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14433 Accepted: 6998 Description ...
- POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage
题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段 ...
- POJ-2318 TOYS 计算几何 判断点在线段的位置
题目链接:https://cn.vjudge.net/problem/POJ-2318 题意 在一个矩形内,给出n-1条线段,把矩形分成n快四边形 问某些点在那个四边形内 思路 二分+判断点与位置关系 ...
- poj2318(叉积判断点在直线左右+二分)
题目链接:https://vjudge.net/problem/POJ-2318 题意:有n条线将矩形分成n+1块,m个点落在矩形内,求每一块点的个数. 思路: 最近开始肝计算几何,之前的几何题基本处 ...
- poj2318 水题(二分+叉积)
题目链接:http://poj.org/problem?id=2318 #include<cstdio> #include<cstring> #include<cmath ...
- POJ2318 TOYS(叉积判断点与直线的关系+二分)
Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...
- POJ2318【判断点在直线哪一侧+二分查找区间】
题目大意:给定一个矩形和一些线段,线段将矩形分割为从左至右的若干部分,之后给出一些玩具的坐标,求每个部分中玩具的数量 #include<cstdio> #include<cstdli ...
- POJ2318(KB13-A 计算几何)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16222 Accepted: 7779 Description ...
- POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]
题目链接:http://poj.org/problem?id=2398 Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad ...
随机推荐
- java:如何用代码控制H2 Database启动
1.纯手动start/stop package com.cnblogs.yjmyzz.h2; import java.sql.Connection; import java.sql.DriverMan ...
- ejb3: message drive bean(MDB)示例
上一篇已经知道了JMS的基本操作,今天来看一下ejb3中的一种重要bean:Message Drive Bean(mdb) 如果要不断监听一个队列中的消息,通常我们需要写一个监听程序,这需要一定的开发 ...
- .net 动态代理的泛型方法支持问题
最近一直在做.net平台下的高速服务框架.其中有一个问题一直困扰着我:通过动态代理RealProxy创建的服务代理,不支持泛型方法调用.比如: 接口声明: public interface IMete ...
- oracle 11g的企业管理器
oracle 11g的企业管理器不同于其他版本,它是B/S的,默认登录为:https://localhost:1158/em,但我试了IE8跟360浏览器都不行,谷歌浏览器是可以访问的
- 【NDK开发】android-ndk r10环境搭建
1)打开Android开发者的官网http://developer.android.com/找到Develop点击.如果页面打不开,通过代理来访问. 2)进入后再点击Tools 3)进入后在左侧找到N ...
- Android Studio代码混淆插件
之前给公司的App添加代码混淆,在代码的混淆过程也遇到了不少的问题,再加上最近学习了一下Android Studio插件的开发,所以就开发一个代码混淆插件方便项目的代码混淆. 截图 第三方库列表清单 ...
- VS2010+MVC4+Spring.NET2+NHibernate4-传统三层架构-前篇
VS2010+MVC4+Spring.NET2+NHibernate4 - 传统三层架构 - 前篇 一直追求使用开源项目,就因一个字:懒! 一直想整理一下的,却一直懒到现在!从当初用的MVC3到现在的 ...
- Centos下编译JDK
因为OpenJDK是开源的,这里使用openJDK进行编译联系 环境要求 Centos6.7 64位 openjdk-7u40-fcs-src-b43-26_aug_2013.zip bootstra ...
- ElasticSearch入门系列(一)是什么以及安装和运行
一.是什么 ElasticSearch是一个基于Apache Lucene的开源搜索引擎. Elasticsearch: 分布式的实时文件存储,每个字段都被所用并可被搜索 分布式的实时分析搜索引擎 可 ...
- HTML5+AJAX原生分块上传文件的关键参数设置
processData:false 这是jquery.ajax的一个参数.默认值为true,表示会将非字符串对象自动变成k1=v1&k2=v2的形式,例如一个数组参数{d:[1,2]},到服务 ...