ETH官方钱包

前往
大廳
主題

[OJ練習] 591、11799

テリ君(桃夫模式) | 2022-12-01 13:09:05 | 巴幣 0 | 人氣 119

GitHub
591(1/5)

#include <stdio.h>

int main(){
    int p, n[51];
    int sum = 0, mean = 0;
    int move = 0;
    int set = 0;
    
    while(scanf("%d", &p) != EOF){
        if(p == 0) break;
        set ++;
        for(int i = 0; i < p; i++){
            scanf("%d", &n[i]);
        }
        for(int i = 0; i < p; i++){
            sum += n[i];
        }
        mean = sum / p;
        for(int i = 0; i < p; i++){
            if(n[i] < mean){
                move += mean - n[i];
            }
            else if(n[i] > mean){
                move += n[i] - mean;
            }
        }
        
        printf("Set #%d\nThe minimum number of moves is %d.\n", set, move / 2);
    }

    return 0;
}

11799(1/5)

#include <stdio.h>


int main(){
    int c, s[10000], t; // c for case, s for speed
    int max;
    
    scanf("%d", &c);
    for(int i = 0; i < c; i++){
        scanf("%d", &t);
        
        for(int j = 0; j < t; j++){
            scanf("%d", &s[j]);
        }
        
        for(int j = 0; j < t; j++){
            if(max < s[j]) max = s[j];
        }
        
        printf("Case %d: %d\n", i + 1, max);
        max = 0;
    }
}


都不難,就當基礎練習ㄅ
不過有些想法是練很多這些東西是增進基礎
但有些進階的用法484一百題後才有辦法學到呢
就先把一百題先練完吧

創(chuàng)作回應

更多創(chuàng)作