light oj 1058
Posted very_czy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了light oj 1058相关的知识,希望对你有一定的参考价值。
哈希老坑了。。。
问你用已知点能找出多少个平行四边形。
原来想着哈希,哪知道数据很小,哈希的话老是不对,一看大牛们都是直接排序。。。瞎了。。。慎用哈希。。。慎用浮点。。。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=1010;
const int INF = (1 << 30) - 1;
const double eps = 1e-10;
double add(double a,double b) //有误差的浮点加法
{
if(abs(a + b) < eps * (abs(a) + abs(b))) return 0;
return a + b;
}
struct Point
{
int x,y;
Point(double tx = 0,double ty = 0) : x(tx),y(ty) {}
Point operator + (Point p)
{
return Point(add(x,p.x),add(y,p.y));
}
Point operator - (Point p)
{
return Point(add(x,-p.x),add(y,-p.y));
}
Point operator * (double d)
{
return Point(x * d,y * d);
}
Point operator / (double d)
{
return Point(x / d,y / d);
}
void Read()
{
scanf("%d%d",&x,&y);
}
};
Point date[MAXN*1000],lis[MAXN*1000];
int Sign(double x)
{
return (x > eps) - (x < -eps);
}
double Cross(Point a,Point b,Point c)
{
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
double Dis(Point a,Point b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool cmp(Point a,Point b)
{
if (a.x==b.x) return a.y<b.y;
else return a.x<b.x;
}
int main()
{
int T,cas=1;
scanf ("%d",&T);
while (T--)
{
int n;
scanf ("%d",&n);
for (int i=0; i<n; i++)
date[i].Read();
int top=0;
for (int i=0; i<n; i++)
{
for (int j=i+1; j<n; j++)
{
lis[top].x=date[i].x+date[j].x;
lis[top].y=date[i].y+date[j].y;
top++;
}
}
sort(lis,lis+top,cmp);
int ans=0,temp=1;
for (int i=1; i<top; i++)
{
if (lis[i].x==lis[i-1].x&&lis[i].y==lis[i-1].y)
{
temp++;
}
else
{
temp=1;
}
ans+=temp-1;
}
printf ("Case %d: %d\n",cas++,ans);
}
return 0;
}
以上是关于light oj 1058的主要内容,如果未能解决你的问题,请参考以下文章
Light oj 1422 - Halloween Costumes
(状压) Brush (IV) (Light OJ 1018)