zoukankan      html  css  js  c++  java
  • 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>


  • 相关阅读:
    Linux:password 与passphrase
    QT设置openCV头文件和链接动态库路径
    matlab对图像加入噪声的方法
    RGB到HSV的彩色空间变化 Matlab
    QImage与IplImage之间的转换
    iframe自适应高度(简单经典)兼容ie6ie9 ,firefox,opera,chrome
    转载:关于生成并发唯一性流水号的解决方案
    EXCEL表格纵横转换
    rdlc打印时多出空白页面(reportviewer)
    一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254544.html
Copyright © 2011-2022 走看看