FZU-2110-Star
2016-03-25 12:08
351 查看
I - Star
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
FZU 2110
Description
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
1
3
0 0
10 0
5 1000
Sample Output
1
题意,第一行给出T,然后T组数据,每组数据第一行给出n,接下来n行给出n组坐标,输出这n个点能构成的锐角三角形个数。
思路:通过坐标得到三边大小,然后判断锐角三角形任意两边平方和大于第三边平方。
三层for循环暴力枚举即可
代码
注意数据精度
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
FZU 2110
Description
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
1
3
0 0
10 0
5 1000
Sample Output
1
题意,第一行给出T,然后T组数据,每组数据第一行给出n,接下来n行给出n组坐标,输出这n个点能构成的锐角三角形个数。
思路:通过坐标得到三边大小,然后判断锐角三角形任意两边平方和大于第三边平方。
三层for循环暴力枚举即可
代码
#include<iostream> #include<algorithm> #include<math.h> #include<string> #include<string.h> #include<stdio.h> #include<queue> using namespace std; int main() { int T; scanf("%d",&T); while(T--) { int n;//n组数据 scanf("%d",&n); double num[2][105];//存储坐标 for(int i=0; i<n; i++) scanf("%lf%lf",&num[0][i],&num[1][i]);//存储x,y坐标 double a,b,c;//三角形三条边 int sum=0;//记录总数 for(int i=0; i<n-2; i++) for(int j=i+1; j<n-1; j++) for(int k=j+1; k<n; k++) { a=sqrt((num[0][i]-num[0][j])*(num[0][i]-num[0][j])+(num[1][i]-num[1][j])*(num[1][i]-num[1][j])); b=sqrt((num[0][i]-num[0][k])*(num[0][i]-num[0][k])+(num[1][i]-num[1][k])*(num[1][i]-num[1][k])); c=sqrt((num[0][k]-num[0][j])*(num[0][k]-num[0][j])+(num[1][k]-num[1][j])*(num[1][k]-num[1][j])); if(a*a+b*b>c*c&&a*a+c*c>b*b&&b*b+c*c>a*a) sum++; } printf("%d\n",sum); } return 0; }
注意数据精度
相关文章推荐
- C#编写的艺术字类实例代码
- 【算法】插入排序
- FEC之我见一
- 给tableview cell添加阴影:
- nodejs笔记三--url处理、Query String;
- 305. Number of Islands II
- 如何撰写创业计划书
- html打开本地android app
- 【慕课笔记】1-2 初涉MYSQL—MYSQL的安装与配置
- 在批处理模式下使用mysql
- hibernate,mybatis,beetlsql 全面比较
- [Java并发包学习七]解密ThreadLocal
- 1003,字母编码最短
- Memcached——非关系型数据库分布式处理
- Oracle-trunc函数用法
- hdu4763kmp
- OC从入门到精通-2.三大特性(封装,继承,多态)
- Unrecognized option: -XX:MaxPernSixe -386m
- 深度解读海量数据存储和访问下的水平分库&去IOE
- 事件委托(js实现)