Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我是将中点排序做的,可是WA,谁能看看呀?

Posted by yeknight at 2010-04-28 17:05:01 on Problem 1971
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator