I - Two Triangles FZU - 2270

原创 2018年04月17日 16:46:04

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;
}


版权声明:小白一个,欢迎各位指错。 https://blog.csdn.net/qq_36424540/article/details/79977047

Android网络框架Volley项目实战

-
  • 1970年01月01日 08:00

FZU 2270 Two Triangles (计算几何)

注意: 注意判断三点共线 注意三角形的判定,对称的不计。 注意判别重合状态,防止计数计多了。 #include #include #include #include #define eps 1e-6...
  • wing_wuchen
  • wing_wuchen
  • 2017-07-18 20:47:40
  • 306

fzu 2273 Triangles 计算几何

Problem 2273 Triangles Time Limit: 1000 mSec    Memory Limit : 262144 KB  Problem Descriptio...
  • u013491262
  • u013491262
  • 2017-07-25 09:46:41
  • 315

FZU2273Triangles+(三角形)+第八届福建省大学生程序设计竞赛

Problem 2273 Triangles Accept: 47    Submit: 115 Time Limit: 1000 mSec    Memory Limit : 262144 KB ...
  • hyyjiushiliangxing
  • hyyjiushiliangxing
  • 2017-07-24 11:06:38
  • 127

Two Triangles FZU - 2270

Fat brother and Maze are playing a kind of special (hentai) game with some points in a two-dimension...
  • w571523631
  • w571523631
  • 2017-08-10 17:28:17
  • 139

I - Two Triangles FZU - 2270

Fat brother and Maze are playing a kind of special (hentai) game with some points in a two-dimensio...
  • qq_36424540
  • qq_36424540
  • 2018-04-17 16:46:04
  • 8

Two Triangles FZU - 2270 (计算几何,叉积判断对称)

Two Triangles FZU - 2270 Fat brother and Maze are playin...
  • codeswarrior
  • codeswarrior
  • 2018-04-18 18:59:59
  • 26

Gym 100971C Triangles

题目链接题意:给定n个数,问是否存在一个数,使得这个数与该数列的任意2个组成一个非退化的三角形(即三角形面积不为0)。分析:简单的三角不等式|a-b|#include #include #includ...
  • HYB733093411
  • HYB733093411
  • 2016-07-31 13:52:54
  • 227

Hurdles of 110m ZOJ - 2972 (DP)

Hurdles of 110m ZOJ - 2972 In the year 2008, the 29th Ol...
  • codeswarrior
  • codeswarrior
  • 2018-04-18 19:23:02
  • 12

C - Knapsack problem FZU - 2214

Given a set of n items, each with a weight w[i] and a value v[i], determine a way to choose the ite...
  • qq_36424540
  • qq_36424540
  • 2018-04-18 18:15:17
  • 5
收藏助手
不良信息举报
您举报文章:I - Two Triangles FZU - 2270
举报原因:
原因补充:

(最多只允许输入30个字)