FZOJ Problem 2148 Moon Game

FZOJ Problem 2148 Moon Game,第1张

FZOJ Problem 2148 Moon Game                                                                                               Problem 2148 Moon Game 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 2 4 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个点,现在由这n个点中任意的四个组成四边形,穷尽所有的可能,问n个点总共能产生多少个凸四边形。


思路:假定取出了一个四边形,用四边形的四个顶点组成三角形,一共可以组成4个三角形,如果是凹四边形,则一定存在其中一个三角形的面积是其余三个三角形的面积之和。


已知三角形的三个顶点的坐标,由行列式                                                   |1     1    1   |        计算可得三角形的面积。


                                                  |x1    x2  x3   |*1/2                                                   |y1    y2    y3  |   AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int N_MAX = + ;
int n;
pair<ll, ll>cor[N_MAX]; ll fab(ll a) {
return a >= ? a : -a;
} int S(int a,int b,int c) {
return fab(cor[a].first*(cor[b].second-cor[c].second)+cor[b].first*(cor[c].second-cor[a].second)+cor[c].first*(cor[a].second-cor[b].second)) ;
} bool judge(int a,int b,int c,int d) {
if (S(a, b, c) == S(a, b, d) + S(a, c, d) + S(b, c, d))
return false;//凹四边形
return true;
} int main() {
int T;
scanf("%d", &T);
int cs = ;
while (T--) {
cs++;
scanf("%d",&n);
for (int i = ; i < n;i++) {
scanf("%lld%lld",&cor[i].first,&cor[i].second);
}
int num = ;
for (int i = ; i < n;i++)
for (int j = i + ; j < n;j++)
for (int k = j + ; k < n;k++)
for (int l = k + ; l < n; l++)
if (judge(i, j, k, l) &&judge(j,i,l,k)&&judge(k,l,i,j)&&judge(l,k,j,i) ) {
num++;
} printf("Case %d: %d\n",cs,num);
}
return ;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/585421.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存