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 }
  • 相关阅读:
    unity中制作模拟第一人称视角下的指南针
    unity3D 中的C#脚本一个类调用另一类中简单方法
    unity中UI的屏幕自适应代码
    unity中导入插件时报错处理办法
    Unity3D在C#编程中的一些命名空间的引用及说明
    Unity中物体碰撞后去掉相互之间的反弹力
    unity3D打包发布Apk详细步骤
    unity3D开发的程序发布到Android平台上进行运行测试的详细步骤
    JAVA的环境变量配置(方式二)
    Java中的 JDK下载和环境配置(方式一)
  • 原文地址:https://www.cnblogs.com/wlc297984368/p/3250116.html
Copyright © 2011-2022 走看看