标签:hdu
http://acm.hdu.edu.cn/showproblem.php?pid=4082

3 1 1 6 5 12 10 4 0 0 1 1 2 0 1 -1 0
1 4
题意:给最多18个点,问最多有多少个相似的三角形。
分析:18个点。。就枚举所有可以组成的三角形判断相似就好。。注意要判断重点和平行的情况。。
/**
* @author neko01
*/
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-8;
const double pi=acos(-1.0);
const int INF=0x7fffffff;
const LL inf=(((LL)1)<<61)+5;
bool vis[250][250];
struct point{
double x,y;
point(double x=0,double y=0):x(x),y(y) {}
}a[22];
struct triangle{
double x,y,z;
}b[18*18*18];
bool gao(int i,int j)
{
if(fabs(b[i].x*b[j].y-b[i].y*b[j].x)<eps&&fabs(b[i].z*b[j].y-b[i].y*b[j].z)<eps)
return true;
return false;
}
bool check(int i,int j,int k)
{
point p1=point(a[i].x-a[j].x,a[i].y-a[j].y);
point p2=point(a[k].x-a[j].x,a[k].y-a[j].y);
return fabs(p1.x*p2.y-p1.y*p2.x)<eps;
}
double dis(int i,int j)
{
return sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
}
int main()
{
int n,m;
while(~scanf("%d",&m)&&m)
{
clr(vis);
n=0;
for(int i=0;i<m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(!vis[x+100][y+100])
{
vis[x+100][y+100]=true;
a[n].x=x;
a[n++].y=y;
}
}
m=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++)
{
if(check(i,j,k)) continue;
double d1=dis(i,j);
double d2=dis(i,k);
double d3=dis(j,k);
double t[3];
t[0]=d1,t[1]=d2,t[2]=d3;
sort(t,t+3);
if(t[0]+t[1]<=t[2]) continue;
b[m].x=t[0],b[m].y=t[1];
b[m++].z=t[2];
}
}
}
int ans=0;
for(int i=0;i<m;i++)
{
int sum=1;
for(int j=0;j<m;j++)
if(i!=j&&gao(i,j))
sum++;
if(sum>ans) ans=sum;
}
printf("%d\n",ans);
}
return 0;
}标签:hdu
原文地址:http://blog.csdn.net/neko01/article/details/40866611