【poj解题】3663
排序,
遍历,需要裁减
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 20000 int cows[MAX]; int N; int L; int cmp(const void * a, const void * b) { return *(int *)a - *(int *)b; } int main() { int i; int j, k; int count; count = 0; scanf("%d%d", &N, &L); for(i = 0; i < N; i++) { scanf("%d", &cows[i]); } qsort(cows, N, sizeof(cows[0]), cmp); for(j = 0; j < N; j++) { if(cows[j] > L) { break; } for(k = j + 1; k < N; k++) { if(cows[k] > L) { break; } if(cows[j] + cows[k] <= L) { count ++; } else { break; } } } printf("%d\n", count); return 0; }
喜欢一起简单,实用的东西,拒绝复杂花哨,我不是GEEK.