FZU 2148 Moon Game
2016-04-19 21:52
369 查看
题意:给定n个点,问选4个点能组成凸四边形的个数
思路:凸包模板上
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
240 0100 00 100100 10040 0100 00 10010 10
Sample Output
Case 1: 1Case 2: 0
思路:凸包模板上
#include <cstdio> #include <queue> #include <cstring> #include <iostream> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <set> #include <ctime> #include <cmath> #include <cctype> #define N 100000 #define LL long long #define U unsigned using namespace std; struct Point { int x,y; Point(int a,int b) { x=a;y=b; } Point() { } bool operator<(const Point &a)const { return x<a.x||(x==a.x&&y<a.y); } Point operator -(const Point &a) const { return Point(x-a.x,y-a.y); } }; int Cross(Point a,Point b) { return a.x*b.y-a.y*b.x; } int ConvexHull(Point*p,int n,Point*ch) { sort(p,p+n); int m=0; for(int i=0;i<n;i++) { while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; ch[m++]=p[i]; } int k=m; for(int i=n-2;i>=0;i--) { while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--; ch[m++]=p[i]; } if(n>1) m--; return m; } Point a[40],b[10],c[10]; int cas=1,T; int n; int main() { //freopen("1.in","w",stdout); //freopen("1.in","r",stdin); //freopen("1.out","w",stdout); scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].x,&a[i].y); int ans=0; for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { for(int k=j+1;k<n;k++) { for(int l=k+1;l<n;l++) { b[0]=a[i];b[1]=a[j];b[2]=a[k];b[3]=a[l]; if(ConvexHull(b,4,c)==4) ans++; } } } } printf("Case %d: %d\n",cas++,ans); } //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC); return 0; }
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
240 0100 00 100100 10040 0100 00 10010 10
Sample Output
Case 1: 1Case 2: 0
相关文章推荐
- 第七周项目29-数组求员工工资
- 原生js之道——原生js编写类选择器
- 站立会议(1)
- [原创]Windows下Google V8 javascript引擎编译
- linux的串口驱动分析
- USACO 之 Section 2.3 (已解决)
- 有关字符串编程
- 33.JAVA编程思想——JAVA IO File类
- Iwfu-保存Fragment切换时的UI状态/保存销毁Activity后再次进入的视图状态
- 32.JAVA编程思想——JAVA IO添加属性和接口
- leetcode——89——Gray Code
- Java 序列化Serializable详解
- strstr代码
- 菜鸟入门_Python_机器学习(1)_线性可分的双月实验
- A strange lift
- 站立会议第一天
- bzoj4537: [Hnoi2016]最小公倍数
- 这次栽倒在sscanf函数上------ 看看错误的语句:int nRet = sscanf("xxx=yyy", "%s=%s", szKey, szValue);
- 31.JAVA编程思想——JAVA IO系统输入和输出
- curl 命令常用