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 ...
随机推荐
- solrJ的使用--覆盖创建索引,查询,删除索引【转自http://blog.sina.com.cn/s/blog_64ac3ab10100t3mq.html】
package com.xzhe.common.search; import java.util.ArrayList; import java.util.Collection; import java ...
- 浅析 Spark Shuffle 内存使用
在使用 Spark 进行计算时,我们经常会碰到作业 (Job) Out Of Memory(OOM) 的情况,而且很大一部分情况是发生在 Shuffle 阶段.那么在 Spark Shuffle 中具 ...
- JS执行保存在数据库中的JS代码
function createScript(script) { var myScript = document.createElement("script"); myScript. ...
- AJPFX浅谈Java 性能优化之字符串过滤实战
★一个简单的需求 首先描述一下需求:给定一个 String 对象,过滤掉除了数字(字符'0'到'9')以外的其它字符.要求时间开销尽可能小.过滤函数的原型如下: String filter(Strin ...
- asp.net 中文部分显示问号
很神奇的事情,今天部署了一个网站,页面从数据读取新闻后,有些新闻标题全部显示问题号,有几个新闻能正确显示汉字,然后查看新闻页面又能正常显示汉字. 解决办法: 在异常的页面上加上 < %@ COD ...
- ios 根据颜色生成图片,十六进制颜色。
//颜色生成图片方法 - (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size { CGRect rect = CGRectMake ...
- docker上配置nginx负载均衡
采用ubuntu系统,docker安装自行百度 1.安装tomcat docker run -d -p : tomcat docker run -d -p : tomcat 安装两个实例,端口分别为8 ...
- Oracle Recycle Bin
开启回收站RECYCLEBIN=ON,默认开启 ALTER SYSTEM SET RECYCLEBIN=OFF SCOPE=SPFILE; 一.从回收站还原表 还原删除的表和从属对象. 如果多个回收站 ...
- 富通天下(W 笔试)
纸质算法题目 1.给你一个字符串,找出其中第一个只出现过一次的字符及其位置 正解:一层for循环,循环按序取出字符串中的单个字符,循环体内部使用String类的indexOf(),从当前字符下标往后搜 ...
- mysql利用binlog恢复数据
需求:需要给开发提供一个2018年9月30号的数据,按照我们公司正常备份策略来说,直接找到对应时间的备份数据,解压导入即可,恰好这个时间节点的数据没有,只备份到2018年9月25号的,糟糕了吧 咋办呢 ...