码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 3664 Election Time

时间:2015-04-10 22:32:12      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:poj

Election Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7845   Accepted: 4176

Description

The cows are having their first election after overthrowing the tyrannical Farmer John, and Bessie is one of N cows (1 ≤ N ≤ 50,000) running for President. Before the election actually happens, however, Bessie wants to determine who has the best chance of winning.

The election consists of two rounds. In the first round, the K cows (1 ≤ K ≤ N) cows with the most votes advance to the second round. In the second round, the cow with the most votes becomes President.

Given that cow i expects to get Ai votes (1 ≤ Ai ≤ 1,000,000,000) in the first round and Bi votes (1 ≤ Bi ≤ 1,000,000,000) in the second round (if he or she makes it), determine which cow is expected to win the election. Happily for you, no vote count appears twice in the Ai list; likewise, no vote count appears twice in the Bi list.

Input

* Line 1: Two space-separated integers: N and K 
* Lines 2..N+1: Line i+1 contains two space-separated integers: Ai and Bi

Output

* Line 1: The index of the cow that is expected to win the election.

Sample Input

5 3
3 10
9 2
5 6
8 4
6 5

Sample Output

5

水题,结构体排序,要按第一次得票和第二次得票排两次序,第一次对n个排序,第二次对前k个排序。
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef __int64 ll;

const int maxn=50000+10;

struct pp
{
	ll first,second;
	int id;
}s[maxn];

int cmp1(const pp &x,const pp &y){
	return x.first>y.first;
}

int cmp2(const pp &x,const pp &y){
	return x.second>y.second;
}

int main()
{
	int n,k,i,j,ans;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%I64d%I64d",&s[i].first,&s[i].second);
		s[i].id=i+1;
	}
	sort(s,s+n,cmp1);
	sort(s,s+k,cmp2);		//注意第二次是前k个
	printf("%d\n",s[0].id);
	return 0;
}


POJ 3664 Election Time

标签:poj

原文地址:http://blog.csdn.net/u013068502/article/details/44983797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!