Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Wrong Answer × 9^9^9^9,叉积+二分,样例已过,求大佬验代码。代码如下: ```cpp #include<cstdio> using namespace std; const int N=5005; typedef long long ll; int n,m; ll x1,y1,x2,y2; int res[N]; struct Point{ ll x,y; Point(){} Point(ll x,ll y):x(x),y(y){} Point operator-(Point A){return Point(x-A.x,y-A.y);} ll operator*(Point A){return x*A.y-y*A.x;} } D[N],U[N]; ll cross(Point A,Point B,Point C){ return (B-A)*(C-A); } //叉积 void add(Point A){ int l=1,r=n+1; int ans=-1; while(l<=r){ int mid=l+r>>1; if(cross(D[mid],U[mid],A)>=0) ans=mid,r=mid-1; else l=mid+1; } res[ans-1]++; } //二分添加 int main(){ int flag=1; while(~scanf("%d",&n)&&n){ scanf("%d%lld%lld%lld%lld",&m,&x1,&y1,&x2,&y2); for(int i=0;i<=n;i++) res[i]=0; for(int i=1;i<=n;i++){ ll u,l;scanf("%lld%lld",&u,&l); D[i]=Point(l,y2),U[i]=Point(u,y1); } D[n+1]=Point(x1,y2),U[n+1]=Point(x2,y1); while(m--){ ll x,y;scanf("%lld%lld",&x,&y); add(Point(x,y)); } for(int i=0;i<=n;i++) printf("%d: %d\n",i,res[i]); putchar(10); } return 0; } ``` Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator