【poj解题】3664
简单,两次排序
#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; }
喜欢一起简单,实用的东西,拒绝复杂花哨,我不是GEEK.