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

为什么我500多ms?

Posted by HG at 2009-05-04 21:29:12 on Problem 3664
In Reply To:partial_sort vs sort (c++ stl) Posted by:tanghaibao at 2008-12-18 11:48:15
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
class cow
{
public:
	long a;
	long b;
	long index;
	cow(long a,long b,long index)
	{
		this->a = a;
		this->b = b;
		this->index = index;
	}
};
bool order(cow a,cow b);
vector<cow> all;
int main()
{
	long n,k,i,a,b,output;
	cin>>n>>k;
	for(i = 0 ; i < n ; i ++)
	{
		cin>>a>>b;
		all.push_back(*(new cow(a,b,i + 1)));
	}
	sort(all.begin(),all.begin() + n,order);
	output = 0;
	for( i = 1 ; i < k ; i++)
		if(all[output].b < all[i].b)
			output = i;
	cout<<all[output].index;
	return 0;
}
bool order(cow a,cow b)
{
	return a.a > b.a;
}

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