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 ...
随机推荐
- Java 修改编码格式的几种方式
1.工作空间 workspase Window→Preferences→General→Workspace→Text file encoding→other→UTF-8 2.项目编码格式 右键项目名→ ...
- 147 Insertion Sort List 链表插入排序
用插入排序对链表进行排序. 详见:https://leetcode.com/problems/insertion-sort-list/description/ Java实现: 链表的插入排序实现原理很 ...
- html5新增的主题结构元素
article元素 article元素代表文档.页面或应用程序中独立的.完整的.可以独自被外部引用的内容. 它可以是一篇博客或者报刊中的文章,一篇论坛帖子.一段用户评论或独立的插件. 或其他任何独立的 ...
- CF750D New Year and Fireworks
题意: 放烟花. 一个烟花从某一起点开始,沿着当前方向移动指定数量的格子之后爆炸分成两部分,分别沿着当前方向的左上和右上方向移动.而每一部分再沿着当前方向移动指定数量的格子之后爆炸分成两部分.如此递归 ...
- expect下命令不能解析通配符*的问题
曾遇到这样一段代码:(Bash脚本) 1 2 3 4 5 6 7 8 9 10 11 12 #!/usr/bin/expect -f set HOST "192.168.102.1" ...
- BeanUtils.copyProperties(productInfo, productInfoVO);
一:spring的工具类方法:BeanUtils.copyProperties(orderMasterDTO, orderMasterDO); 作用:将orderMasterDTO对象中的属性值,赋值 ...
- QTP自动FlightReservation小程序,数据库被玩坏了~~~
1.尝试使用CheckPointOnDataBase功能. 2.选中自带的数据库 3.执行Delete * from Orders; 如下图: 4.再次使用FlightReservation的时候,不 ...
- jmeter+ant+jenkins
前提:需要先配置下面两个环境,严格按照本人的配置去配,要不然后面你会看不懂 (1)ant+jmeter集成:http://blog.csdn.net/qq_23101033/article/detai ...
- x86和i386
x86: 1 9 7 8年6月,I n t e l公司推出了8 0 8 6,一个1 6位微处理器,它可访问的存储空间达到1 M B. Intel x86家族继续发展,1 9 8 5年出现了3 2位的3 ...
- UGUI世界坐标转换为UI本地坐标
以下是实现hud跟随3D物体的脚本,只是测试用,不是开发中的代码,脚本挂在任意游戏物体上 demo下载 using UnityEngine; public class SceneFollowUI : ...