Moon Game

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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
题意:t组数据,每组n个点,n小于等于30,问从这些点中任取四个点构成的四边形有多少个是凸四边形。
题解:暴力跑,用三角形有向面积的绝对值判断是否为凹多边形,注意优化即可。
开始用ijkl都是从0开始跑的叉积判断,TLE了,这道题用面积判断更好。
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
const double PI=acos(-1.0);
using namespace std;
struct Point{
double x,y;
int id;
Point(double x=,double y=,int id=-):x(x),y(y){} //构造函数,方便代码编写
};
typedef Point Vector; //从程序上实现,Vector只是Point的别名
Vector operator + (Vector A,Vector B)
{
return Vector(A.x+B.x,A.y+B.y);
}
//点-点=向量
Vector operator - (Point A,Point B)
{
return Vector(A.x-B.x,A.y-B.y);
}
//向量*数=向量
Vector operator * (Vector A,double p)
{
return Vector(A.x*p,A.y*p);
}
//向量/数=向量
Vector operator / (Vector A,double p)
{
return Vector(A.x/p,A.y/p);
}
//运算符重载
bool operator <(const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps=1e-;
//三态函数精度问题
int dcmp(double x)
{
if(fabs(x)<eps) return ; else return x<?-:;
}
bool operator ==(const Point &a,const Point &b)
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
//叉积
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
double Area(Point A,Point B,Point C)
{
return Cross(B-A,C-A);
}
int main()
{
int t,cas=;
scanf("%d",&t);
while(t--)
{
int n;
Point p[];
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int ans=;
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++)
{
double a=fabs(Area(p[i],p[j],p[k])); //有向面积
double b=fabs(Area(p[j],p[k],p[l]));
double c=fabs(Area(p[k],p[l],p[i]));
double d=fabs(Area(p[l],p[i],p[j]));
double m=max(max(a,b),max(c,d));
double sum=a+b+c+d-m;
if(sum==m)
continue;
ans++;
}
printf("Case %d: %d\n",cas++,ans);
}
return ;
}

FZU 2148 moon game (计算几何判断凸包)的更多相关文章

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

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

  2. FZU 2148 Moon Game

    Moon Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

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

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

  4. FZU 2148 Moon Game --判凹包

    题意:给一些点,问这些点能够构成多少个凸四边形 做法: 1.直接判凸包 2.逆向思维,判凹包,不是凹包就是凸包了 怎样的四边形才是凹四边形呢?凹四边形总有一点在三个顶点的内部,假如顶点为A,B,C,D ...

  5. POJ 1584 A Round Peg in a Ground Hole[判断凸包 点在多边形内]

    A Round Peg in a Ground Hole Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6682   Acc ...

  6. hrbustoj 1318:蛋疼的蚂蚁(计算几何,凸包变种,叉积应用)

    蛋疼的蚂蚁 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 39(22 users)    Total Accepted: 26 ...

  7. poj 1696:Space Ant(计算几何,凸包变种,极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2876   Accepted: 1839 Descrip ...

  8. FZOJ Problem 2148 Moon Game

                                                                                                  Proble ...

  9. poj1584(判断凸包+求点到线段的距离)

    题目链接:https://vjudge.net/problem/POJ-1584 题意:首先要判断凸包,然后判断圆是否在多边形中. 思路: 判断凸包利用叉积,判断圆在多边形首先要判断圆心是否在多边形中 ...

随机推荐

  1. spring获取ApplicationContext对象的方法——ApplicationContextAware

    一. 引言 工作之余,在看一下当年学的spring时,感觉我们以前都是通过get~ set~方法去取spring的Ioc取bean,今天就想能不能换种模型呢?因为我们在整合s2sh时,也许有那么一天就 ...

  2. [Unity 游戏设计的元素]

    1.核心游戏机制 2.主题 3.功能集合 4.可能的附加功能 5.备用主题创意

  3. java中的不为空判断

    String不为空判断 if(null != str && !"".equals(str)) List不为空判断 if(list!=null && ...

  4. jboss7 添加虚拟目录 上传文件路径

    直接在jboss-as-7.1.1.Final\welcome-content\下加个子目录: jboss-as-7.1.1.Final\welcome-content\logs. 即可访问.

  5. 学习笔记-Kuaihu(仿知乎日报)

    本文目的:由于第一次学习较为完整的项目,故作记录以系统地整理APP开发知识 先看看整个项目结构: activity, fragment, 不用说了.可以看做MVC中的controller db, 存储 ...

  6. Spring学习8-Spring事务管理(注解式声明事务管理)

    步骤一.在spring配置文件中引入<tx:>命名空间 <beans xmlns="http://www.springframework.org/schema/beans& ...

  7. UML(5)——协作图

    协作图中表示了角色之间的关系,通过协作图限定协作中的对象或链.协作指的是在一定的语境中一组对象以及实现某些行为的对象间的相互作用. 协 作图是表现对象协作关系的图,表示了协作中作为各种类元角色的对象所 ...

  8. ASP.NET 5 :上传文件(转)

    (此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:在ASP.NET 5(MVC 6)中处理上传文件的方式和之前有所不同. 在MVC 5之前的版本中上传文件, ...

  9. 搜狗2013年校园招聘研发类笔试试卷之C/C++类

    今天无聊在网上搜了下今年各大NB IT公司的笔试题,搜到了搜狗的,只有扫描版的试卷没有电子版也没有答案,就拿来做了做,题目非常多,涉及到C/C++.Java.数据结构.Android.IOS.Java ...

  10. 分页控件-ASP.NET(AspNetPager)

    AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: <div class="oa-el ...