poj 1917
来源:互联网 发布:身高算法 编辑:程序博客网 时间:2024/05/16 05:43
这题一道典型的hash题,其实hash写的好的应该挺快的,不过我的4600+ms过个,比较惊险,不是爆内存就是tle,题意是给你n个点问这n个点能组成多少个平行四边形,平行四边形的性质就是对角线互相平分,那么只要找出两对角线的中点相同即可,用hash统计数目,我一边输入一边累加都快tle了,不知道用上组合数学回怎么样,还有一种做法是将其中点排序,然后统计,应该挺快的我觉的,没去实验。
#include<cstdio>#include<cstring>#include<cmath>using namespace std;const int N=1000003;int pos,head[N+2]={0};long long flag=0;struct nd{int x,y,z;int n;}hash[N+2];void into(int x,int y){int tem;if(x+y<0){tem=-(x+y)&N;}elsetem=(x+y)&N;int k=head[tem];while(k&&(hash[k].x!=x||hash[k].y!=y)){k=hash[k].n;}if(k==0){hash[pos].x=x,hash[pos].y=y;hash[pos].z=1;hash[pos].n=head[tem];head[tem]=pos++;}else{flag+=hash[k].z;hash[k].z++;}}int main(){int c,i,j,k,m;int x[1005],y[1005];scanf("%d",&c);while(c--){memset(hash,0,sizeof(hash));memset(head,0,sizeof(head));flag=0;pos=1;scanf("%d",&m);for(i=0;i<m;i++){scanf("%d%d",&x[i],&y[i]);for(j=i-1;j>=0;j--){into(x[i]+x[j],y[i]+y[j]);}}printf("%lld\n",flag);}return 0;}
- poj 1917
- poj 1917
- poj 1917 Automatic Poetry
- POJ 1917 Automatic Poetry
- POJ 1917 字符串替换
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- 精简代码的技巧整理
- CWnd::OnCtlColor
- 自动生成Windows API的C#函数声明
- 使用PowerDesigner生成数据库测试数据
- InvalidateRect( LPCRECT lpRect) 以及 RedrawWindow( LPCRECT lpRect) 中的重绘部分区域 是什么含义
- poj 1917
- DML、DDL、DCL区别
- C++ code style
- 3G之Android学习第二章节<<开发第一个HelloWorld应用程序>>
- 安装Android的Eclipse插件ADT遇到错误“requires 'org.eclipse.gef 0.0.0' but it could not be found”
- 中国父母伤害孩子的“七种武器”
- IncMinute:将一个TDateTime变量加减某个数量的分钟数
- Direct3D 简单纹理cube
- poj 2774