Problem A: Hz's treasure chest
Time Limit: 1 Sec Memory Limit: 128 MBCommits: 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
output
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;
}