某神的代码:
#include<stdio.h>
#define max(x,y) (x)>(y)?(x):(y)
#define min(x,y) (x)<(y)?(x):(y)
const int inf=0x7fffffff;
struct node // Fruit
{
int adv;
int x[11],y[11];
}Fruit[11];
int Fruit_num,ans;
//----
int judge( int x1,int y1,int x2,int y2,int x,int y )
{
return ( ( x1-x )*( y2-y ) - ( x2-x )*( y1-y ) );
}
bool on_megment( int x1,int y1,int x2,int y2,int x3,int y3 )
{
int t1=x1-x3;
int t2=y1-y3;
int t3=x1-x2;
int t4=y1-y2;
if( ( t1*t4-t2*t3 )==0 )
return true;
else return false;
}
bool megment( int x1,int y1,int x2,int y2,int p1,int q1,int p2,int q2 )
{
if( on_megment( p1,q1,p2,q2,x1,y1 )|| on_megment( p1,q1,p2,q2,x2,y2 ) )
return true;
int d1=judge( p1,q1,p2,q2,x1,y1 );
int d2=judge( p1,q1,p2,q2,x2,y2 );
if( d1*d2<0 ) return true;
return false;
}
//---
/*
bool megment1( int p1,int q1,int p2,int q2, int x1,int y1,int x2,int y2 )
{
if ( x1 != x2 ) // k exsit
{
double a = (y1-y2)/(x1-x2);
double b = y1;
if( a*p1+b < q1 && a*p2+b < q2 || a*p1+b > q1 && a*p2+b > q2 )
return false;
return true;
}
else
{
if( p1 > x1 && p2 > x2 || p1 < x1 && p2 < x2)
return false;
return true;
}
}*/
void getFruit()
{
for(int i = 1; i <= Fruit_num; ++i )
{
scanf("%d",&(Fruit[i].adv) );
for(int j = 1; j <= Fruit[i].adv; ++j )
{
scanf("%d%d",&(Fruit[i].x[j]),&(Fruit[i].y[j]));
}
}
}
void Search()
{
for(int i = 1; i <= Fruit_num; ++i ) // 选取任意两个水果
for( int j = i+1; j <= Fruit_num; ++j )
{
for(int a = 1; a <= Fruit[i].adv; ++a ) //第一个水果顶点
{
for(int b = 1; b <= Fruit[j].adv; ++b ) //第二个水果顶点 作为直线
{
int x1 = Fruit[i].x[a], y1 = Fruit[i].y[a];
int x2 = Fruit[j].x[b], y2 = Fruit[j].y[b];
int cut_num = 2;
for( int c = 1; c <= Fruit_num; ++c ) //对剩余的水果进行枚举比较
{
if( c == i || c == j ) continue;
bool flag = false;
int d;
for( d = 1; d < Fruit[c].adv; ++d )//选取相邻两顶点
{
if(flag) continue;
if( megment(Fruit[c].x[d],Fruit[c].y[d],Fruit[c].x[d+1],Fruit[c].y[d+1] ,x1,y1,x2,y2 ) )
flag = true;
}
if( megment(Fruit[c].x[d],Fruit[c].y[d],Fruit[c].x[1],Fruit[c].y[1],x1,y1,x2,y2 ) )
flag = true;
if(flag) cut_num++;
}
ans = max(ans,cut_num);
}
}
}
}
int main()
{
int t, Case = 1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&Fruit_num);
getFruit(); //Input the Fruit.
ans = 0;
Search(); //Search the Max numbers of Fruit.
if( Fruit_num == 1 )
printf("Case %d: %d\n",Case++,1);
else
printf("Case %d: %d\n",Case++,ans);
}
return 0;
}