在不打擾居民的前提下,統計住房空置率的一種方法是根據每戶用電量的連續變化規律進行判斷。判斷方法如下:
- 在觀察期內,若存在超過一半的日子用電量低於某給定的閾值e,則該住房爲“可能空置”;
- 若觀察期超過某給定閾值D天,且滿足上一個條件,則該住房爲“空置”。
現給定某居民區的住戶用電量數據,請你統計“可能空置”的比率和“空置”比率,即以上兩種狀態的住房佔居民區住房總套數的百分比。
輸入格式:
輸入第一行給出正整數N(<=1000),爲居民區住房總套數;正實數e,即低電量閾值;正整數D,即觀察期閾值。隨後N行,每行按以下格式給出一套住房的用電量數據:
K E1 E2 ... EK
其中K爲觀察的天數,Ei爲第i天的用電量。
輸出格式:
在一行中輸出“可能空置”的比率和“空置”比率的百分比值,其間以一個空格分隔,保留小數點後1位。
輸入樣例: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
輸出樣例:
40.0% 20.0%
(樣例解釋:第2、3戶爲“可能空置”,第4戶爲“空置”,其他戶不是空置。)
==================================================================
沒什麼特別的,按照題目意思做即可。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
int main()
{
int d,k,i,j;
double n,e,temp1,temp2,may=0,kong=0;
cin>>n>>e>>d;
for(j=0;j<n;j++)
{
cin>>k;
temp2 = 0;
for(i=0;i<k;i++)
{
cin>>temp1;
if(temp1 < e)
temp2++;
}
if(temp2 > k/2)
{
if(k > d)
kong++;
else
may++;
}
}
cout<<fixed<<setprecision(1)<<100*may/n<<"% "<<fixed<<setprecision(1)<<100*kong/n<<"%"<<endl;
return 0;
}