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

论二分的两种写法T_T...........HML

Posted by cyy1308947278 at 2016-07-26 19:09:31 on Problem 2318
#include<stdio.h>
#include<string.h>
#include<iostream>
#define N 5555
#define ll long long
using namespace std; 
ll ban[N][2];
ll ans[N];
ll x1,x2,y1,y2;
ll xx,yy;
int solve(int mid)
{
	ll px1=ban[mid][0]-xx;
				ll py1=y1-yy;
				ll px2=ban[mid][1]-xx;
				ll py2=y2-yy;
				ll tmp1=px1*py2-px2*py1;	
				return tmp1>0;
}
int main()
{
	int n,m;
	while(~scanf("%d",&n)&&n)
	{
		scanf("%d%lld%lld%lld%lld",&m,&x1,&y1,&x2,&y2);
		ban[0][0]=ban[0][1]=0;
		for(int i=1;i<=n;i++)
		scanf("%lld%lld",&ban[i][0],&ban[i][1]);	
		ban[++n][0]=ban[n][1]=x2;
		memset(ans,0,sizeof(ans));
		for(int i=0;i<m;i++)
		{
			
			scanf("%lld%lld",&xx,&yy);
			int sta=0,end=n,mid;
			while(sta<end)
			{
				mid=(sta+end)/2;				 
				if(solve(mid)&&!solve(mid+1))
				{
					ans[mid]++;
					break;
				}
				if(solve(mid))sta=mid+1;
				else end=mid;
				
			}
		}
		for(int i=0;i<n;i++)
		printf("%d: %lld\n",i,ans[i]);
		printf("\n");
	}
	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