poj——3664——Election Time
2014-01-24 16:31
363 查看
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<iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int n,k; const int M=50010; struct node { int a; int b; int num; }Node[M]; int cmpa(node a,node b) { if(a.a!=b.a) return a.a>b.a; else return a.b>b.b; } int cmpb(node a,node b) { if(a.b!=b.b) return a.b>b.b; else return a.a>b.a; } int main() { while(cin>>n>>k) { for(int i=0;i<n;i++) { scanf("%d%d", &Node[i].a, &Node[i].b); Node[i].num=i+1; } sort(Node,Node+n,cmpa); sort(Node,Node+k,cmpb); printf("%d\n",Node[0].num); } return 0; }
相关文章推荐
- hdu3461
- [转] Linux Daemon Writing HOWTO
- IOS7 NavigationBar 遇到的问题
- 红帽:我们有能力用OpenStack云构建IaaS
- Fixing nios problem "System ID mismatch System timestamp mismatch"
- SUSE成为AWS GovCloud (US)支持的首款企业级Linux
- UVa 10361 - Automatic Poetry解题报告
- AFNetworkingV2Client改进版
- qt下qml和c++交互信号槽机制测试
- CentOS下通过locale来设置字符集
- bae3.0第四步 第一个polls系统
- 错误:[将截断字符串或二进制数据。\r\n语句已终止。]
- json全套
- synthesis-of-weak-property-only-allowed-in-arc-or-gc-mode ARC属性
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
- js截取字符串
- Windows 应用程序交互过程
- 联想集团收购IBM x86服务器业务
- cacti监控一览无余
- hdu 2152 有上下界的母函数使用