poj 3664 Election Time
来源:互联网 发布:mysql 显示视图前几行 编辑:程序博客网 时间:2024/05/17 04:29
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 33 109 25 68 46 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;}
- 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 再想想
- POJ Election Time
- poj——3664——Election Time
- Election Time
- Election Time
- (Relax ST1.22)POJ 3664 Election Time(两次排序的巧妙应用)
- pku3664 Election Time
- BNUOJ 14362 Election Time
- POJ_3664 Election Time
- POJ3664 Election Time
- POJ3664——Election Time
- poj 2643 Election
- python twisted reactor 的定时处理
- iphone存储以及读取指定文件(Documents)中的内容
- 在录音等情况下保持屏幕长亮
- 堆内存访问错误
- dex 文件结构
- poj 3664 Election Time
- javaScript中prototype的妙用 巧妙运用prototype属性原型链创建对象
- 中星ZC3XX摄像头驱动在内核中的配置
- linux find 用法
- Oracle存储过程-pl/sql编程
- java中静态代码块的用法 static用法详解 类的加载顺序
- 5.2.3.1 避免复杂的元组
- xcode6模拟器不显示键盘解决方案
- 自动创建计划任务 删除