Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:Wrong Answer × 9^9^9^9,叉积+二分,样例已过,求大佬验代码。

Posted by YuRuochen at 2023-12-02 21:59:21 on Problem 2318
In Reply To:Wrong Answer × 9^9^9^9,叉积+二分,样例已过,求大佬验代码。 Posted by:YuRuochen at 2023-12-02 21:56:02
> 代码如下:
> ```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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator