PAT B -1053 housing vacancy rate (20 points)

Click on the link full solution summary PAT B -AC

Title:
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 format:
input of the first row is given a positive integer N (≤1000), 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:

KE 1, E 2 ... E the K

​​

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

Output format:
output line "vacant" ratios and "empty" the percentage value of the ratio, with a space therebetween, Reserved 1 decimal place.

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.)

My code:

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件

int main()
{
    double N,e,D;
    cin>>N>>e>>D;
    int num_maybe=0,num_is=0;
    for(int i=0;i<N;i++)
    {
        int K,sum=0;
        cin>>K;
        for(int j=0;j<K;j++)
        {
            double t;
            cin>>t;
            if(t<e)sum++;
        }
        if(sum>K/2&&K>D)num_is++;
        else if(sum>K/2)num_maybe++;
    }
    double res_maybe=100.0*num_maybe/N;
    double res_is=100.0*num_is/N;
    printf("%2.1f%% %2.1f%%",res_maybe,res_is);

    return 0;
}

Published 82 original articles · won praise 1 · views 1682

Guess you like

Origin blog.csdn.net/qq_34451909/article/details/104841585