Election Time

Time Limit: 1000MS Memory limit: 65536K

题目描述

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.

输入

 Line 1: Two space-separated integers: N and K

Lines 2..N+1: Line i+1 contains two space-separated integers: Ai and Bi
 

输出

 The index of the cow that is expected to win the election.

示例输入

5 3
3 10
9 2
5 6
8 4
6 5

示例输出

5

题目意思,一些牛进行竞选,竞选两次,第一次有K只牛入围,第二次竞选从入围的牛进行竞选第一名。

思路,改进快速排序,进行两次即可,不多说了具体代码如下:

 #include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
int a,b,num;
} s[];
int cmpa(node a, node b)
{
if (a.a == b.a) return a.b > b.b;
return a.a > b.a;
}
int cmpb(node a, node b)
{
if (a.b == b.b) return a.a > b.a;
return a.b > b.b;
}
int main()
{
int i,n,k;
while (scanf("%d%d", &n, &k) != EOF)
{
for (i = ; i < n; ++i)
{
scanf("%d%d", &s[i].a, &s[i].b);
s[i].num = i + ;
}
sort(s, s + n, cmpa);
sort(s, s + k, cmpb);
printf("%d\n", s[].num);
}
return ;
}

Election Time的更多相关文章

  1. [译]ZOOKEEPER RECIPES-Leader Election

    选主 使用ZooKeeper选主的一个简单方法是,在创建znode时使用Sequence和Ephemeral标志.主要思想是,使用一个znode,比如"/election",每个客 ...

  2. hihoCoder 1426 : What a Ridiculous Election(总统夶选)

    hihoCoder #1426 : What a Ridiculous Election(总统夶选) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - ...

  3. berkeley db replica机制 - election algorithm

    repmgr_method.c, __repmgr_start_int() 初始2个elect线程. repmgr_elect.c, __repmgr_init_election() __repmgr ...

  4. zookeeper 集群 Cannot open channel to X at election address Error contacting service. It is probably not running.

    zookeeper集群   启动 1.问题现象. 启动每一个都提示  STARTED 但是查看 status时全部节点都报错 [root@ip-172-31-19-246 bin]# sh zkSer ...

  5. bzoj1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区

    Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...

  6. 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit:  ...

  7. 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)

    1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit:  ...

  8. A Bayesian election prediction, implemented with R and Stan

    If the media coverage is anything to go by, people are desperate to know who will win the US electio ...

  9. bzoj:1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区

    Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...

随机推荐

  1. Android 颜色渲染(四) BitmapShader位图渲染

    版权声明:本文为博主原创文章,未经博主允许不得转载. Android 颜色处理(四) BitmapShader位图渲染 public   BitmapShader(Bitmap bitmap,Shad ...

  2. JS浮点类型计算

    /* ---------------- JS浮点数运算重置 ---------------- */ //加法函数 //调用:accAdd(arg1,arg2) //返回值:arg1加上arg2的精确结 ...

  3. cidaemon.exe进程cpu占用率高及关闭cidaemon.exe进程方法

    问题描写叙述:   这段时间机器总是出现一个奇怪的问题:cidaemon.exe进程占用CUP率98%以上,大大影响了电脑的正常使用.资源管理器中出现多个cidaemon.exe进程,强制结束占用cp ...

  4. mybatis0207 resultType、resultMap、延迟加载使用场景总结

    延迟加载: 延迟加载实现的方法多种多样,在只查询单表就可以满足需求,为了提高数据库查询性能使用延迟加载,再查询关联信息. mybatis提供延迟加载的功能用于service层. resultType: ...

  5. 搬移到GitHub Page啦~

    GitHub: https://github.com/BOT-Man-JL/ Page: https://BOT-Man-JL.github.io/

  6. JS 拼凑字符串

    和Java一样,JS中直接用"+"号拼凑字符串是很耗费资源的,所以在大量拼凑字符串的情景中,我们也需要一个类似于StringBuffer的工具, 下面利用Array.join()方 ...

  7. 使用JExcel导出excel文件

    package org.aaa.portal.tools; import java.io.File; import java.io.IOException; import java.util.List ...

  8. 怎样写好一份IT技术岗位的简历

    10月是校园招聘的旺季,很多应届毕业生都忙碌起来了,从CSDN笔试-面试文章的火热程度,从我收到的简历就看得出来. 我很久没有参与笔试和面试了,所以只能从“简历”来阐述下我的看法. 截至目前,已经帮8 ...

  9. Java 原始数据类型转换

    在开发中经常遇到数据类型转换的问题,大多数都是拿来强制转换,强制转换可能会出现你意想不到的问题: int a = -1; 我们经过多重转换之后:int b = (int)(char)(byte) a ...

  10. NetworkOnMainThreadException

    来自:http://www.2cto.com/kf/201402/281526.html NetworkOnMainThreadException extends RuntimeException j ...