住房空置率

题源

PTA 乙级

题解

这个题的坑在于“空置”统计.
题目中描述如下:

若存在超过一半的日子用电量低于某给定的阈值 e观察期超过某给定阈值 D 天满足上述两点位“空置”。

意思是观察的日子足够长,加上有一半低于阈值即可;而非观察日里低于阈值天数超过D天。
如果不注意这两点,测试点1 测试点2无法通过。

#include<stdio.h>
int N,D,n;
float e,num;
int count = 0,may = 0,real = 0;
int main(){
    scanf("%d %f %d",&N,&e,&D);
    for(int i = 0;i < N;i++){
        scanf("%d",&n);
        count = 0;
        for(int j = 0;j < n;j++){
            scanf("%f",&num);
            if(num < e) count++;
        }
        if(n > D && count > n/2)real++;
        else if(count > n/2)may++;
    }
    char c = '%';
    printf("%.1f%c %.1f%c",100.0*may/N,c,100.0*real/N,c);
    getchar();getchar();
    return 0;
}
posted @ 2021-04-28 13:13  summeriver13  阅读(23)  评论(0)    收藏  举报