Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 375????Accepted Submission(s): 120
?
Input There are multiple test cases, and the number of test cases is no more than 12.?
Sample Input3 1 1 6 5 12 10 4 0 0 1 1 2 0 1 -1 0
?
Sample Output1 4?
??????? 阴险的水题,提交第16次才AC,最后一个小时里AC了,当时差点崩溃。
??????? 注意:数组大小要开大点,重复点算一个,组成不能三角形就不用判断了。
??????? 当场阴死了很多队伍,清华、交大都WA差不多10次,以后做题要读清题目意思!
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4082
代码:
?#include <iostream>
#include <stdio.h>
#include <math.h>
#include <memory.h>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
struct point
{
int x, y;
bool tar; //tar是标记重复的点
}p[25]; //点数很少,可以暴力
struct triangle
{
double ang[3];
}t[8005]; //20*20*20 = 8000,不要开小了
double dis(point a, point b) //求两点的距离
{
return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool judge(double a, double b, double c) //判断是否三点能否组成三角形
{
if(a + b <= c) return false;
if(a + c <= b) return false;
if(b + c <= a) return false;
return true;
}
bool ok(triangle a, triangle b) //判断两个三角形是否相似,两个角相等就行
{
if( fabs(a.ang[0] - b.ang[0]) < eps && fabs(a.ang[1] - b.ang[1]) < eps ) return true;
return false;
}
bool hash[205][205], flag[8005];
int main()
{
int i, j, k, n, sum, tx, ty, temp, MAX;
double a, b, c;
while(scanf("%d", &n), n)
{
for(i = 0; i < n; i++) p[i].tar = false;
memset(hash, false, sizeof(hash));
for(i = 0; i < n; i++)
{
scanf("%d %d", &p[i].x, &p[i].y);
tx = p[i].x + 100;
ty = p[i].y + 100;
if(hash[tx][ty] == false) //hash判断是否有重复点
{
hash[tx][ty] = true;
p[i].tar = true;
}
}
sum = 0;
for(i = 0; i < n; i++)
{
if(!p[i].tar) continue;
for(j = i + 1; j < n; j++)
{
if(!p[j].tar) continue;
for(k = j + 1; k < n; k++)
{
if(!p[k].tar) continue;
a = dis(p[i], p[j]);
b = dis(p[j], p[k]);
c = dis(p[i], p[k]);
if(judge(a, b, c)) //3边能组成三角形
{
//余弦定理求三角形的三个角
t[sum].ang[0] = acos((b*b+c*c-a*a)/(2*b*c));
t[sum].ang[1] = acos((a*a+c*c-b*b)/(2*a*c));
t[sum].ang[2] = acos((b*b+a*a-c*c)/(2*b*a));
sort(t[sum].ang, t[sum].ang + 3);
sum++;
}
}
}
}
memset(flag, false, sizeof(flag));
MAX = 0;
for(i = 0; i < sum; i++) //开始求最大值
{
if(flag[i]) continue;
flag[i] = true;
temp = 0;
for(j = i; j < sum; j++)
{
if(ok(t[i], t[j]))
{
flag[j] = true;
temp++;
if(temp > MAX) MAX = temp;
}
}
}
printf("%d\n", MAX);
}
return 0;
}
?
?
?