Problem 2148 Moon Game

Accept: 24    Submit: 61 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

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
 
福州大学,福建省赛;ps:http://acm.fzu.edu.cn/problem.php?pid=2148
 
题意;平面上给定N个点求不同的凸四边形个数;
 
思路:凸四边形的对角线相交;关键是判断对角线相交问题,先连接两直线,然后另外的两点代入直线,得到s1,s2;
 
s1*s2<0,表示在线段两侧,这里要用两次比较;即当a,b做线段时,判断点d,c是否在线段两端;当c,d做线段时,
 
判断a,b是否在线段两端,这样是为了排除三个点共线的情况!
 
详见代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#define MAX 35
__int64 ans[MAX][]; int cheak(int i,int j,int k,int l)
{ __int64 x1,y1,x2,y2,x3,y3,x4,y4;
x1=ans[i][];
y1=ans[i][];
x2=ans[j][];
y2=ans[j][];
x3=ans[k][];
y3=ans[k][];
x4=ans[l][];
y4=ans[l][];
double k1,k2,b1,b2,s1,s2,s3,s4;
if(x2==x1&&x3==x4)
return ;
if(x2==x1&&x3!=x4)
{
s1=x3-x1;
s2=x4-x1;
if(s1*s2>=)
return ;
else
{
k2=(y3-y4)*1.0/(x3-x4);
b2=y3-k2*x3;
s3=(y2-b2)-k2*x2;
s4=(y1-b2)-k2*x1;
if(s3*s4>=)
return ;
if(s1*s2<&&s3*s4<)
return ;
} }
if(x3==x4&&x1!=x2)
{
s3=x1-x3;
s4=x2-x3;
if(s3*s4>=)
return ;
else
{
k1=(y2-y1)*1.0/(x2-x1);
b1=y1-k1*x1;
s1=(y3-b1)-k1*x3;
s2=(y4-b1)-k1*x4;
if(s1*s2>=)
return ;
if(s1*s2<&&s3*s4<)
return ;
}
}
else
{
k1=(y2-y1)*1.0/(x2-x1);
b1=y1-k1*x1;
s1=(y3-b1)-k1*x3;
s2=(y4-b1)-k1*x4;
if(s1*s2>=)
{
return ;
}
else
{
k2=(y3-y4)*1.0/(x3-x4);
b2=y3-k2*x3;
s3=(y2-b2)-k2*x2;
s4=(y1-b2)-k2*x1;
if(s3*s4>=)
return ;
if(s1*s2<&&s3*s4<)
return ;
}
}
} int main()
{
int T,N;
int i,j,k,l,cnt;
scanf("%d",&T);
for(cnt=;cnt<=T;cnt++)
{
scanf("%d",&N);
memset(ans,,sizeof(ans));
for(i=;i<N;i++)
{
scanf("%I64d%I64d",&ans[i][],&ans[i][]);
}
int temp=;
for(i=;i<N-;i++)
for(j=i+;j<N-;j++)
for(k=j+;k<N-;k++)
for(l=k+;l<N;l++)
{
if(cheak(i,j,k,l))
temp++;
if(cheak(i,k,j,l))
temp++;
if(cheak(i,l,k,j))
temp++;
}
printf("Case %d: %d\n",cnt,temp); }
return ;
} /*
20
4
0 0
100 0
0 100
100 100
5
0 0
10 0
0 5
5 5
15 0
4
0 0
100 0
0 100
10 10
5
1 1
5 6
9 7
5 5
2 2
4
1 1
1 1
1 1
1 1
5
1 1
2 2
3 3
4 4
5 5
6
5 8
6 4
1 0
10 5
8 6
3 5 */

   

    表示比赛的时候策略错误。。。应该让我自己做这题的,不过还是很感谢我给力的队友啊。。。    

(虽然我是个小坑!              o(∩_∩)o 哈哈)那么我会好好努力的,大家一起加油哈!

Moon Game (凸四边形个数,数学题)的更多相关文章

  1. HDU3629(凸四边形的个数)

    HDU 3629 计算几何 题目描述:给你n个点(4~700), 问你能够成多少个不同的凸四边形. 解题报告: 暴力的话C(700,4)必然超时,发现,任何一个凹包必然是其中一点在其它3点构成的三角形 ...

  2. FZU Problem 2148 Moon Game (判断凸四边形)

    题目链接 题意 : 给你n个点,判断能形成多少个凸四边形. 思路 :如果形成凹四边形的话,说明一个点在另外三个点连成的三角形内部,这样,只要判断这个内部的点与另外三个点中每两个点相连组成的三个三角形的 ...

  3. 暴力(判凸四边形) FZOJ 2148 Moon Game

    题目传送门 题意:给了n个点的坐标,问能有几个凸四边形 分析:数据规模小,直接暴力枚举,每次四个点判断是否会是凹四边形,条件是有一个点在另外三个点的内部,那么问题转换成判断一个点d是否在三角形abc内 ...

  4. 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

  5. ACM学习历程—FZU2148 Moon Game(计算几何)

    Moon Game Description Fat brother and Maze are playing a kind of special (hentai) game in the clearl ...

  6. Problem A: 踢罐子 解题报告

    Problem A: 踢罐子 Description 平面上有\(n\)个点,其中任意2点不重合,任意3点不共线. 我们等概率地选取一个点A,再在剩下的\(n-1\)个点中等概率地选取一个点B,再在剩 ...

  7. fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)

    题目:http://acm.fzu.edu.cn/problem.php?pid=2148 题意:给出n个点,判断可以组成多少个凸四边形. 思路: 因为n很小,所以直接暴力,判断是否为凸四边形的方法是 ...

  8. ACM: FZU 2148 Moon Game - 海伦公式

     FZU 2148  Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  9. 数论 - Moon Game

    Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we ca ...

随机推荐

  1. UWP开发---抓包分析

    一,使用工具 ①Fiddler 摘自百度百科Fiddler简介: Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的“进出”Fi ...

  2. MVC 5使用ViewData(模型)显示数据

    看过此篇<MVC 5使用ViewData(对象)显示数据>http://www.cnblogs.com/insus/p/3377178.html 都明白在控制器使用ViewData(obj ...

  3. 【Anaconda】:科学计算的Python发行版

    [背景] Python易用,但包管理和Python不同版本的问题比较头疼,特别是当你使用Windows的时候.为了解决这些问题,有不少发行版的Python,比如WinPython.Anaconda等, ...

  4. 怎么把excel表格内的数据导入数据库?

    第一种方法: 思路:想要把excel表格内的数据直接导入数据库不是那么容易,可以把excel表格另存为.csv格式的文档(特点:内容以逗号分割):然后通过一系列的文档操作函数处理成为一个二维数组,然后 ...

  5. 玄武短信接口和移动MAS短信接口的API封装

    直接上代码,关键点: 133行的敏感词过滤 176行的6位扩展码写入 using System; using System.Collections.Generic; using System.Linq ...

  6. MVC3学习:利用mvc3+ajax结合MVCPager实现分页

    本例使用表格Users(Uid,UserName,PassWord),数据库访问使用EF first code. public class Users { [Key] public int Uid { ...

  7. Shell 相互调用

    Shell 文件包含 和其他语言一样,Shell 也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件. Shell 文件包含的语法格式如下: . filename # 注意点号( ...

  8. 文件句柄FileDescriptor的hanle/fd两个字段分析

    对于FileInputStream/FileOutputStream/RandomAccessFile,使用handle来表示底层的文件句柄 对于ServerSocket/Socket,使用fd来表示 ...

  9. 21-hadoop-weibo推送广告

    1, tf-idf 计算每个人的词条中的重要度 需要3个mapreduce 的 job执行, 第一个计算 TF 和 n, 第二个计算 DF, 第三个代入公式计算结果值 1, 第一个job packag ...

  10. Linux-(rcp,scp)

    rcp命令 1.命令格式: rcp [参数] [源文件] [目标文件] 2.命令功能: rcp命令用在远端复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前 ...