数平行四边形,地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=1971
#include <iostream>
#include <algorithm>
#include <memory>
using namespace std;
struct point
  {
int x,y;
};
struct seg
  {
int a,b;
point v;
};
bool operator <(seg a,seg b)
  {
return (a.v.x<b.v.x)||(a.v.x==b.v.x&&a.v.y<b.v.y);
}
seg tmp, vs[500500];
point p[1000];
bool commen(int i,int j);
 int main() {
int i,j,k,n, t;
cin>>t;
for(k = 0 ; k < t ;k ++)
 {
memset(vs,0,sizeof(vs));
cin>>n;
for(i = 0 ;i < n ; i ++) cin>>p[i].x>>p[i].y;
int num=0;
for(i = 0 ;i < n-1 ; i ++)
for(j = i +1 ;j < n ;j ++)
 {
tmp.a = i; tmp.b = j;
tmp.v.x = p[i].x-p[j].x; tmp.v.y = p[i].y-p[j].y;
if(tmp.v.x<=0&&tmp.v.y<=0)
 {
tmp.v.x=-tmp.v.x; tmp.v.y=-tmp.v.y;
}
if(tmp.v.x<=0&&tmp.v.y>=0)
 {
tmp.v.x=-tmp.v.x; tmp.v.y=-tmp.v.y;
}
vs[num++]=tmp;
}
sort(vs,vs+num);
int sum = 0;
int beg = 0;
while(beg < num)
 {
for(i = beg; vs[i].v.x==vs[beg].v.x&&vs[i].v.y==vs[beg].v.y;i++)
for(j = i+1;vs[j].v.x==vs[beg].v.x&&vs[j].v.y==vs[beg].v.y;j++ )
if(!commen(i,j))sum++;
beg = i;
}
cout<<sum/2<<endl;
}
return 0;
}
bool commen(int i,int j)
  {
if((p[vs[j].b].x-p[vs[i].a].x)*vs[i].v.y==(p[vs[j].b].y-p[vs[i].a].y)*vs[i].v.x)
return 1;
return 0;
}



|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
24 | 25 | 26 | 27 | 28 | 29 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论

阅读排行榜
评论排行榜
|
|