简单,两次排序

#include <stdio.h>
#include <stdlib.h>
#include <string.h> #define MAX 50000 struct Vote {
int index;
int a;
int b;
}; struct Vote candidates[MAX];
int N, K; int cmp_1(const void * a, const void * b) {
return ((struct Vote *)b)->a - ((struct Vote *)a)->a;
}
int cmp_2(const void * a, const void * b) {
return ((struct Vote *)b)->b - ((struct Vote *)a)->b;
} int pick() {
qsort(candidates, N, sizeof(candidates[0]), cmp_1);
qsort(candidates, K, sizeof(candidates[0]), cmp_2);
return candidates[0].index;
} int main() {
int i;
int res; scanf("%d%d", &N, &K);
for(i = 0; i < N; i++) {
scanf("%d%d", &candidates[i].a, &candidates[i].b);
candidates[i].index = i + 1;
} res = pick();
printf("%d\n", res);
return 0;
}

  

【poj解题】3664的更多相关文章

  1. POJ解题经验交流

    感谢范意凯.陈申奥.庞可.杭业晟.王飞飏.周俊豪.沈逸轩等同学的收集整理.   题号:1003 Hangover求1/2+1/3+...1/n的和,问需多少项的和能超过给定的值 类似于Zerojudg ...

  2. 【poj解题】1028

    stack的应用 #include<iostream> #include<stack> #include<stdio.h> #include<stdlib.h ...

  3. 【poj解题】3663

    排序, 遍历,需要裁减 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX ...

  4. 【poj解题】1308

    判断一个图是否是一个树,树满足一下2个条件即可:1. 边树比node数少12. 所有node的入度非0即1 节点数是0的时候,空树,合法树~ 代码如下 #include <stdio.h> ...

  5. [poj解题]1017

    Packets Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41014   Accepted: 13776 Descrip ...

  6. 洛谷 P1731 [NOI1999]生日蛋糕 && POJ 1190 生日蛋糕

    题目传送门(洛谷)  OR 题目传送门(POJ) 解题思路: 一道搜索题,暴力思路比较容易想出来,但是这道题不剪枝肯定会TLE.所以这道题难点在于如何剪枝. 1.如果当前状态答案已经比我们以前某个状态 ...

  7. 网络-05-端口号-F5-负载均衡设-linux端口详解大全--TCP注册端口号大全备

    [root@test1:Standby] config # [root@test1:Standby] config # [root@test1:Standby] config # [root@test ...

  8. POJ 1003 解题报告

    1.问题描述: http://poj.org/problem?id=1003 2.解题思路: 最直观的的想法是看能不能够直接求出一个通项式,然后直接算就好了, 但是这样好水的样子,而且也不知道这个通项 ...

  9. POJ 1004 解题报告

    1.题目描述: http://poj.org/problem?id=1004 2.解题过程 这个题目咋一看很简单,虽然最终要解出来的确也不难,但是还是稍微有些小把戏在里面,其中最大的把戏就是float ...

随机推荐

  1. const、volatile、mutable的用法

    http://blog.csdn.net/wuliming_sc/article/details/3717017 const.volatile.mutable的用法 const修饰普通变量和指针 co ...

  2. 最简单的入门github

    下载   git clone ***(地址) 上传  1. 先注册一个github账号 2.在github网站上建设一个工程 3. 把想要上传的数据上传到网站去 1 git config --glob ...

  3. Linq分组,linq方法分组

    Group在SQL经常使用,通常是对一个字段或者多个字段分组,求其总和,均值等. Linq中的Groupby方法也有这种功能.具体实现看代码: 假设有如下的一个数据集: 01.public class ...

  4. 1.1 selenium 安装

    1.在火狐浏览器的附加组件里搜索Selenium IDE

  5. 修改apache配置文件去除thinkphp url中的index.php

    例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index. ...

  6. java中io对文件操作的简单介绍

    11.3 I/O类使用 由于在IO操作中,需要使用的数据源有很多,作为一个IO技术的初学者,从读写文件开始学习IO技术是一个比较好的选择.因为文件是一种常见的数据源,而且读写文件也是程序员进行IO编程 ...

  7. jz2440 环境搭建遇到的问题

    已解决:

  8. LightOJ 1341 Aladdin and the Flying Carpet(整数拆分定理)

    分析:题目并不难理解,就是一些细节上的优化需要我们注意,我在没有优化前跑了2000多MS,优化了一些细节后就是400多MS了,之前还TLE了好几次. 方法:将整数拆分为质因子以后,表达为这样的形式,e ...

  9. mouseleave 和 mouseout 区别

    jQuery中的mouseleave和mouseout的区别 $("li").each(function(i) {            //删除的鼠标划过的显示与隐藏       ...

  10. Python 安装matplotlib,six,dateutil,pyparsing 完整过程

    [摘要:正在做词频剖析的时间,须要用matlotlib 做图表,柱状图啥的,因而便最先了一个又一个的装置库的进程 由于matplotlib 须要依附很多其他科教盘算的第三圆库,须要一个一个的装置了.. ...