记录编号 |
97304 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[USACO Jan14]奶牛冰壶运动 |
最终得分 |
100 |
用户昵称 |
Suke |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.226 s |
提交时间 |
2014-04-18 12:10:38 |
内存使用 |
1.46 MiB |
显示代码纯文本
#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;
long long area;
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);
}
inline long long labs(long long x){
if (x>=0) return x;
else return -x;
}
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];
}
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;
}
area=0;
for(i=1;i<=size;++i)
area+=(long long)res[i-1].x*(long long)res[i].y-(long long)res[i].x*(long long)res[i-1].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];
}
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;
}
area=0;
for(i=1;i<=size;++i)
area+=(long long)res[i-1].x*(long long)res[i].y-(long long)res[i].x*(long long)res[i-1].y;
}
bool ok(re p){
if (p.x>maxx || p.x<minx || p.y>maxy || p.y<miny) return false;
long long sum=0;
for(int i=1;i<=size;++i)
sum+=labs((long long)(res[i-1].x-p.x)*(long long)(res[i].y-p.y)-(long long)(res[i].x-p.x)*(long long)(res[i-1].y-p.y));
if (sum==area) return true;
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;
}