【POJ2318】—TOYS(计算几何)
看到都用二分,似乎没必要吧…
直接枚举也能过
二分边界什么的弄得我想死…
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define eps 1e-8
inline int read(){
char ch=getchar();
int res=0,f=1;
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
return res*f;
}
const int N=5005;
struct point{
int x,y;
point(double a=0,double b=0){
x=a,y=b;
}
friend inline point operator -(const point &a,const point &b){
return point(a.x-b.x,a.y-b.y);
}
friend inline int operator *(const point &a,const point &b){
return a.x*b.y-a.y*b.x;
}
};
struct line{
point a,b;
}p[N];
int n,m,x1,x2,yx,y2;
short ans[N];
inline void calc(point a){
int l=0,r=n-1,res=n;
while(l<r){
int mid=(l+r)>>1;
if((a-p[mid].b)*(p[mid].a-p[mid].b)>0)l=mid+1;
else r=mid;
}
if((a-p[l].b)*(p[l].a-p[l].b)<0)ans[l]++;
else ans[l+1]++;
}
int main(){
n=read();
while(n){
m=read(),x1=read(),yx=read(),x2=read(),y2=read();
for(int i=0;i<n;i++){
p[i].a.x=read(),p[i].a.y=yx;
p[i].b.x=read(),p[i].b.y=y2;
}
memset(ans,0,sizeof(ans));
for(int i=1;i<=m;i++){
int x=read(),y=read();
calc(point(x,y));
}
for(int i=0;i<=n;i++)cout<<i<<": "<<ans[i]<<'\n';puts("");
n=read();
}
}