Election Time
Election Time
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入
输出
示例输入
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的更多相关文章
- [译]ZOOKEEPER RECIPES-Leader Election
选主 使用ZooKeeper选主的一个简单方法是,在创建znode时使用Sequence和Ephemeral标志.主要思想是,使用一个znode,比如"/election",每个客 ...
- hihoCoder 1426 : What a Ridiculous Election(总统夶选)
hihoCoder #1426 : What a Ridiculous Election(总统夶选) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - ...
- berkeley db replica机制 - election algorithm
repmgr_method.c, __repmgr_start_int() 初始2个elect线程. repmgr_elect.c, __repmgr_init_election() __repmgr ...
- 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 ...
- 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 ...
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第二弹)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(题解第一弹)
1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- 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 ...
- 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 ...
随机推荐
- JavaCodeTra 猴子选猴王 约瑟夫循环
之前用的是循环链表,java刚学,不知道怎么用链表.用个小算法吧 代码: import java.util.Scanner; /** * */ /** * @author john * @约瑟夫循环/ ...
- [Javascript] An Introduction to JSPM (JavaScript Package Manager)
JSPM can handle installed packages, transpiling ES6, and bundling all from the command-line. This vi ...
- Android 图标上面添加提醒(二)使用开源UI类库 Viewbadger
版权声明:本文为博主原创文章,未经博主允许不得转载. 上一篇讲到用canvas进行绘制得到对应最终的bitmap. 在实际应用中,我们除了给图标添加数字外,也有可能加一些红色方块之类的图标作为新功能的 ...
- android 49 广播接收者中启动其他组件
main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro ...
- linux块设备IO栈浅析
http://www.sysnote.org/2015/08/06/linux-io-stack/
- 基于HTML5的SLG游戏开发(序)
2012年前后,HTML5游戏凭借跨平台.易移植.部署简单.节省成本等优点被炒的火热,经过一两年的快速发展,市场出现了一些成功地HTML5游戏产品,像磊友的<修仙三国>,神奇时 ...
- Fragment之我的解决方案:Fragmentation
Fragment系列文章:1.Fragment全解析系列(一):那些年踩过的坑2.Fragment全解析系列(二):正确的使用姿势3.Fragment之我的解决方案:Fragmentation 如果你 ...
- linux的grep命令
参考文档如下: linux grep命令 grep abb15455baeb4b23ab47540272ec47eb epps-sas.log | grep operateSettleBill exp ...
- angularJS function
angular.bootstrap 启动Angular angular.element 相当于轻量的JQuery 使用方法: angular.element('#qq'); angular.eleme ...
- php文件加锁 lock_sh ,lock_ex
文件锁有两种:共享锁和排他锁,也就是读锁(LOCK_SH)和写锁(LOCK_EX) 文件的锁一般这么使用: $fp = fopen("filename", "a" ...