poj 2318 TOYS

水题

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

struct node
{
	double k;
	double b;
}par[5005];
int num[5005];
int n,m;
double x1=0,x2=0,y1=0,y2=0;
int search(int begin,int end,double x,double y)
{
	int m=(end+begin)/2;
	double s1,s2;
	if(m==0)
		s1=x1;
	else
		s1=par[m].k*y+par[m].b;
	if(m==n)
		s2=x2;
	else
		s2=par[m+1].k*y+par[m+1].b;

	if(x>s1&&x<s2)		
		return m;
	
	 if(x>s2)
		return search(m+1,end,x,y);
	 if(x<s1)
		return search(begin,m-1,x,y);
	return 1000;
}
int main()
{
	freopen("test.txt","r",stdin);
	
	int i;
	
	double Ui=0,Li=0;
	double xj=0,yj=0;
	int position;
	while(scanf("%d",&n)!=EOF && n!=0 )
	{
		scanf("%d %lf %lf %lf %lf",&m,&x1,&y1,&x2,&y2);
		for(i=1;i<=n;i++)
		{
			scanf("%lf %lf",&Ui,&Li);
			par[i].k=(Ui-Li)/(y1-y2);
			par[i].b=Ui-y1*(par[i].k);
		}
		
		memset(num,0,sizeof(num));
		for(i=1;i<=m;i++)
		{
			scanf("%lf %lf",&xj,&yj);
			position=search(0,n,xj,yj);
			num[position]++;
		}

		for(i=0;i<=n;i++)
			printf("%d: %d\n",i,num[i]);
		printf("\n");
			
		
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值