http://poj.org/problem?id=2087
#include<iostream>
#include"stdio.h"
#include"math.h"
#include<algorithm>
using namespace std;
/////////////////////////
#define Type double /*�������*/
/////////////////////////
struct point
{
Type x,y;
int host;
};
const double pi=3.1415926535898;
inline Type cheng(point a,point b,point c)
{return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);}
inline Type dcheng(point a,point b,point c)
{return (b.x-a.x)*(c.x-a.x)+(c.y-a.y)*(b.y-a.y);}
double jl(point a,point b)
{
return ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
const double eps=0.0000001;
point object(point a,double degree,double len)
{
point c;
c.x=a.x+len*cos(degree/180*pi);
c.y=a.y+len*sin(degree/180*pi);
c.host=a.host;
return c;
}
point p[10];
int n;
void throwball(point a,point b,int prev)
{
point pt;
int k=-1,i;double l=9999999,t;
for(i=0;i<n;i++)
if(i!=prev)
{
if(fabs(cheng(p[i],a,b))<eps&&dcheng(p[i],a,b)<-eps)
{
t=jl(p[i],a);
if(t<l)
{
k=i;
l=t;
}
}
}
if(k<0)
{
p[n++]=b;
for(i=0;i<n;i++)
if(p[i].host==-1)break;
if(i!=0)swap(p[i],p[0]);
}
else
{
pt=p[k];
p[k].host=a.host;
b.host=pt.host;
throwball(pt,b,k);
}
}
int cmp(point a,point b)
{
return jl(a,p[0])<jl(b,p[0]);
}
void doit()
{
int key;int use[2]={0,0};
char name1[100],name2[100];
cin>>name1>>name2;
point start;
double degree,len,t;
cin>>start.x>>start.y>>degree>>len;
p[0]=object(start,degree,len);
p[0].host=-1;
n=1;
cin>>start.x>>start.y>>degree>>len;
start.host=0;
throwball(start,object(start,degree,len),-1);
cin>>start.x>>start.y>>degree>>len;
start.host=1;
throwball(start,object(start,degree,len),-1);
int i,j,k;
for(i=3;i<7;i++)
{
k=-1;len=9999999;
if(use[0]==2)key=0;
else if(use[1]==2)key=1;
else for(j=1;j<n;j++)
{
t=jl(p[0],p[j]);
if(k==-1||t<len)
{
k=j;
len=t;
key=p[j].host;
}
}
cin>>start.x>>start.y>>degree>>len;
start.host=1-key;
if(use[start.host]>=2)while(1);
use[start.host]++;
throwball(start,object(start,degree,len),-1);
}
i=i;
sort(&p[1],&p[7],cmp);
if(p[1].host==0)cout<<name1<<' ';
else cout<<name2<<' ';
for(i=1;p[i].host==p[1].host;i++) ;
cout<<i-1<<endl;
return;
}
int main()
{
int t;
cin>>t;
while(t--)
{
doit();
}
return 0;
}