POJ 3664----Election Time
2015-04-11 17:18
627 查看
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
Sample Output
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#include<stdio.h> #include<algorithm> using namespace std; struct vote { int a,b,num; }cow[50005]; int cmpa(vote p,vote q) { return p.a>q.a; } int cmpb(vote p,vote q) { return p.b>q.b; } int main(void) { int n,k,i; scanf("%d%d",&n,&k); for(i=0;i<n;i++) { scanf("%d%d",&cow[i].a,&cow[i].b); cow[i].num=i+1; } sort(cow,cow+n,cmpa); sort(cow,cow+k,cmpb); printf("%d\n",cow[0].num); return 0; }
相关文章推荐
- POJ3664——Election Time
- POJ_3664 Election Time
- poj 3664 Election Time
- POJ 3664 Election Time(简单的快速排序)
- POJ 3664 Election Time 题解
- poj 3664 Election Time
- (Relax ST1.22)POJ 3664 Election Time(两次排序的巧妙应用)
- POJ 3664 Election Time 题解
- poj——3664——Election Time
- POJ 3664 Election Time
- poj 3664 Election Time
- POJ 3664 Election Time 再想想
- POJ 3664 Election Time
- (解题报告)POJ3664---Election Time---用结构体实现两组相关联数据的排序问题
- POJ 3664
- poj3664
- poj 3664
- poj 3664
- POJ 3664 排序,水题
- pku3664 Election Time