poj2318

/***************************************************************\

 *Author:Hu Wenbiao

 *Created Time: Tue 27 Jul 2010 07:10:34 PM CST

 *File Name: main.cpp

 *Description:几何题目。简单的叉积应用

\***************************************************************/

//*========================*Head File*========================*\\



#include<iostream>

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

/*----------------------*Global Variable*----------------------*/

struct Cardboard{//隔板

 int u,l;

}card[5010];

int toynum[5010],n,m,x1,y1,x2,y2,X,Y;//toynum计算数目

//*=======================*Main Program*=======================*//

using namespace std;



bool left(int m){//判断toy在第m个隔板左边

 int a=card[m].u-card[m].l,b=y1-y2,c=X-card[m].l,d=Y-y2;

 return a*d-b*c>0;

}



void location(){//二分法,将toy所在的区间数目加1

 int s=0,t=n;

 int m=(s+t)/2;

 while(s<t){

  if(left(m)){

   t=m;

   m=(s+t)/2;

  }

  else{

   s=m+1;

   m=(s+t)/2;

  }

 }

 toynum[t]++;

}

int main(){

 //freopen("input","r",stdin);

 while(scanf("%d%d%d%d%d%d",&n,&m,&x1,&y1,&x2,&y2)!=EOF&&n){

  for(int i=0;i<n;i++)

    scanf("%d%d",&card[i].u,&card[i].l);

  card[n].u=card[n].l=x2;//用box右边界作第n个区间的‘隔板’

  memset(toynum,0,sizeof(toynum));

  while(m--){

   scanf("%d%d",&X,&Y);

   location();

  }

  for(int i=0;i<=n;i++)

    printf("%d: %d\n",i,toynum[i]);

  printf("\n");

 }

}

你可能感兴趣的:(poj)