FZU
来源:互联网 发布:帝国cms微信支付插件 编辑:程序博客网 时间:2024/06/04 19:01
Accept: 1040 Submit: 3205
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
题意:给若干个点,求这些点能组成凸四边形的个数
解决:枚举每种情况,用面积判断:如果是凹四边形,凹进去的那个点就在另外三个点组成的三角形里面,这个点与另外两个点组成的三个三角形面积和等于最外面那个三角形的面积。
细节:坐标求三角形面积公式:S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2)
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <set>#include <stack>#include <queue>#include <cmath>#include <map>#define fin freopen("in.txt", "r", stdin)#define line printf("-----------------\n")using namespace std;const int maxn = 1000000;int t, n, x, y;struct Point{ int x, y; Point(int xx = 0, int yy = 0){ this-> x = xx; this->y = yy; }}point[35];double area(int a, int b, int c){ //S=(1/2)*(x1y2+x2y3+x3y1-x1y3-x2y1-x3y2) int ar = point[a].x*point[b].y + point[b].x*point[c].y + point[c].x*point[a].y - point[a].x*point[c].y - point[b].x*point[a].y - point[c].x*point[b].y; return abs(ar) * 0.5;}bool ok(int a, int b, int c, int d){ double aa = area(a, b, c), bb = area(a, b, d), cc = area(a, c, d), dd = area(b, c, d); if(2*max(max(aa, bb), max(cc,dd)) == aa+bb+cc+dd) return false; return true;}int main(){ cin >> t; for(int cases = 1; cases <= t; cases++){ cin >> n; int num = 0; for(int i = 0; i < n; i++){ cin >> x >> y; point[i] = Point(x,y); } for(int i = 0; i < n-3; i++) for(int j = i+1; j < n-2; j++) for(int k = j+1; k < n-1; k++) for(int o = k+1; o < n; o++) if(ok(i,j,k,o)) num++; printf("Case %d: %d\n", cases, num); }}
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- FZU
- Text Volume (Codeforces
- 关于php红包分配算法
- 数据库设计的基本规范和原则
- 初识nodejs11
- require和include的区别
- FZU
- MySQL 调优/优化的 100 个建议
- 自然语言处理的十个发展趋势
- 动态规划、分治法与贪心算法的区别
- csdn第一个博客
- UEditor 取消所有的标签自动转义、替换
- HDOJ2084 数塔(DP)
- idea报Error Compilation failed
- 【日渐成熟的无线监控】大面积公共场所安防监控