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 |
我是将中点排序做的,可是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; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator