【poj解题】3663

排序,

遍历,需要裁减

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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;
}

  

【poj解题】3663

上一篇:Auto push git tag


下一篇:循环队列