<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. 提高FPGA速度的quartus编译选项

    Turning on some optimizations in Quartus II may help increase it. Here are some you may want to try: ...

  2. [Swift]forEach详解

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. Python Schema使用说明

    转自https://segmentfault.com/a/1190000011777230 Python Schema使用说明 Schema是什么? 不管我们做什么应用,只要和用户输入打交道,就有一个 ...

  4. ajax中Post和Get请求方式的区别?

    ajax中Post和Get请求方式的区别: 1.Post传输数据时,不需要在URL中显示出来,而Get方法要在URL中显示. 2.Post传输的数据量大,可以达到2M,而Get方法由于受到URL长度的 ...

  5. echarts 绑定事件重复执行问题。

    网上所有,先调用.off 方法后再调用.on 绑定事件. 无效果,查看api未发现off方法,于是采用,先删除原先元素,后重新生成的方式. 场景描述. 用户查询时,每次结果都对应一张饼图.该张饼图绑定 ...

  6. HDU 3277 Marriage Match III

    Marriage Match III Time Limit: 4000ms Memory Limit: 32768KB This problem will be judged on HDU. Orig ...

  7. Spring Cloud学习笔记【六】Hystrix 监控数据聚合 Turbine

    上一篇我们介绍了使用 Hystrix Dashboard 来展示 Hystrix 用于熔断的各项度量指标.通过 Hystrix Dashboard,我们可以方便的查看服务实例的综合情况,比如:服务调用 ...

  8. qt 闰年

    bool QDate::isLeapYear ( int year ) [static]

  9. HTML学习----------DAY1 第三节

    本章通过实例向您演示最常用的 HTML 标签. 提示:不要担心本章中您还没有学过的例子,您将在下面的章节中学到它们. 提示:学习 HTML 最好的方式就是边学边做实验.我们为您准备了很好的 HTML ...

  10. 23 HBase 存储架构。

    个 Region,Region会下线,新Split出的2个子Region会被HMaster分配到相应的HRegionServer 上,使得原先1个Region的压力得以分流到2个Region上由此过程 ...