POJ 3664 (qsort 快排)
2010-11-15 21:20
267 查看
//2010-11-15 #include <stdio.h> #include <stdlib.h> struct vote { int firstRound; int secondRound; int ID; }; struct vote arr[50001]; int cmp(const void *a, const void *b) {//必须这样写!用“->”错! 明白此处 “.” 和“ ->” 的区别!!!! return (*(struct vote *)b).firstRound - (*(struct vote *)a).firstRound; // return ((struct vote *)b)->firstRound - ((struct vote *)a)->firstRound; 这样也是可以的 } /* 1. 结构体变量.成员名 2. (* p).成员名 两侧的括号不能省,成员运算符.优先于 * 3. p->成员名 三者等价! 详见谭浩强 c语言程序设计第三版 p289-290 */ int main() { int i; int nCows, nFirstSelect; int temp, index; while(2==scanf("%d%d", &nCows, &nFirstSelect)) { for(i=0; i<nCows; i++) { scanf("%d%d", &arr[i].firstRound, &arr[i].secondRound); arr[i].ID=i+1; } qsort(arr, nCows, sizeof(arr[0]), cmp); temp=0; for(i=0; i<nFirstSelect; i++) { if(arr[i].secondRound>temp) { temp=arr[i].secondRound; index=i; } } printf("%d/n", arr[index].ID); } return 0; }
相关文章推荐
- poj 2388 Who's in the Middle-----qsort 排序
- POJ 2503 Babelfish qsort+bserach
- poj 3664 Election Time
- poj 2807 两倍 memset(num,0,sizeof num); qsort(num,i,sizeof(int),Compare);
- H - Election Time POJ - 3664
- POJ 3664----Election Time
- POJ 3664 Election Time 题解
- poj-3664
- POJ 3719 qsort学生信息排序
- POJ_3664 Election Time
- poj 3664
- poj 3664
- POJ 3664
- Poj 2371--Questions and answers(QSort)
- POJ 3664 Election Time 再想想
- poj 3664 Election Time
- (Relax ST1.22)POJ 3664 Election Time(两次排序的巧妙应用)
- poj 1328 贪心+qsort
- poj 2075 lightblueme double qsort cmp函数的写法
- 【poj解题】3664