FZOJ2110 star(DFS)
来源:互联网 发布:手机淘宝分期付款流程 编辑:程序博客网 时间:2024/06/07 03:20
Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
For each test case:
The first line contains one integer n (1≤n≤100), the number of stars.
The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.
Output
For each test case, output an integer indicating the total number of different acute triangles.
Sample Input
130 010 05 1000
Sample Output
1
#include<stdio.h>#include<math.h>typedef struct nn{ double x1,y1;}node;void cmp(double *a,double *b,double *c){ double tem; if(*a<*b){tem=*a;*a=*b;*b=tem;} if(*a<*c){tem=*a;*a=*c;*c=tem;}}double cacreat(double x1,double y1,double x2,double y2){ double edglen; edglen=sqrt(pow(x1-x2,2.0)+pow(y1-y2,2.0)); return edglen;}int pandu(double a,double b,double c){ if(b*b+c*c-a*a>0) return 1; return 0;}double x[105],y[105];node s[3];int vist[105],n,sum;void dfs(int cout,int j){ double edg1,edg2,edg3; int i; s[cout].x1=x[j];s[cout].y1=y[j]; if(cout==2) { edg1=cacreat(s[0].x1,s[0].y1,s[1].x1,s[1].y1); edg2=cacreat(s[0].x1,s[0].y1,s[2].x1,s[2].y1); edg3=cacreat(s[1].x1,s[1].y1,s[2].x1,s[2].y1); cmp(&edg1,&edg2,&edg3); if(pandu(edg1,edg2,edg3)!=0) sum++; return ; } for(i=j+1;i<n;i++) if(vist[i]==0) { vist[i]=1; dfs(cout+1,i); vist[i]=0; }}int main(){ int i,t; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) { scanf("%lf%lf",&x[i],&y[i]); vist[i]=0; } sum=0; for(i=0;i<n;i++) { vist[i]=1; dfs(0,i); vist[i]=0; } printf("%d\n",sum); }}
- FZOJ2110 star(DFS)
- FZOJ2110: Star
- Star
- Star
- Star
- star
- star
- Star Trek
- A star
- star(CD1231)
- poj2352 Star
- A star
- 百度star
- A Star
- a star
- Star UML
- Star miscellaneous
- STAR法则
- 条件编译的一个作用
- 开始学习android开发
- 2013-08-11 Hello word|异常|代码书写规范|编译器虚拟机|注释|命名规则|数据类型|不常用的运算符|语法|
- ntpq –p命令查看连接的NTP服务器
- java异常处理
- FZOJ2110 star(DFS)
- Expecting a string, date or number here, Expression x is instead a freemarker.template.TemplateBoole
- 01.UTinventory多用户进销存系统概述
- java文件读取
- 映射组件属性之④:组件作为Map的索引
- 题目1443:Tr A
- JAVA & ANT 入门
- Java基础知识——Java语言基础
- 黑马程序员-C#中的方法与飞行棋游戏设计思路笔记