FZU-1925+几何

时间:2023-03-09 16:31:33
FZU-1925+几何

题意简单。

由于没有注意到椭圆不一定是在圆心。。贡献无数的wa。。。。。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
using namespace std; const int maxn = 555;
const int maxm = 555;
const double eps = 1e-8; struct Node{
char name[55];
char nation[55];
int sum;
int id;
double x,y;
}p[ maxn ]; struct Cir{
double r;
double x,y;
int val;
}c1[ maxm ];
struct Cir2{
double x,y;
double a,b;
int val;
}c2[ maxm ];
struct Point {
double x,y;
};
struct Ploy{
Point pnt[ maxn ];
int cnt;
int val;
}ploy[ maxm ]; int od[ maxm ]; int cmp( Node a,Node b ){
if( a.sum!=b.sum ) return a.sum>b.sum;
else return a.id<b.id;
} double dis( double x1,double y1,double x2,double y2 ){
return ( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) );
} bool InCir( Node aim,int ID ){
double dd = dis( aim.x,aim.y,c1[ID].x,c1[ID].y );
if( dd<=c1[ID].r*c1[ID].r ) return true;
else return false;
} bool InCir2( Node aim,int ID ){
double dd = (aim.x-c2[ID].x)*(aim.x-c2[ID].x)/(c2[ID].a*c2[ID].a)+(aim.y-c2[ID].y)*(aim.y-c2[ID].y)/(c2[ID].b*c2[ID].b);
if( dd<=1.0 ) return true;
else return false;
} int D( double x ){
return x<-eps?-1:x>eps;
} double det( Point a,Point b,Point c ){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} int InPloy1( int n,double xx,double yy,Point pnt[] ){
Point q;
q.x = xx,q.y = yy;
int i,s[3] = {1,1,1};
pnt[n] = pnt[0];
for( int i=0;i<n&&s[0]|s[2];i++ ){
s[ D(det(pnt[i],pnt[i+1],q))+1 ] = 0;
}
return s[0]|s[2];
}
int InPloy2( int n,double xx,double yy,Point pnt[] ){
Point q;
q.x = xx;
q.y = yy;
int i,s[3] = {1,1,1};
pnt[n] = pnt[0];
for( int i=0;i<n&&s[1]&&s[0]|s[2];i++ ){
s[ D(det(pnt[i],pnt[i+1],q))+1 ] = 0;
}
return s[1]&&s[0]|s[2];
} void init(){
for( int i=0;i<maxn;i++ )
p[i].sum = 0;
} void test( int n ){
for( int i=1;i<=n;i++ ){
printf("name = %s, sum = %d\n",p[i].name,p[i].sum);
}
} int main(){
int T;
scanf("%d",&T);
int Case = 1;
while( T-- ){
int n,m;
scanf("%d",&m);
init();
char str[ 55 ];
for( int i=1;i<=m;i++ ){
scanf("%s",str);
if( str[0]=='C' ){
od[ i ] = 1;
scanf("%lf%lf%lf%d",&c1[ i ].x,&c1[ i ].y,&c1[ i ].r,&c1[ i ].val);
}
else if( str[0]=='E' ){
od[ i ] = 2;
scanf("%lf%lf%lf%lf%d",&c2[ i ].x,&c2[ i ].y,&c2[ i ].a,&c2[ i ].b,&c2[ i ].val);
}
else {
od[ i ] = 3;
int cc;
scanf("%d",&cc);
for( int j=0;j<cc;j++ ){
scanf("%lf%lf",&ploy[i].pnt[j].x,&ploy[i].pnt[j].y);
}
ploy[i].cnt = cc;
scanf("%d",&ploy[i].val);
}
}
scanf("%d",&n);
for( int i=1;i<=n;i++ ){
scanf("%s%s%lf%lf",p[i].name,p[i].nation,&p[i].x,&p[i].y);
//p[i].sum = 0;
p[i].id = i;
}
for( int i=1;i<=n;i++ ){
for( int j=1;j<=m;j++ ){
if( od[j]==1&&InCir( p[i],j )==true ){
p[i].sum += c1[j].val;
}
else if( od[j]==2&&InCir2( p[i],j )==true ){
p[i].sum += c2[j].val;
}
else if( od[j]==3&&(InPloy1( ploy[j].cnt,p[i].x,p[i].y,ploy[j].pnt )||InPloy2( ploy[j].cnt,p[i].x,p[i].y,ploy[j].pnt )) ){
p[i].sum += ploy[j].val;
}
}
} sort( p+1,p+1+n,cmp );
//test( n );
printf("Case %d:\n",Case ++ );
int Gold = 0;
if( p[1].sum<=0 ) continue;
int flag = 1;
for( int i=1;i<=n;i++ ){
if( p[i].sum==p[1].sum&&p[1].sum>0 ){
printf("Gold Medal: %s from %s got %d point(s)\n",p[i].name,p[i].nation,p[i].sum);
Gold ++ ;
flag = i;
}
else break;
}
if( p[flag+1].sum<=0 ) continue;
if( Gold>=3 ) continue;
int Silver = 0;
int temp = flag+1;
bool f = false;
for( int i=temp;i<=n;i++ ){
if( p[i].sum==p[temp].sum && p[i].sum>0 ){
flag = i;
Silver ++ ;
if( Gold<=1 ) printf("Silver Medal: %s from %s got %d point(s)\n",p[i].name,p[i].nation,p[i].sum);
else{
f = true;
printf("Bronze Medal: %s from %s got %d point(s)\n",p[i].name,p[i].nation,p[i].sum);
}
}
else break;
}
if( Silver+Gold>=3||f==true ) continue;
if( p[flag+1].sum<=0 ) continue;
for( int i=flag+1;i<=n;i++ ){
if( p[i].sum==p[flag+1].sum&&p[i].sum>0 ){
printf("Bronze Medal: %s from %s got %d point(s)\n",p[i].name,p[i].nation,p[i].sum);
}
else break;
}
}
return 0;
}