HDU 4082 Hou Yi's secret(暴力)

直接6重循环就行了吧。。。判三角形相似直接从小到大枚举两向量夹角是否相等就行了。注意去重点跟三点共线就行了。。。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<bitset>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define eps 1e-10
using namespace std; struct Point
{
double x, y;
Point (double x=0, double y=0):x(x), y(y) {}
};
typedef Point Vector; Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } bool operator < (const Point& a, const Point& b)
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
} int dcmp(double x)
{
if(fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
} bool operator == (const Point& a, const Point& b)
{
return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
} double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angel(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
double Area2(Vector A, Vector B, Vector C) { return Cross(B-A, C-A); } //向量逆时针旋转
Vector Rotate(Vector A, double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
} //求直线p+tv和q+tw的交点 Cross(v, w) == 0无交点
Point GetLineIntersection(Point p, Vector v, Point q, Vector w)
{
Vector u = p-q;
double t = Cross(w, u) / Cross(v, w);
return p + v*t;
} //点p到直线ab的距离
double DistanceToLine(Point p, Point a, Point b)
{
Vector v1 = b - a, v2 = p - a;
return fabs(Cross(v1, v2)) / Length(v1);//如果不带fabs 得到的是有向距离
} //点p到线段ab的距离
double DistanceToSegment(Point p, Point a, Point b)
{
if(a == b) return Length(p-a);
Vector v1 = b-a, v2 = p-a, v3 = p-b;
if(dcmp(Dot(v1, v2) < 0)) return Length(v2);
else if(dcmp(Dot(v1, v3)) > 0) return Length(v3);
else return fabs(Cross(v1, v2)) / Length(v1);
} //点p在直线ab上的投影
Point GetLineProjection(Point p, Point a, Point b)
{
Vector v = b-a;
return a + v*(Dot(v, p-a) / Dot(v, v));
} //点段相交判定
bool SegmentItersection(Point a1, Point a2, Point b1, Point b2)
{
double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1),
c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1);
return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;
} //点在线段上
bool OnSegment(Point p, Point a1, Point a2)
{
return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;
} //多变形面积
double PolygonArea(Point* p, int n)
{
double ret = 0;
FF(i, 1, n) ret += Cross(p[i]-p[0], p[i+1]-p[0]);
return ret/2;
} Point read_point()
{
Point a;
scanf("%lf%lf", &a.x, &a.y);
return a;
} bool cmp(double a[], double b[])
{
if(dcmp(a[0]-b[0])!=0) return 0;
if(dcmp(a[1]-b[1])!=0) return 0;
if(dcmp(a[2]-b[2])!=0) return 0;
return 1;
} const int maxn = 100;
Point p[maxn];
int n, cnt;
double aa[10], bb[10]; bool can(int i, int j, int k)
{
return dcmp(Cross(p[j]-p[i], p[k]-p[i])) != 0;
} int main()
{
Vector a = Vector(0, 1), b = Vector(0, 100);
while(scanf("%d", &cnt), cnt)
{
REP(i, cnt) p[i] = read_point();
sort(p, p+cnt);
n = unique(p, p+cnt) - p; int ans = 0; REP(i, n) FF(j, i+1, n) FF(k, j+1, n)
{
if(!can(i, j, k)) continue;
int tmp = 0;
aa[0] = Angel(p[j]-p[i], p[k]-p[i]);
aa[1] = Angel(p[i]-p[j], p[k]-p[j]);
aa[2] = Angel(p[i]-p[k], p[j]-p[k]);
sort(aa, aa+3);
REP(ii, n) FF(jj, ii+1, n) FF(kk, jj+1, n)
{
if(!can(i, j, k)) continue;
bb[0] = Angel(p[jj]-p[ii], p[kk]-p[ii]);
bb[1] = Angel(p[ii]-p[jj], p[kk]-p[jj]);
bb[2] = Angel(p[ii]-p[kk], p[jj]-p[kk]);
sort(bb, bb+3);
if(cmp(aa, bb)) tmp++;
}
ans = max(ans, tmp);
}
printf("%d\n", ans);
}
return 0;
}
上一篇:细说java中的类


下一篇:Java开发知识之Java中的集合上List接口以及子类讲解.