Problem 2110 StarAccept: 477 Submit: 1422
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem 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
130 010 05 1000
Sample Output
1
Source
“高教社杯”第三届福建省大学生程序设计竞赛#include <iostream>
#include <algorithm>
using namespace std;
struct point{
double x,y;
}p[105];
double dis[105][105];
int main(){
int T;
cin>>T;
while(T--){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>p[i].x>>p[i].y;
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
dis[i][j]=(p[j].x-p[i].x)*(p[j].x-p[i].x)+(p[j].y-p[i].y)*(p[j].y-p[i].y);
}
}
double b[3];
int count=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++){
b[0]=dis[i][j];
b[1]=dis[j][k];
b[2]=dis[i][k];
sort(b,b+3);
if((b[0]+b[1])>b[2])
count++;
}
}
}
cout<<count<<endl;
}
return 0;
}
本文介绍了一道算法题目,任务是在平面上找到由星星组成的锐角三角形的数量。输入包含多个测试用例,每个用例提供星星的位置坐标,输出为不同锐角三角形的总数。
647

被折叠的 条评论
为什么被折叠?



