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; ...
随机推荐
- 46. AngularJS所有版本下载
转自:https://www.cnblogs.com/best/tag/Angular/ 官网下载:https://angularjs.org/ AngularJS所有版本下载:https://cod ...
- directshow 获取本地摄像头播放
最近因为项目的需要,做了一个基本的获取本地笔记本摄像头并且播放的例子,因为网上的关于这部分的完整例子基本都没有,那我就上传一个吧,希望能够帮到需要学习视频的朋友. 另外也是为了纪念雷霄骅博士为音视频方 ...
- sql 知识点
1 聚集索引和非聚集索引的区别 聚集索引是指 表中存储的数据按照索引的顺序来存储,数据检索效率高,但是对数据更新影响较大:非聚集索引是数据存储在一个地方,索引存储在另一个地方:索引带有指针,指向数据的 ...
- shell判断变量是字符还是数字
ok,以后最好是每天一个shell小脚本吧,这样以后工作时还可以直接套用,嗯,比较不错,顺便还可以带给刚入门shell的朋友一些帮助,好了,废话不多说,下面是我两种判断的实现方式: 1.通过grep去 ...
- python-生成器即send()用法
参考链接: http://www.mamicode.com/info-detail-2399245.html 作者首先介绍了生成器的作用:是为了让程序员可以更简单的编写用来产生值的序列的代码,然后又介 ...
- 【Henu ACM Round#18 F】Arthur and Walls
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 考虑,为什么一个连通块里面的空格没有变成一个矩形? 如果不是形成矩形的话. 肯定是因为某个2x2的单张方形里面. 只有一个角是墙.其 ...
- Java基础学习总结(15)——java读取properties文件总结
一.java读取properties文件总结 在java项目中,操作properties文件是经常要做的,因为很多的配置信息都会写在properties文件中,这里主要是总结使用getResource ...
- 无比强大!Python抓取cssmoban网站的模版并下载
Python实现抓取http://www.cssmoban.com/cssthemes网站的模版并下载 实现代码 # -*- coding: utf-8 -*- import urlparse imp ...
- Windows远程登录Linux
本文以Ubuntu Kylin1404为例,说明如何通过Windows远程登录Linux. 首先,要确保Ubuntu上SSH服务执行正常.默认情况下,Ubuntu已装有SSHclient.比方输入ss ...
- vue22 路由
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...