数论 - Moon Game
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 -----------------------------------------------------我是分割线^_^-------------------------------------------------------- 题目意思就是说问你在给出的点中最多可以组成多少个凸四边形,此题没做出来,数学底子还是太差了,
直接暴力使用四重循环枚举判断即可,其中对于四边形的判断可以使用面积进行判断,具体图如下:
取四个点,如果有四边形为凹四边形,则必有一个点在其他三个点所形成的三角形内部,所以凸四边形
的问题也是类似的,然后就是求面积了,求面积可以使用向量的叉乘,因为向量a*向量b=|a|*|b|*sin<a,b>,
面积就出来了,于是便进行判断,注意转为浮点数,进行误差处理。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std; #define lson rt<<1
#define rson rt<<1|1
#define INF 0x3f3f3f3f
#define Int __int64
typedef pair<int,int> pii; const int MAXN = 55;
pii pos[MAXN]; double Area(pii p1, pii p2, pii p3) {
return fabs(1.0 * (p1.first - p2.first) * (p1.second - p3.second) - (p1.second - p2.second) * (p1.first - p3.first)) / 2.0;
}
bool Ok(pii p1, pii p2, pii p3, pii p4) {
if (fabs(Area(p1, p2, p3) - Area(p1, p2, p4) - Area(p1, p3, p4) - Area(p2, p3, p4)) < 1e-8) return false;
else return true;
}
int main() {
//freopen("input.txt", "r", stdin);
int cas;
while (cin>>cas) {
int sign = 1;
while (cas--) {
printf("Case %d: ", sign++);
int n;
cin>>n;
for (int i = 0; i < n; i++) {
cin>>pos[i].first>>pos[i].second;
}
int ans = 0;
for (int i1 = 0; i1 < n; i1++) {
for (int i2 = i1 + 1; i2 < n; i2++) {
for (int i3 = i2 + 1; i3 < n; i3++) {
for (int i4 = i3 + 1; i4 < n; i4++) {
if (Ok(pos[i1], pos[i2], pos[i3], pos[i4]) &&
Ok(pos[i1], pos[i2], pos[i4], pos[i3]) &&
Ok(pos[i1], pos[i4], pos[i3], pos[i2]) &&
Ok(pos[i4], pos[i2], pos[i3], pos[i1])) {
ans++;
}
}
}
}
}
printf("%d\n", ans);
}
}
return 0;
}
数论 - Moon Game的更多相关文章
- SP19997 MOON2 - Moon Safari (Hard) 【数论,多项式】
题目描述:求 \[ \sum_{i=1}^ni^kr^i \] 对某个质数取模.\(T\)组数据. 数据范围:\(n,r\le 10^{18},\sum k\le 2.56\times 10^6\) ...
- Moon.Orm 入门总指南
注意:下面的pdf文件强烈建议下载或在线查看 1)旗舰版帮助文档点击查看或下载 2)http://pan.baidu.com/s/1hq7krFu(新手手册下载)(强烈推荐) 3)性能及规范下载,网友 ...
- Moon.Orm 常见查询实例
一.Moon.Orm框架总述 (您还用hibernate?实体框架?) 1.框架名:Moon 意思是月亮,而非Mono.因为很喜欢明月,所以以此为名.它是一个.NET下的Orm框架. 2.发展历史:历 ...
- Moon.Orm 配置说明
一.在线技术文档: http://files.cnblogs.com/files/humble/d.pdf 二.使用的大致流程 1.首先下载代码生成器,可以一键生成项目Model层;(其中含有 ...
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- Moon.Orm 5.0(MQL版)的高性能,将发言权交给你!
Moon.Orm 5.0性能问题,我将它交给关心它性能的您,让你自己测试,决不让你失望的. Moon.Orm 5.0 (MQL版) 版本维护及下载 (跟踪发布) Moon.Orm 5.0系列文章 火晋 ...
- Moon.Orm 5.0 (MQL版) 欣赏另一种Orm的设计风格----大道至简
Moon.Orm 5.0(MQL版)使用指南(二) 一.使用sql及存储过程 1)使用List<Dictionary<))) 2)MQL 全面接触
- Moon.Orm性能报告
以下为有网友公司的评估测试及使用规范 大家可以下载word看看 http://pan.baidu.com/s/1hquvRuc 一.和ADO.NET进行的压力测试 说明:2000并发用户,此图为一网友 ...
- Moon.Orm与其他Orm的技术对比
有时候在思考大家为什么喜欢EF,为什么又出现这么多的Orm,为什么Nhiberate被人许多人接收又被许多人拒绝 最后发现结论:萝卜白菜各有所爱.适合自己的就是最好的. EF 微软团队支持(可谓强大的 ...
随机推荐
- yii2 登录用户和未登录用户使用不同的 layout
可以在配置文件中增加一个 “beforeRequest” 事件: 'on beforeRequest' => function () { Yii::$app->layout = Yii:: ...
- optparse
Python 有两个内建的模块用于处理命令行参数: 一个是 getopt,<Deep in python>一书中也有提到,只能简单处理 命令行参数: 另一个是 optparse,它功能强大 ...
- C语言 完美字符串
约翰认为字符串的完美度等于它里面所有字母的完美度之和.每个字母的完美度可以由你来分配,不同字母的完美度不同,分别对应一个1-26之间的整数. 约翰不在乎字母大小写.(也就是说字母F和f)的完美度相同. ...
- Unity 编译错误记录
1. 相关代码: NetworkView.RPC ("ReceiveMessage", RPCMode.All, message); 编译输出: Assets/cs/ClientC ...
- Python 之旅
Python2 之旅: https://funhacks.net/explore-python/ <Python Cookbook>第三版 PYTHON3 http://pyt ...
- java 使用正则表达式过滤HTML中标签
/** * 去掉文本中的html标签 * * @param inputString * @return */ public static String html2Text(String inputSt ...
- iOS CoreData 中 objectID 的不变性
关于 CoreData的 objectID 官方文档有这样的表述:新建的Object还没保存到持久化存储上,那么它的objectID是临时id,而保存之后,就是持久化的id,不会再变化了. 那么,我想 ...
- CI 扩展 Service
CI 扩展 Service 说明 CodeIgniter是一套典型的MVC框架,M负责数据,C负责交互,V负责视图,但是随着业务逻辑越来越复杂, 必然会涉及到一些列操作过程,例如用户下订单,就会存在校 ...
- Oracle 文件的导入与导出
说明:本机使用的是32位oracle,使用的方法是plsql导入与导出 1.导出数据步骤. 1)登陆上plsql后在工具里选择导出用户对象,选择上所有的表在选择保存的路径.点击导出就可以了. 2)上边 ...
- 只有IE64位能上网。