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. 【MongoDB】在windows平台下mongodb的分片集群(五)

    本篇接着上面的四篇继续讲述在window平台下mongodb的分片集群搭建. 在分片集群中也照样能够创建索引,创建索引的方式与在单独数据库中创建索引的方式一样.因此这不再多说.本篇主要聚焦在分片键的选 ...

  2. android 21 隐式意图启动系统预定义activity

    Intent intent=new Intent(LoginActivity.this, MainActivity.class);//显示意图启动,显示从一个activity到另一个activity, ...

  3. centos 6 搭建ftp服务器支持匿名读写

    转载请注明: 凌云物网智科嵌入式实验室: http://iot-yun.com/     郭文学<guowenxue@gmail.com> vsftpd在运行时一定要关闭SELinux,否 ...

  4. Bash关闭输出(关闭正确、错误输出)

    利用&>重定向,不输出任何内容: echo hello &> /dev/null 关闭正确输出: echo hello 1> /dev/null 关闭错误输出: ec ...

  5. setTimeout 方法用于在指定的毫秒数后调用函数或计算表达式

    setTimeout 方法用于在指定的毫秒数后调用函数或计算表达式

  6. angularJS function

    angular.bootstrap 启动Angular angular.element 相当于轻量的JQuery 使用方法: angular.element('#qq'); angular.eleme ...

  7. treeview右键添加新节点

    private void advTree1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Righ ...

  8. ASP.NET网站实现中英文转换(本地化资源)

    主要内容: 1. 简单例子 2. 进一步认识Localization 3. 语言转换 4. 解决方案 一. 简单例子 下面通过一个简单的例子来说明利用Localization来实现本地化是那么的简单, ...

  9. 关于 ASP.NET 验证码

    Session["CheckCode"] 这个..不懂神马意思.. .创建一个用户控件 用户名:TextBox 密码: TextBox 验证码:TextBox 验证码图片 < ...

  10. 【模板】【凸包】Graham_scan

    /* 唐代李白 <江夏别宋之悌> 楚水清若空,遥将碧海通.人分千里外,兴在一杯中. 谷鸟吟晴日,江猿啸晚风.平生不下泪,于此泣无穷. */ #include <iostream> ...