码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2398

时间:2014-07-26 00:07:26      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   for   re   c   div   amp   

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int Max=1050;

struct e{
	int x1,x2;
}edge[Max];
struct c{
	int x,y;
}cal[4];

int n,m;
int X1,Y1,X2,Y2;
int ans[Max],co[Max];
int u,v;

bool cmp(struct e A,struct e B){
	if(A.x1<B.x1) return true;
	return false;
}

void init(){
	for(int i=0;i<=n;i++){
		ans[i]=0; co[i]=0;
	}
}

bool in(){
	if(u>=X1&&u<=X2&&v>=Y2&&v<=Y1)
	return true;
	return false;
}

__int64 multi(int i){
	int j=i+1;
	if(j==4) j=0;
	return (__int64)(u-cal[i].x)*(__int64)(cal[j].y-cal[i].y)-(__int64)(v-cal[i].y)*(__int64)(cal[j].x-cal[i].x);
}

bool judge(int mid){
	__int64 pre,now;
	cal[0].x=edge[mid].x1; cal[0].y=Y1;
	cal[1].x=X2; cal[1].y=Y1;
	cal[2].x=X2; cal[2].y=Y2;
	cal[3].x=edge[mid].x2; cal[3].y=Y2;
	for(int i=0;i<4;i++){
		now=multi(i);
		if(i>0){
			if(pre*now<0)
			return false;
		}
		pre=now;
	}
	return true;
}

void slove(){
	int low=0,high=n;
	int anst;
	while(low<=high){
		int mid=(low+high)/2;
		if(judge(mid)){
			anst=mid; low=mid+1;
		}
		else high=mid-1;
	}
	int k=ans[anst];
	co[k]--;
	ans[anst]++;
	co[k+1]++;
}

int main(){
	while(scanf("%d",&n)!=EOF){
		if(n==0) break;
		scanf("%d%d%d%d%d",&m,&X1,&Y1,&X2,&Y2);
		init();
		co[0]=m;
		edge[0].x1=X1,edge[0].x2=X1;
		for(int i=1;i<=n;i++){
			scanf("%d%d",&edge[i].x1,&edge[i].x2);
		}
		sort(edge,edge+n+1,cmp);
		for(int i=0;i<m;i++){
			scanf("%d%d",&u,&v);
			if(in())
				slove();
		}
		printf("Box\n");
		for(int i=1;i<=m;i++){
			if(co[i]){
				printf("%d: %d\n",i,co[i]);
			}
		}
	}
	return 0;
}

  

POJ 2398,布布扣,bubuko.com

POJ 2398

标签:blog   os   io   for   re   c   div   amp   

原文地址:http://www.cnblogs.com/jie-dcai/p/3868299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!