题目地址:http://lightoj.com/volume_showproblem.php?problem=1234
数据到10^8,刚好可以循一轮,那么我们就用预处理的思想(但是不保存),一次性把答案处理出来然后再去输出。
之前忘记考虑重复了WA了一发。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct num
{
int quest;
int place;
}p[10010];
double ans[10010];
bool cmp(num a,num b)
{
return a.quest<b.quest;
}
int main()
{
int T;
scanf("%d",&T);
for(int i=0;i<T;i++)
{
scanf("%d",&p[i].quest);
p[i].place=i;
}
sort(p,p+T,cmp);
double now=0;
int cont=0;
for(int i=1;i<=100000000;i++)
{
if(cont>=T) break;
now+=1.0/i;
while(p[cont].quest==i)
{
ans[p[cont++].place]=now;
}
}
for(int i=0;i<T;i++)
{
printf("Case %d: %.10lf\n",i+1,ans[i]);
}
return 0;
}
/*
12
1
2
3
4
5
6
7
8
9
90000000
99999999
100000000
*/