# I - Two Triangles FZU - 2270

Fat brother and Maze are playing a kind of special (hentai) game with some points in a two-dimensional plane. First Fat Brother would choose three different points and then Maze would choose other three different points. If both of the player’s points form a triangle, they would feel happy. Also, if these two triangles are exactly the same, they would feel even happier. The two triangles are considered the same if one can be changed from another by translation and rotation.

Now given N points in a plane, Fat Brother would like to know how many different sets of points they can choose in order to make them even happier.

Input

The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.

Then T cases follow, each case contains an integer N (6 <= N <= 10) indicated the number of the points in the two-dimensional plane. The N lines follow, each line contains two integers x and y (0 <= x, y <= 10) shows this point’s coordinate. All the points have different coordinate in this plane.

Output

For each case, output the case number first, and then output the number of the different sets of points they can choose in order to make them even happier.

Sample Input
3
6
0 0
2 0
2 1
8 8
10 8
10 9
6
0 0
2 0
2 1
8 8
10 8
10 7
6
0 0
1 0
2 0
0 1
1 1
2 1

Sample Output
Case 1: 2
Case 2: 0
Case 3: 6

Hint

In the first case, Fat Brother can choose a set which contains first three points and Maze can choose a set which contains last three points, this makes a suitable answer. Also, Fat Brother and Maze can change the set they choose and still make a solid result.

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#define bug(x) printf("%d***\n",x)
using namespace std;
typedef long long ll;

const double eps=1e-9;
const int maxn=20;
struct node{
double x,y;
node(){}
node(double _x,double _y){
x=_x,y=_y;
}
node operator - (const node& b){
return node(x-b.x,y-b.y);//简化
}
}p[maxn];
int ans=0,n;
int vis[20];
int num1[10],num2[10];
int tmp1[10],tmp2[10];
double e1[10],e2[10];
double getl(int a,int b){
double ans=sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));
return ans;
}

int is_no(){
double v1x=p[num1[0]].x-p[num1[1]].x,v1y=p[num1[0]].y-p[num1[1]].y;
double v2x=p[num1[2]].x-p[num1[1]].x,v2y=p[num1[2]].y-p[num1[1]].y;
if(fabs(v1x*v2y-v1y*v2x)<eps)return 1;
return 0;
}

int check(){
if(is_no())return 0;
/*
得利用一下极角排序，把他们在空间中的位置固定下来，要不然的话，这个顺序就没有办法确定
还有就是不能直接修改原先保留的数组，这样会导致我们之前的记录出现问题，得
重新开辟一个数组
*/
for(int i=0;i<3;i++){
tmp1[i]=num1[i],tmp2[i]=num2[i];
}
node p1,p2;
p1=p[tmp1[1]]-p[tmp1[0]],p2=p[tmp1[2]]-p[tmp1[0]];
if(p1.x*p2.y-p1.y*p2.x<0)swap(tmp1[1],tmp1[2]);

p1=p[tmp2[1]]-p[tmp2[0]],p2=p[tmp2[2]]-p[tmp2[0]];
if(p1.x*p2.y-p1.y*p2.x<0)swap(tmp2[1],tmp2[2]);

for(int i=0;i<3;i++){
e1[i]=getl(tmp1[i],tmp1[(i+1)%3]);
}
for(int i=0;i<3;i++){
e2[i]=getl(tmp2[i],tmp2[(i+1)%3]);
}
for(int i=0;i<3;i++){
int flag=1;
for(int j=0;j<3;j++){
int a=j,b=(i+j)%3;
if(fabs(e1[a]-e2[b])>eps){
flag=0;
break;
}
}
if(flag) return 1;
}
return 0;
}

void dfs2(int pre,int now){
if(now==3){
if(check()){
//	print();
ans++;
}
return;
}
for(int i=pre+1;i<=n;i++){
if(vis[i])continue;
vis[i]=1;
num2[now]=i;
dfs2(i,now+1);
vis[i]=0;
}
}

void dfs1(int pre,int now){
if(now==3){
//bug(1);
dfs2(0,0);
return;
}
for(int i=pre+1;i<=n;i++){
if(vis[i])continue;
vis[i]=1;
num1[now]=i;
dfs1(i,now+1);
vis[i]=0;
}
}

int main(){
int T,kase=1;
scanf("%d",&T);
while(T--){
memset(vis,0,sizeof(vis));
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lf %lf",&p[i].x,&p[i].y);
}
ans=0;
dfs1(0,0);
printf("Case %d: %d\n",kase++,ans);
}
return 0;
}

• 评论

• 下一篇
• 上一篇