当前位置:网站首页>PAT B1053

PAT B1053

2022-06-25 19:55:00 Madness makes freedom

1053 Housing vacancy rate (20 branch )

Without disturbing the residents , One way to calculate the housing vacancy rate is to judge according to the continuous change of electricity consumption of each household . The judgment method is as follows :

  • During the observation period , If more than half of the daily electricity consumption is below a given threshold e, Then the house is “ May be vacant ”;

  • If the observation period exceeds a given threshold D God , And satisfy the previous condition , Then the house is “ The vacancy ”.

The household electricity consumption data of a residential area is given , Please make statistics “ May be vacant ” Ratio and “ The vacancy ” ratio , That is, the percentage of houses in the above two states in the total number of houses in residential areas .

Input format :

Enter the first line to give a positive integer N(≤1000), Is the total number of housing units in the residential area ; A positive real number e, Low battery threshold ; Positive integer D, That is, the observation period threshold . And then N That's ok , Each row gives the electricity consumption data of a house in the following format :

K E1​ E2​ ... EK​

among K Is the number of days observed ,Ei​ For the first time i Days of electricity consumption .

Output format :

Output in one line “ May be vacant ” Ratio and “ The vacancy ” Percentage of the ratio , Separated by a space , After decimal point 1 position .

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 explanation : The first 2、3 Households as “ May be vacant ”, The first 4 Households as “ The vacancy ”, Other households are not vacant .)

Next time anyway , You must see the title clearly , Understand the meaning of each data representation to write code !!!!

If the observation period exceeds a given threshold D God , And satisfy the previous condition , Then the house is “ The vacancy ”.

The electricity level during the observation period is lower than e The number of consecutive days exceeded d;( It's a bit of a detour , That's true , But I know I made myself clear !!!


#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int n,d;
    double e;
    cin >> n >> e >> d;
    int may=0,fact=0;
    for(int j=0;j<n;++j)
    {
        int days;
        cin >> days;
        int sum=0;//series: continuity , series 

        for(int i=0;i<days;++i)
        {
            double use;
            cin >> use;
            if(use<e)
            {
                ++sum;
            }
        }

        if(sum>days/2)
        {
            if(days>d)
                ++fact;
            else
                ++may;
        }
    }
    double may_=(may*100.0)/n,fact_=(fact*100.0)/n;
    printf("%.1f%% %.1f%%\n",may_,fact_);
    return 0;
}

原网站

版权声明
本文为[Madness makes freedom]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190512261737.html