POJ 3664 排序,水题
2012-06-28 16:04
232 查看
Election Time
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
Source
USACO 2008 January Bronze
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5531 | Accepted: 2998 |
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
Source
USACO 2008 January Bronze
#include <stdio.h> #include <algorithm> const int S=51000; using namespace std; struct TT{ int id,v1,v2; }f[S]; inline bool cmp1(const TT &a, const TT &b){ return (a.v1>b.v1); } inline bool cmp2(const TT &a, const TT &b){ return (a.v2>b.v2); } int main(){ int n,k,i; scanf("%d%d",&n,&k); for (i=0;i<n;i++){ scanf("%d%d",&f[i].v1,&f[i].v2); f[i].id=i+1; } sort(f,f+n,cmp1); sort(f,f+k,cmp2); printf("%d\n",f[0].id); return 0; }
相关文章推荐
- poj_1007 排序水题
- poj 2388 排序的水题
- (Relax ST1.22)POJ 3664 Election Time(两次排序的巧妙应用)
- POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题
- (解题报告)POJ3664---Election Time---用结构体实现两组相关联数据的排序问题
- poj 2291/3637 水题排序
- POJ 3312 Mahershalalhashbaz, Nebuchadnezzar, and Billy Bob Benjamin Go to the Regionals (排序水题)
- POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题
- POJ 2388 排序水题
- POJ 2007 Scrambled Polygon 凸包加排序 水题一道
- POJ 1247 Magnificent Meatballs(我的水题之路——数组两边求和)
- POJ 1326 Mileage Bank(我的水题之路——模拟,四舍五入)
- CF 721B 字符串排序水题
- poj1979 水题简单dfs
- POJ水题总结
- hdoj--1379--DNA Sorting(排序水题)
- POJ 2109 Power of Cryptography(我的水题之路——k^n=p)
- Flying to the Mars(hdu1800,水题排序)
- POJ 2498 StuPId(我的水题之路——from back to front- -!)
- POJ 1002 487-3279(排序or不排序)