FZU-2148-Moon Game,,几何计算~~
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
Sample Output
题意也不难懂,就是找有多少个凸四边形,而且题目不会有三点共线的情况,开始做的时候想的是用角度判断的方法,,快结束了才知道思路是错的,记得在小白书(算法入门经典)85业看过有向三角形面积计算,目的就是判断一个点是否在三角形内,,这个题就可以用这种思路,也就是说如果所选四个点中有一个点在其他三个点所围成的三角形内部,他就是凹三角形,反之~~~~
有了正确思路,代码就不成问题了吧;
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=50;
struct node
{
int x,y;
} a[N];
int fun(int a)
{
return a>0?a:-a;//因为是有向面积,可正可负;
}
int mj(int x1,int y1,int x2,int y2,int x3,int y3)
{
return fun(x1*y2+x3*y1+x2*y3-x3*y2-x1*y3-x2*y1);//有向面积计算公式;
}
int main()
{
int t,n;
scanf("%d",&t);
int t1=t;
while(t--)
{
int sum=0;
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%d%d",&a[i].x,&a[i].y);
for(int i=1; i<=n-3; i++)
for(int j=i+1; j<=n-2; j++)
for(int k=j+1; k<=n-1; k++)
for(int l=k+1; l<=n; l++)
{
if(mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y)==mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)+
mj(a[i].x,a[i].y,a[l].x,a[l].y,a[k].x,a[k].y)+mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y))
continue;//点l在中间的情况;
if(mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)==mj(a[i].x,a[i].y,a[k].x,a[k].y,a[l].x,a[l].y)+
mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y)+mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y))
continue;//点k在中间的情况;
if(mj(a[i].x,a[i].y,a[k].x,a[k].y,a[l].x,a[l].y)==mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)+
mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y)+mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y))
continue;//点j在中间的情况;
if(mj(a[l].x,a[l].y,a[j].x,a[j].y,a[k].x,a[k].y)==mj(a[i].x,a[i].y,a[j].x,a[j].y,a[l].x,a[l].y)+
mj(a[i].x,a[i].y,a[l].x,a[l].y,a[k].x,a[k].y)+mj(a[i].x,a[i].y,a[j].x,a[j].y,a[k].x,a[k].y))
continue;//点i在中间的情况;
sum++;
}
printf("Case %d: ",t1-t);
printf("%d\n",sum);
}
return 0;
}
FZU-2148-Moon Game,,几何计算~~的更多相关文章
- ACM: FZU 2148 Moon Game - 海伦公式
FZU 2148 Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- FZU 2148 Moon Game
Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- FZU 2148 moon game (计算几何判断凸包)
Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- FZU 2148 Moon Game --判凹包
题意:给一些点,问这些点能够构成多少个凸四边形 做法: 1.直接判凸包 2.逆向思维,判凹包,不是凹包就是凸包了 怎样的四边形才是凹四边形呢?凹四边形总有一点在三个顶点的内部,假如顶点为A,B,C,D ...
- FZOJ Problem 2148 Moon Game
Proble ...
- 1549: Navigition Problem (几何计算+模拟 细节较多)
1549: Navigition Problem Submit Page Summary Time Limit: 1 Sec Memory Limit: 256 Mb Su ...
- Jack Straws POJ - 1127 (几何计算)
Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5428 Accepted: 2461 Descr ...
- fzu Problem 2148 Moon Game(几何 凸四多边形 叉积)
题目:http://acm.fzu.edu.cn/problem.php?pid=2148 题意:给出n个点,判断可以组成多少个凸四边形. 思路: 因为n很小,所以直接暴力,判断是否为凸四边形的方法是 ...
- FZU Moon Game(几何)
Accept: 710 Submit: 2038 Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Fa ...
随机推荐
- 在eclipse中配置Tomcat并将项目部署到Tomcat上
参考:http://blog.csdn.net/yerenyuan_pku/article/details/51830104 首先在点击window窗口然后preferences 然后点击Add,选择 ...
- freertos之特点
主要特点:协程(co-routine):任务间的中断通信机制 支持可抢占式/协作式任务调度 .FreeRTOS-MPU 内核对象可以动态或静态分配 ...
- CGI和Servlet的比较
转载自:http://www.maxhis.info/java/cgi-vs-servlet/ 概括来说,CGI和Servlet可以完成相同的功能. CGI(Common Gateway Interf ...
- [转]浅谈.NET下的多线程和并行计算(二)线程基本知识
本文转自:http://www.cnblogs.com/lovecindywang/archive/2009/12/25/1632213.html 首先来看看如何创建线程: Console.Write ...
- 学习Python的day1
自己以前从来没有写博客的想法,但是学Python,里面的老师也说了,写博客可以加深自己的记忆,也能回顾内容.还能给别人参考.挺值的.2017-09-16 一. Python介绍 python的创始人为 ...
- Github-Client(ANDROID)开源之旅(三) ------ 巧用ViewPagerIndicator
接上篇博文:Github-Client(ANDROID)开源之旅(二) ------ 浅析ActionBarSherkLock 文中结合了网易新闻客户端讲解了开源库ActionBarSherklock ...
- sql语句分为三类(DML,DDL,DCL)-介绍
本文知识来源自:<Oracle专家高级编程> 分享作者:Vashon 时间:20150415 DDL is Data Definition Language statements. Som ...
- 2019年今日头条机试_JAVA后台岗_第一题
广度优先遍历: import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; class Nod ...
- droplang - 删除一种 PostgreSQL 过程语言
SYNOPSIS droplang [ connection-option...] langname [ dbname] droplang [ connection-option...] --list ...
- MySQL-02 数据表管理
学习要点 数据类型 数据字段属性 数据表的类型及存储位置 索引 数据表对象管理 数据类型 数据库中的数据类型分为字段类型和值类型,定义如下: 在设计数据表字段的时候,字段类型定义为三大类:数值类.字符 ...