1053. 住房空置率 (20)

原题: https://www.patest.cn/contests/pat-b-practise/1053

思路: 这题完全是文字游戏呀, 一开始卡在文字理解上, 只得12分.
加入阈值是20天, 调查了100天. 有40天是低电量状态, 那么该套房
仍然是可能空, 而不是一定空. 必须是先确定低电量的天数先大于调查
天数的一半, 然后再看调查的天数是不是大于阈值.

实现:

#include <stdio.h>

int main (void) {
    int total;
    double lowPower;
    int day;
    int halfDay;
    int realDay;
    int maybeEmpty = 0;
    int mustEmpty = 0;
    int empty;
    double temp;
    int i;
    int j;

    scanf("%d %lf %d", &total, &lowPower, &day);
    for (i = 1; i <= total; i++) {
        scanf("%d", &realDay);
        empty = 0;
        halfDay = realDay / 2;
        for (j = 1; j <= realDay; j++) {
            scanf("%lf", &temp);
            if (temp < lowPower) {
                empty++;
            }
        }
        if (empty > halfDay) {
            if (realDay > day) {
                mustEmpty++;
            } else {
                maybeEmpty++;
            }
        }
    }
    double maybe = (double)(maybeEmpty) / total * 100.0;
    double must = (double)(mustEmpty) / total * 100.0; 
    printf("%.1f%% %.1f%%", maybe, must);

    return 0;
}

参考: http://www.jianshu.com/p/ff2c53cb75cb

原文地址:https://www.cnblogs.com/asheng2016/p/7873694.html