您的位置:首页 > 其它

poj 3664 Election Time

2014-10-20 14:04 337 查看
Election Time

Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 7415Accepted: 4013
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


题意:一群牛选总统,有两次选举的模拟a、b,选举规则为第一次选举前k名的参加第二次选举,第二场选举b最大的为总统;

#include <iostream>
#include <algorithm>
using namespace std;
struct cow{
int index,a,b;
}c[50005];
int cmp1(cow x,cow y){
if (x.a>=y.a)
return 1;
return 0;
}
int cmp2(cow x,cow y){
if (x.b>=y.b)
return 1;
return 0;
}
int main(){
int n,k;
while (cin>>n>>k){
for (int i=0;i<n;i++){
c[i].index=i;
cin>>c[i].a>>c[i].b;
}

sort(c,c+n,cmp1);

sort(c,c+k,cmp2);

cout<<c[0].index+1<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: