比赛 20140418 评测结果 AWWWWWWWWA
题目名称 奶牛冰壶运动 最终得分 20
用户昵称 Suke 运行时间 0.209 s
代码语言 C++ 内存使用 1.46 MiB
提交时间 2014-04-18 11:22:20
显示代码纯文本
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 50005
#define inf ~0U>>2
struct re{
	int x,y;
} pa[N],pb[N],res[N];
int n,size,maxx,maxy,minx,miny,ans,ex;
bool cmp(const re &a,const re &b){
	if (a.y<b.y) return 1;
	if (a.y>b.y) return 0;
	return (a.x<b.x);
}
inline long long xmulti(re a,re b,re c){
	long long x1=(long long)(b.x-a.x),x2=(long long)(c.x-a.x);
	long long y1=(long long)(b.y-a.y),y2=(long long)(c.y-a.y);
	return (x1*y2-x2*y1);
}
void convex1(){
	int i;
	res[0]=pa[1];
	res[1]=pa[2];
	size=1;
	for(i=3;i<=n;++i)
	{
	  	while(size>0 && xmulti(res[size-1],res[size],pa[i])<0) size--;
	  	res[++size]=pa[i];
	}
	ex=size;
	for(i=n-1;i>=1;--i){
	  	while(size>0 && xmulti(res[size-1],res[size],pa[i])<0) size--;
	  	res[++size]=pa[i];
	}
	maxx=maxy=-inf;
	minx=miny=inf;
	for(i=1;i<=size;++i){
		if (res[i].x>maxx) maxx=res[i].x;
		if (res[i].x<minx) minx=res[i].x;
		if (res[i].y>maxy) maxy=res[i].y;
		if (res[i].y<miny) miny=res[i].y;
	}
}
void convex2(){
	int i;
	res[0]=pb[1];
	res[1]=pb[2];
	size=1;
	for(i=3;i<=n;++i)
	{
	  	while(size>0 && xmulti(res[size-1],res[size],pb[i])<0) size--;
	  	res[++size]=pb[i];
	}
	ex=size;
	for(i=n-1;i>=1;--i){
	  	while(size>0 && xmulti(res[size-1],res[size],pb[i])<0) size--;
	  	res[++size]=pb[i];
	}
	maxx=maxy=-inf;
	minx=miny=inf;
	for(i=1;i<=size;++i){
		if (res[i].x>maxx) maxx=res[i].x;
		if (res[i].x<minx) minx=res[i].x;
		if (res[i].y>maxy) maxy=res[i].y;
		if (res[i].y<miny) miny=res[i].y;
	}
}
bool ok(re p){
	if (p.x>maxx || p.x<minx || p.y>maxy || p.y<miny) return false;
	int i,flag=0;
	long long tem;
	if (p.y==res[0].y){
		if (p.x==res[0].x) return true;
		if (p.x<res[0].x) return false;
		for(i=1;i<=ex;++i){
			if (res[i].y>p.y) return false;
			if (res[i].x>=p.x) return true;
		}
	}
	if (p.y==res[ex].y){
		if (p.x==res[0].x) return true;
		if (p.x>res[0].x) return false;
		for(i=ex+1;i<=size;++i){
			if (res[i].y<p.y) return false;
			if (res[i].x<=p.x) return true;
		}
	}
	for(i=1;i<=size;++i)
	 if(p.y>=min(res[i-1].y,res[i].y) && p.y<=max(res[i-1].y,res[i].y)){
	 	 tem=xmulti(p,res[i-1],res[i]);
	if (tem==0&& (p.x>=min(res[i-1].x,res[i].x) && p.x<=max(res[i-1].x,res[i].x))) return true;
         if (tem>0) flag++;
	 }
	if (flag==2) return true;
	else return false;
}
int main(){
	freopen("curling.in","r",stdin);
	freopen("curling.out","w",stdout);
	cin>>n;
	int i;
	for(i=1;i<=n;++i){
		scanf("%d%d",&pa[i].x,&pa[i].y);
	}
	for(i=1;i<=n;++i){
		scanf("%d%d",&pb[i].x,&pb[i].y);
	}
	sort(pa+1,pa+n+1,cmp);
	sort(pb+1,pb+n+1,cmp);
	convex1();
	ans=0;
	for(i=1;i<=n;++i){
		if (ok(pb[i])) ans++;
		if (pb[i].y>maxy) break;
	}
	printf("%d ",ans);
	ans=0;
	convex2();
	for(i=1;i<=n;++i){
		if (ok(pa[i])) ans++;
		if (pa[i].y>maxy) break;
	}
	printf("%d\n",ans);
	return 0;
}