<span style="color:#6600cc;">/*
D - Election Time
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status
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 3
3 10
9 2
5 6
8 4
6 5
Sample Output
5
BY Grant Yuan
2014.7.11
*/
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
int m,k;
typedef struct{
long long f;
long long s;
int m;
}vote;
vote v[50001];
void Qsort(vote a[],int left,int right)
{ int key=a[left].f,i=left,j=right+1,t,l;
if(left<right){
while(1){
while(i<j&&a[--j].f<key);
while(i<j&&a[++i].f>key);
if(i>=j)break;
t=a[j].f; a[j].f=a[i].f;a[i].f=t;
t=a[j].s; a[j].s=a[i].s;a[i].s=t;
t=a[j].m; a[j].m=a[i].m;a[i].m=t;
}
t=a[left].f;a[left].f=a[j].f;a[j].f=t;
t=a[left].s;a[left].s=a[j].s;a[j].s=t;
t=a[left].m;a[left].m=a[j].m;a[j].m=t;
Qsort(a,left,i-1);
Qsort(a,i+1,right);}
} int main()
{ int max;
cin>>m>>k;
for(int i=0;i<m;i++)
{
cin>>v[i].f>>v[i].s;
v[i].m=i;}
Qsort(v,0,m);
max=0;
for(int i=1;i<k;i++)
if(v[i].s>v[max].s)
max=i;
cout<<v[max].m+1<<endl;
return 0;
}
</span>

Pku3664的更多相关文章

  1. pku3664 Election Time

    http://poj.org/problem?id=3664 水题 #include <stdio.h> #include <map> using namespace std; ...

随机推荐

  1. Redis 存储图片 [base64/url/path]vs[object]

    一.base64图片编解码 基本流程:从网络获取下载一张图片.然后base64编码,再base64解码,存到本地E盘根文件夹下. import java.awt.image.BufferedImage ...

  2. Django是什么

    Django是什么 Django是什么? 是基于python语言的优秀的web开发框架.很多有名的网站比如youtube就是用django开发的. Python写的开源Web应用框架, 快速搭建blo ...

  3. WEB前端开发工程师成长计划

    今天看到一篇文章,感觉很不错,于是转了过来,同时也给自己规划一个方向. [背景] 如果你是刚进入web前端研发领域,想试试这潭水有多深,看这篇文章吧:如果你是做了两三年web产品前端研发,迷茫找不着提 ...

  4. Django和Flask相对总结目录

    Django中文文档官网:https://yiyibooks.cn/xx/Django_1.11.6/index.html Flask中文文档官网:https://dormousehole.readt ...

  5. 再谈Ubuntu和CentOS安装好之后的联网问题(桥接和NAT、静态和动态ip)(博主推荐)

    不多说,直接上干货! 首先,普及概念. hostonly.桥接和NAT的联网方式 对于CentOS系统,用的最多的就是,NAT和桥接模式 CentOS 6.5静态IP的设置(NAT和桥接联网方式都适用 ...

  6. 200 from memory cache / from disk cache / 304 Not Modified 区别

    三者情况有什么区别和联系,什么情况下会发生200 from memory cache 或 200 from disk cache 或 304 Not Modified? 200 from memory ...

  7. HDU 5223 GCD

    题意:给出一列数a,给出m个区间,再给出每个区间的最小公倍数 还原这列数 因为数组中的每个数至少都为1,而且一定是这个区间的最小公约数ans[i]的倍数,求出它与ans[i]的最小公倍数,如果大于1e ...

  8. 51Nod 天堂里的游戏

    多年后,每当Noder看到吉普赛人,就会想起那个遥远的下午. Noder躺在草地上漫无目的的张望,二楼的咖啡馆在日光下闪着亮,像是要进化成一颗巨大的咖啡豆.天气稍有些冷,但草还算暖和.不远的地方坐着一 ...

  9. require(): open_basedir restriction in effect. File

    新安装的 lnmp 环境,将项目放上报 require(): open_basedir restriction in effect. File 的错误! 错误日志显示,访问脚本不在 open_base ...

  10. 洛谷3962 [TJOI2013]数字根

    题目描述 一个数字的数字根定义为:这个数字每一位的数字加起来求和,反复这个过程直到和小于10.例如,64357的数字跟为7,因为6+4+3+5+7=25,2+5=7个区间的数字根定义为这个区间所有数字 ...