| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:625MSIn Reply To:625MS Posted by:donkeyinacm at 2010-03-05 11:29:41 > #include <iostream>
> #include <cmath>
> using namespace std;
> #define MAXN 1005
> #define INF 20005
> #define MAXH 999999
> #define esp 1e-10
> int n,x2,y2,x4,y4,res;
> struct point
> {
> int x,y;
> point *next;
> };
> point P[MAXN];
> point *hash[MAXH];
>
> int cmp(const void *a,const void *b)
> {
> if(static_cast<const point*>(a)->x==static_cast<const point*>(b)->x)
> return static_cast<const point*>(a)->y-static_cast<const point*>(b)->y;
> return static_cast<const point*>(a)->x-static_cast<const point*>(b)->x;
> }
>
>
> bool exist(int x,int y)
> {
> bool b[2]={false};
> int hv=(x*x+y*y)%MAXH;
> point *p=hash[hv];
> while(p!=NULL)
> if(p->x==x&&p->y==y)
> return true;
> else
> p=p->next;
> return false;
> }
>
>
> int main()
> {
> //freopen("c:/aaa.txt","r",stdin);
> int i,j;
> while(scanf("%d",&n)&&n)
> {
> for(i=0;i<MAXH;i++)
> hash[i]=NULL;
> res=0;
> for(i=0;i<n;i++)
> {
> scanf("%d%d",&P[i].x,&P[i].y);
> int hv=(P[i].x*P[i].x+P[i].y*P[i].y)%MAXH;
> point *p=new point();
> p->next=hash[hv];
> p->x=P[i].x;
> p->y=P[i].y;
> hash[hv]=p;
> }
> qsort(P,n,sizeof(P[0]),cmp);
> for(i=0;i<n;i++)
> {
> for(j=i+1;j<n;j++)
> if(P[j].y>P[i].y)
> {
> if(P[j].x==P[i].x&&P[j].y-P[i].y==1 || P[j].y==P[i].y&&P[j].x-P[i].x==1)
> continue;
> int x1=P[i].x;
> int y1=P[i].y;
> int x3=P[j].x;
> int y3=P[j].y;
> x2=(x1+x3+y3-y1)/2;
> y2=(y1+y3+x1-x3)/2;
> x4=(x1+x3-y3+y1)/2;
> y4=(y1+y3-x1+x3)/2;
>
> double len1=((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))*2;
> double len2=((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
> if(fabs(len1-len2)>esp)
> continue;
> if(exist(x2,y2)&&exist(x4,y4))
> {
> // printf("1 x1:%d y1:%d x2:%d y2:%d x3:%d y3:%d x4:%d y4:%d\n",x1,y1,x2,y2,x3,y3,x4,y4);
> res++;
> }
> }
> }
> printf("%d\n",res);
> }
> return 0;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator