码迷,mamicode.com
首页 > 其他好文 > 详细

FZU - 2148 Moon Game

时间:2015-04-13 09:31:42      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

技术分享 Problem 2148 Moon Game

Accept: 499    Submit: 1398
Time Limit: 1000 mSec    Memory Limit : 32768 KB

技术分享 Problem Description

Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimensional plane. Then Fat brother starts to draw N starts in the sky which we can just consider each as a point. After he draws these stars, he starts to sing the famous song “The Moon Represents My Heart” to Maze.

You ask me how deeply I love you,

How much I love you?

My heart is true,

My love is true,

The moon represents my heart.

But as Fat brother is a little bit stay-adorable(呆萌), he just consider that the moon is a special kind of convex quadrilateral and starts to count the number of different convex quadrilateral in the sky. As this number is quiet large, he asks for your help.

技术分享 Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains an integer N describe the number of the points.

Then N lines follow, Each line contains two integers describe the coordinate of the point, you can assume that no two points lie in a same coordinate and no three points lie in a same line. The coordinate of the point is in the range[-10086,10086].

1 <= T <=100, 1 <= N <= 30

技术分享 Output

For each case, output the case number first, and then output the number of different convex quadrilateral in the sky. Two convex quadrilaterals are considered different if they lie in the different position in the sky.

技术分享 Sample Input

24
0 0
100 0
0 100
100 100
4
0 0
100 0
0 100
10 10

技术分享 Sample Output

Case 1: 1
Case 2: 0


给出n个点(不重,没有三点共线),求能组成多少个凸四边形。凹四边形一定有一个点在其他三个点组成的三角形内,假设为d点,此时Sabc=Sabd+Sacd+Sbcd。因为n最大就30,可以枚举所有不同的四个点,只要四个点中没有内点满足上面等式就是凸四边形。

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
const double Exp = 10e-6;
struct Point
{
	int x;
	int y;
};
double area(Point a, Point b, Point c)
{
	return fabs(1.0*((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x))) / 2.0;
}

bool check(Point a, Point b, Point c, Point d)
{
	if (fabs(area(a, b, c) - area(a, b, d) - area(b, c, d) - area(a, c, d)) < Exp)
		return false;
	return true;
}
int main()
{
	int casen;
	cin >> casen;
	for (int cas = 1; cas <= casen; cas++)
	{
		Point p[35];
		int n;
		int cnt = 0;
		cin >> n;
		for (int i = 0; i < n; i++)
			cin >> p[i].x >> p[i].y;
		for (int p1 = 0; p1 < n; p1++)
		for (int p2 = p1 + 1; p2 < n; p2++)
		for (int p3 = p2 + 1; p3 < n; p3++)
		for (int p4 = p3 + 1; p4 < n; p4++)
		{
			if (check(p[p1], p[p2], p[p3], p[p4]) && check(p[p1], p[p4], p[p3], p[p2]) && check(p[p1], p[p2], p[p4], p[p3]) && check(p[p4], p[p2], p[p3], p[p1]))
				cnt++;
		}
		cout << "Case " << cas << ": " << cnt << endl;
	}
}



FZU - 2148 Moon Game

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/45017123

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!