The treasure chest of Hz

Problem A: Hz's treasure chest

Time Limit: 1 Sec   Memory Limit: 128 MB
Commits: 21   Resolved: 16
[ Commit ][ Status ][ Discussion Board ]

Topic description

Hz has an ancestral treasure chest, and there are n keys left by the old ancestors, but only one key can open the treasure chest. Hz was curious about what was in the box, so he took n keys to open the box. Hz wants to know how many times on average it takes to open the case?

enter

The first line includes an integer T, indicating the number of test data

Enter an integer n per line for the next T lines

output

The average number of times the chest can be opened, with 2 decimal places.

sample input

2
1
2

Sample output

1.00
1.50

hint

Code:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    double s;
    int n,i,t;
    scanf("%d",&t);
    while(t--)
    {
        s=0;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            s=s+i;
        }
        s=s/n;
        printf("%.2lf\n",s);
    }
    return 0;
}

[ commit ] [ status ]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324508125&siteId=291194637