记录编号 |
97325 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[USACO Jan14]奶牛冰壶运动 |
最终得分 |
100 |
用户昵称 |
OI永别 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.340 s |
提交时间 |
2014-04-18 14:51:33 |
内存使用 |
7.94 MiB |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 100001
struct arr{
long long x,y;
}s1[N],s2[N],a[N],b[N],ss[N];
int top1,top2;
int n;
long long are1,are2;
inline long long tf(long long x){
return x >= 0? x: -x;
}
bool comp(const arr &a,const arr & b){
if (a.y < b.y) return 1;
if (a.y > b.y) return 0;
return a.x < b.x;
}
inline long long angle(const arr &a,const arr & b,const arr & c){// ab ×ac 逆时针>0
int p1 = b.x - a.x,q1 = b.y - a.y;
int p2 = c.x - a.x,q2 = c.y - a.y;
return (long long)p1 * q2 - (long long)p2 * q1;
}
void work1(){
sort(a + 1,a + 1 + n,comp);
s1[++top1] = a[1];
s1[++top1] = a[2];
for (int i = 3;i <= n; i++){
while (top1 > 1 && angle(s1[top1 - 1],s1[top1],a[i]) <= 0) top1 --;
s1[++top1] = a[i];
}
int p = top1;
for (int i = n - 1;i; i--){
while (top1 - p > 0 && angle(s1[top1 - 1],s1[top1],a[i]) <= 0) top1 --;
s1[++top1] = a[i];
}
return;
}
void work2(){
sort(b + 1,b + 1 + n,comp);
s2[++top2] = b[1];
s2[++top2] = b[2];
for (int i = 3;i <= n; i++){
while (top2 > 1 && angle(s2[top2 - 1],s2[top2],b[i]) <= 0) top2 --;
s2[++top2] = b[i];
}
int p = top2;
for (int i = n - 1; i >= 1; i--){
while (top2 - p > 0 && angle(s2[top2 - 1],s2[top2],b[i]) <= 0) top2 --;
s2[++top2] = b[i];
}
return;
}
void gets1(){
arr node;
node.x = node.y = 0;
are1 = 0;
for (int i = 1; i< top1; i++){
are1 += angle(node,s1[i],s1[i + 1]);
}
are1 = tf(are1);
}
void gets2(){
arr node;node.x = node.y = 0;
are2 = 0;
for (int i = 1; i< top2; i++){
are2 += angle(node,s2[i],s2[i + 1]);
}
are2 = tf(are2);
}
int main(){
freopen("curling.in","r",stdin);
freopen("curling.out","w",stdout);
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(s1,0,sizeof(s1));
memset(s2,0,sizeof(s2));
for (int i = 1; i <= n; i ++){
scanf("%lld%lld",&a[i].x,&a[i].y);
}
for (int j = 1; j <= n; j++){
scanf("%lld%lld",&b[j].x,&b[j].y);
}
work1();
work2();
gets1();
gets2();
int ansb = 0;
long long s = 0;
for (int i = 1; i <= n; i++){
s = 0;
for (int j = 1; j < top1; j++){
s += (long long)abs(angle(s1[j + 1],s1[j],b[i]));
if (s > are1) break;
}
if (s == are1) ansb++;
}
int ansa = 0;
for (int i = 1; i <= n; i++){
s = 0;
for (int j = 1; j < top2; j++){
s += (long long)abs(angle(s2[j + 1],s2[j],a[i]));
if (s > are2) break;
}
if (s == are2) ansa++;
}
if (!are1) ansb--;
if (!are2) ansa--;
printf("%d %d\n",ansb,ansa);
return 0;
}