请教POJ1971题
http://acm.pku.edu.cn/JudgeOnline/problem?id=1971
我是求出各条线段的中点,然后将中点进行排序,然后计算平行四边形的个数,但结果是WA,不知为什么
#include <iostream>#include <vector>#include <algorithm>#include <fstream>using namespace std;struct Point{ float x,y;};Point pt[1001];vector<Point> point;int test,n;bool cmp(Point p1,Point p2){ if(p1.x != p2.x) return p1.x < p2.x; return p1.y < p2.y;}int main(){ fstream file; file.open("1.txt",ios::in | ios::out); file>>test; while(test--) { file>>n; point.clear(); int i = 0; int j = 0; for(i = 0; i < n; i++) { file>>pt[i].x>>pt[i].y; } for(i = 0; i < n; i++) { for(j = i + 1; j < n; j++) { Point temp; temp.x = (pt[i].x + pt[j].x) / 2; temp.y = (pt[i].y + pt[j].y) / 2; point.push_back(temp); } } sort(point.begin(),point.end(),cmp); vector<Point>::iterator iter; int ans = 0; int res = 0; for(iter = point.begin(); iter != point.end() - 1; iter++) { if(iter->x == (iter + 1)->x && iter->y == (iter + 1)->y) ans++; else { res += ans * (ans + 1) / 2; ans = 0; } } cout<<res<<endl; } system("pause"); return 0;}