POJ 2398

#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;
}

  

转载于:https://www.cnblogs.com/jie-dcai/p/3868299.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值