标签:output mos lang accept sizeof lines ges cardboard dea
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14433 | Accepted: 6998 |
Description
Input
Output
// // main.cpp // poj2318 // // Created by Candy on 2017/1/26. // Copyright © 2017年 Candy. All rights reserved. // #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <vector> using namespace std; typedef long long ll; const int N=5005; const double eps=1e-8; inline int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();} return x*f; } inline int sgn(double x){ if(abs(x)<eps) return 0; else return x<0?-1:1; } struct Vector{ double x,y; Vector(double a=0,double b=0):x(a),y(b){} bool operator <(const Vector &a)const{ return x<a.x||(x==a.x&&y<a.y); } }; typedef Vector Point; Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);} Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);} Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);} Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);} bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==0&&sgn(a.y-b.y)==0;} double Cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; } struct Line{ Point p; Vector v; Line(){} Line(Point p,Vector v):p(p),v(v){} bool operator <(const Line a)const{ return sgn(Cross(v,a.v))>=0; } }a[N]; bool OnLeft(Line l,Point p){ return sgn(Cross(l.v,p-l.p))>=0; } int n,m,x,y,x2,y2,u,l,xx,yy; int ans[N]; int main(int argc, const char * argv[]) { while(true){ memset(ans,0,sizeof(ans)); n=read();if(n==0) break; m=read();x=read();y=read();x2=read();y2=read(); for(int i=1;i<=n;i++) u=read(),l=read(),a[i]=Line(Point(l,y2),Vector(u-l,y-y2)); a[++n]=Line(Point(x2,y2),Vector(0,y-y2)); for(int i=1;i<=m;i++){ x=read();y=read(); Point p=Point(x,y); int l=1,r=n,pos=-1; while(l<=r){ int mid=(l+r)>>1; if(OnLeft(a[mid],p)) pos=mid,r=mid-1; else l=mid+1; } ans[pos]++; } for(int i=1;i<=n;i++) printf("%d: %d\n",i-1,ans[i]); puts(""); } return 0; }
标签:output mos lang accept sizeof lines ges cardboard dea
原文地址:http://www.cnblogs.com/candy99/p/6352162.html