Pku3664
<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的更多相关文章
- pku3664 Election Time
http://poj.org/problem?id=3664 水题 #include <stdio.h> #include <map> using namespace std; ...
随机推荐
- Ext4.1 chart的使用
var reportsPanel = Ext.create('Ext.panel.Panel', { id:'reportsPanel', layout: 'fit', tbar: [{ ...
- nj08---process、console
概念:所有属性都可以在程序的任何地方访问,即全局变量.在JavaScript中,通常window是全局对象,而Node.js的全局对象是global,所有全局变量都是global对象的属性,如:con ...
- python 同步IO
IO在计算机中指Input/Output 由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接口.IO编程中,Stream(流)是一个很重要的概念,可以把流想象成一 ...
- 6.CPU调度
总论:所有的程序都是CPU和I/O等待交替执行 CPU调度器的操作时机 调用CPU调度器的时机,通常发生在 某一进程从执行状态转化为等待状态 某一进程从执行状态转化为就绪状态 某一进程从等待状态转为就 ...
- BZOJ 2115 DFS+高斯消元
思路: 先搞出来所有的环的抑或值 随便求一条1~n的路径异或和 gauss消元找异或和最大 贪心取max即可 //By SiriusRen #include <cstdio> #inclu ...
- ajax中Post和Get请求方式的区别?
ajax中Post和Get请求方式的区别: 1.Post传输数据时,不需要在URL中显示出来,而Get方法要在URL中显示. 2.Post传输的数据量大,可以达到2M,而Get方法由于受到URL长度的 ...
- SharePoint InfoPath 保存无法发布问题
设计完表单以后提示以下错误 错误描述 InfoPath无法保存下列表单:******* 此文档库已被重命名或删除,或者网络问题导致文件无法保存.如果此问题持续存在,请于网络管理员联系. 可参考网站 & ...
- js控制分页打印、打印分页示例
1 打印分页 需要添加一段代码 <div style="page-break-before:always;"><br /></div> 2 & ...
- 51Nod 蜥蜴和地下室(搜索)
哈利喜欢玩角色扮演的电脑游戏<蜥蜴和地下室>.此时,他正在扮演一个魔术师.在最后一关,他必须和一排的弓箭手战斗.他唯一能消灭他们的办法是一个火球咒语.如果哈利用他的火球咒语攻击第i个弓箭手 ...
- datable
$("#table_d").append("<table id='dmglTable' class='table table-striped table-hover ...