poj 3664 Election Time

在这篇博客中,作者介绍了如何通过分析牛群选举的投票数据来预测胜选者。选举分为两轮,第一轮中得票最多的K头牛进入第二轮,最终一轮得票最高的牛将成为总统。作者提供了代码实现,包括对投票数据的排序和比较,以确定胜选者。
Election Time
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5030 Accepted: 2750

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 ≤ KN) 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
#include<iostream>
#include<algorithm>
struct vote
{
int vo1;
int vo2;
int index;
};
int comp1(vote v1, vote v2)
{
return v1.vo1 > v2.vo1;
}
int comp2(vote v1, vote v2)
{
return v1.vo2 > v2.vo2;
}
using namespace std;
int main()
{
int n,k;
int i;
vote in[50000];
cin>>n;
cin>>k;
for(i=0;i<n;i++)
{
cin>>in[i].vo1;
cin>>in[i].vo2;
in[i].index=i+1;
}
sort(in,in+n,comp1);
sort(in,in+k,comp2);
cout<<in[0].index<<endl;
}

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/23/2259864.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值