zoukankan      html  css  js  c++  java
  • poj 3664 Election Time

    题目描述

    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.

    输入

     Line 1: Two space-separated integers: N and K 
    Lines 2..N+1: Line i+1 contains two space-separated integers: Ai and Bi
     

    输出

     The index of the cow that is expected to win the election.

    示例输入

    5 3
    3 10
    9 2
    5 6
    8 4
    6 5

    示例输出

    5
    
    题意:输入N行数据 求出前k项中第二轮得票最多的是哪一项
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #define N 50005
     4 
     5 typedef struct cow
     6 {
     7     int ai,bi,data;//ai第一列数据,bi第二列数据,data存储位置信息
     8 } Cow;
     9 Cow a[N];
    10 
    11 /*int型数据qsort排序方法头文件位于#include<stdlib.h>
    12 格式:
    13 int cmp ( const void *a , const void *b )
    14 {
    15 return *(int *)a - *(int *)b;由小到大排序
    16 }
    17 qsort(num,100,sizeof(num[0]),cmp);*/
    18 
    19 int cmp ( const void *a , const void *b )
    20 {
    21     return *(int *)b - *(int *)a;
    22 }
    23 
    24 int main()
    25 {
    26     int n,k,i,max,j;
    27     scanf("%d%d",&n,&k);
    28     for(i=0; i<n; i++)
    29     {
    30         scanf("%d%d",&a[i].ai,&a[i].bi);
    31         a[i].data=i+1;
    32     }
    33     qsort(a,n,sizeof(Cow),cmp);//int型数据qsort排序方法头文件位于#include<stdlib.h>
    34     for(i=0,max=0; i<k; i++)
    35     {
    36         if(max<a[i].bi)
    37         {
    38             max = a[i].bi;
    39             j = i;
    40         }
    41     }
    42     printf("%d
    ",a[j].data);
    43     return 0;
    44 
    45 }
  • 相关阅读:
    Android笔记——数据库升级与降级
    Android笔记——SQLiteOpenHelper类
    Android笔记——关于Cursor类的介绍
    Android笔记——permission权限大全
    Android笔记——Android中visibility属性VISIBLE、INVISIBLE、GONE的区别
    Android笔记——提升ListView的运行效率
    Android知识——ViewHolder的作用与用法
    Tween Animation----Rotate旋转动画
    Tween Animation----Translate位置移动动画
    Tween Animation---Scale渐变尺寸缩放动画
  • 原文地址:https://www.cnblogs.com/wlc297984368/p/3250116.html
Copyright © 2011-2022 走看看