PAT Basic 1053 the housing vacancy rate (20 points)

Without disturb residents, a method of statistical housing vacancy rate is judged by a continuous variation of electricity according to household. Determined as follows:

  • During the observation period, if there is more than half of the day electricity is below a given threshold value  E, the housing is "vacant";

  • When the observation period exceeds a given threshold value  D days, and on a condition satisfied, the housing is "empty."

Now given a residential area of ​​household electricity consumption data, you statistics "vacant" ratios and "vacancy" rate, housing that is more than two states as a percentage of total units of residential housing.

Input formats:

Input of the first row is given a positive integer  N ( ≤), total units of residential housing; positive real number  to e, the low battery threshold; positive integer  D, the observation period threshold. Then  N rows, each housing a given power consumption data in the following format:

E 1 E 2 ...  E K

Where  K is the number of days of observation, E i for the first  day i consumption.

Output formats:

The percentage ratio of the output values ​​in a row "vacant" and "empty" ratio, with a space therebetween, a retained after the decimal point.

Sample input:

5 0.5 10
6 0.3 0.4 0.5 0.2 0.8 0.6
10 0.0 0.1 0.2 0.3 0.0 0.8 0.6 0.7 0.0 0.5
5 0.4 0.3 0.5 0.1 0.7
11 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
11 2 2 2 1 1 0.1 1 0.1 0.1 0.1 0.1

Sample output:

40.0% 20.0%

(Sample explained: the second and third family is "vacant", the first four as "vacant", other users are not empty.)

 

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int N,D;double e,tmp;
    scanf("%d %lf %d",&N,&e,&D);
    int pro_emp=0,emp=0;
    for(int i=0;i<N;i++){
        int num,empty_num=0;
        scanf("%d",&num);
        for(int j=0;j<num;j++){
            scanf("%lf",&tmp);
            if(tmp<e) empty_num++;
        }
        if(empty_num>num/2){
            num>D?emp++:pro_emp++;
        }
    }
    printf("%.1f%% %.1f%%",(pro_emp*1.0/N)*100,(emp*1.0/N)*100);
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11707868.html