• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

FOJ Problem 2148 Moon Game

Problem 2148 Moon Game

Accept: 19    Submit: 53 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

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
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 100025
14 #define pi acos(-1.0)
15 int n, m;
16 int t;
17 struct point{
18     ll x, y;
19     point(){}
20     point(ll x, ll y) :x(x), y(y){}
21 }a[maxn];
22 ll xmult(point b, point c, point a){return (b.x - a.x)*(c.y - a.y) - (c.x - a.x)*(b.y - a.y);}
23 ll opposite_side(point p1, point p2, point l1, point l2){ return xmult(l1, p1, l2)*xmult(l1, p2, l2)<0; }
24 ll intersect_ex(point u1, point u2, point v1, point v2){ return opposite_side(u1, u2, v1, v2) && opposite_side(v1, v2, u1, u2); }
25 int main(){
26     int cas = 1;
27     scanf("%d", &t);
28     while (t--){
29         scanf("%d", &n);
30         int k = 0;
31         for (int i = 0; i < n; i++)scanf("%I64d%I64d", &a[i].x, &a[i].y);
32         for (int i = 0; i < n; i++)
33         for (int j = i+1; j < n; j++)
34         for (int x = j+1; x < n; x++)
35         for (int y = x+1; y < n; y++){
36                 int flag = 0;
37                 if (intersect_ex(a[i],a[j],a[x],a[y]))flag++;
38                 if (intersect_ex(a[i],a[x],a[j],a[y]))flag++;
39                 if (intersect_ex(a[i],a[y],a[j],a[x]))flag++;
40                 if (flag)k++;
41             }
42         printf("Case %d: ", cas++);
43         printf("%d\n", k);
44     }
45 }
View Code

 

 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 1025
14 #define pi acos(-1.0)
15 ll n, m, y,now, all, v,ans;
16 int t;
17 struct point{
18     ll x, y;
19     point(ll x=0, ll y=0) :x(x), y(y){}
20     ll operator * (const point& r)const{ return x*r.y - y*r.x; }
21 }a[101];
22 ll area(ll x0, ll y0, ll x1, ll y1, ll x2, ll y2){ return x0*y1 + x2*y0 + x1*y2 - x2*y1 - x0*y2 - x1*y0; }
23 int main(){
24     int cas = 1;
25     scanf("%d", &t);
26     while (t--){
27         scanf("%d", &n);
28         for (int i = 0; i < n; i++)scanf("%I64d%I64d", &a[i].x, &a[i].y);
29         int k = 0;
30         for (int ii = 0; ii < n; ii++){
31             for (int jj = ii+1; jj < n; jj++){
32                 for (int xx = ii+1; xx < n; xx++){
33                     for (int yy = ii+1; yy < n; yy++){
34                         int flag = 0;
35                         if (xx != ii&&xx != yy&&xx != jj&&yy != jj&&yy != ii&&ii != jj){
36                             int c = area(a[ii].x, a[ii].y, a[jj].x, a[jj].y, a[xx].x, a[xx].y);
37                             if (area(a[ii].x,a[ii].y,a[jj].x,a[jj].y,a[yy].x,a[yy].y)*c>0)flag++;
38                             if (area(a[ii].x,a[ii].y,a[xx].x,a[xx].y,a[yy].x,a[yy].y)*c>0)flag++;
39                             if (area(a[jj].x,a[jj].y,a[xx].x,a[xx].y,a[yy].x,a[yy].y)*c>0)flag++;
40                             if (flag == 3)k++;
41                         }
42                     }
43                 }
44             }
45         }
46         printf("Case %d: ", cas++);
47         printf("%d\n", k/2);
48     }
49     return 0;
50 }
View Code
posted @ 2013-12-23 06:52  HaibaraAi  阅读(163)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3