Accept: 710    Submit: 2038

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

240 0100 00 100100 10040 0100 00 10010 10

 Sample Output

Case 1: 1Case 2: 0

我直接用了凸包算法,大材小用了

#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm> using namespace std;
struct Node
{
int x;
int y;
}a[5],b[35];
int s[10];
int top;
int cross(Node a,Node b,Node c)
{
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
int dis(Node a,Node b)
{
return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int cmp(Node p1,Node p2)
{
int temp=cross(a[0],p1,p2);
if(temp>0) return true;
else if(temp==0&&dis(a[0],p1)<dis(a[0],p2)) return true;
else return false;
}
int cmp2(Node a,Node b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
int graham(int n)
{
if(n==1){return 0;}
if(n==2){return 1;}
if(n>2)
{
top=1;s[0]=0;s[1]=1;
for(int i=2;i<n;i++)
{
while(top>0&&cross(a[s[top-1]],a[s[top]],a[i])<=0)
top--;
s[++top]=i;
} return top; } }
int n;
int main()
{
int t;
scanf("%d",&t);
int cas=0;
int ans=0;
while(t--)
{
scanf("%d",&n);
ans=0;
for(int i=1;i<=n;i++)
scanf("%d%d",&b[i].x,&b[i].y);
for(int i=1;i<=n;i++)
{ for(int j=i+1;j<=n;j++)
{ for(int k=j+1;k<=n;k++)
{ for(int p=k+1;p<=n;p++)
{
a[0]=b[i];a[1]=b[j];a[2]=b[k];a[3]=b[p];
sort(a,a+4,cmp2); sort(a+1,a+4,cmp); //cout<<i<<" "<<j<<" "<<k<<" "<<p<<endl;
if(graham(4)==3)
{
// cout<<i<<" "<<j<<" "<<k<<" "<<p<<endl;
ans++;
}
}
}
}
}
printf("Case %d: %d\n",++cas,ans);
}
return 0;
}

最新文章

  1. Symbols
  2. java的值传递和引用传递
  3. knockoutjs+jquery.gridgroup 实现table数据加载和行合并
  4. 寻找两个已序数组中的第k大元素
  5. echarts中视觉映射器(visualMap)与时间轴(timeline)混用的实现方法
  6. java设计模式-----单例设计模式
  7. logstash 修改配置不重启的方法
  8. angular2升级到angular4历程
  9. javascript刷新父页面的各种方法汇总
  10. 网络编程 -- RPC实现原理 -- RPC -- 迭代版本V1 -- 本地方法调用
  11. hdu 1038 Biker&amp;#39;s Trip Odometer(水题)
  12. Linux中Readlink命令
  13. hive12启动报错org.apache.thrift.server.TThreadPoolServer.&lt;init&gt;(Lorg/apache/thrift/server/TThreadPoolServer$Args;)
  14. spring mvc 数据回显
  15. C#高级编程 (第六版) 学习 第一章:.Net体系结构
  16. Linux 学习第四天
  17. sparksql读写hbase
  18. crontab-用于设置周期性被执行的指令
  19. HDU 4436 str2int (后缀自动机)
  20. 做dg时遇到的log_archive_dest、log_archive_dest_1、db_recovery_file_dest之间互相影响

热门文章

  1. ctags高级用法
  2. Unity3D 应用程序退出调用OnDestroy测试
  3. Java Mail(二):JavaMail介绍及发送一封简单邮件
  4. 一款纯css3实现的tab选项卡
  5. 超赞的lua开发工具zerobrane
  6. openvpn 移植之buildroot添加相关选项
  7. [shell]system和execlp简单示例
  8. js 调试问题
  9. ThinkPHP 的URL重写时遇到No input file specified的解决方法
  10. IoC最大的好处是什么