<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. 使用ShareSDK实现第三方授权登录、分享以及获取用户资料效果,项目中包含:源码+效果图+项目结构图

    [Android应用开发详解]第01期:第三方授权认证(一)实现第三方授权登录.分享以及获取用户资料   由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字和图片等这样的效果,几经波折, ...

  2. android页面布局(listview填充中间)

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  3. Mojo For Chromium Developers1

    Mojo For Chromium Developers Overview This document contains the minimum amount of information neede ...

  4. tensorflow 问题库

    1.module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell' 将tf.nn.rnn_cell ->tf.contrib.rnn

  5. Unity C# 关于设计模式的思考

    一.当你的项目发现有如下问题之一时,就需要考虑重构代码,可能会有某种模式适合. 1.代码无法进行单元测试. 2.需求的变动总是导致代码的变动. 3.有重复代码的存在. 4.继承层次过多. 5.隐藏的依 ...

  6. ECNUOJ 2575 Separate Connections

    Separate Connections Time Limit:5000MS Memory Limit:65536KBTotal Submit:421 Accepted:41 Description  ...

  7. [React Native] Use the SafeAreaView Component in React Native for iPhone X Compatibility

    In this lesson, you will learn how to use the SafeAreaView component to avoid the sensor cluster (th ...

  8. Java定时器TimeTask

    package com.alan.timer; import java.util.Calendar;import java.util.Date;import java.util.Timer;impor ...

  9. BZOJ2020: [Usaco2010 Jan]Buying Feed II

    [传送门:BZOJ2020] 简要题意: 约翰开车回家,遇到了双十一节,那么就顺路买点饲料吧.回家的路程一共有E 公里,这一路上会经过N 家商店,第i 家店里有Fi 吨饲料,售价为每吨Ci 元.约翰打 ...

  10. .Net中字典的使用

    /// <summary> /// 获取用户市信息 /// </summary> /// <param name="CustomerId">&l ...