B. JOE is on TV!-----思维/水

Our dear Cafe’s owner, JOE Miller, will soon take part in a new game TV-show “1 vs. n”!

The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The show ends when only JOE remains (we assume that JOE never answers a question wrong!).

For each question JOE answers, if there are s (s>0) opponents remaining and t (0≤t≤s) of them make a mistake on it, JOE receives ts dollars, and consequently there will be s−t opponents left for the next question.

JOE wonders what is the maximum possible reward he can receive in the best possible scenario. Yet he has little time before show starts, so can you help him answering it instead?

Input
The first and single line contains a single integer n (1≤n≤105), denoting the number of JOE’s opponents in the show.

Output
Print a number denoting the maximum prize (in dollars) JOE could have.

Your answer will be considered correct if it’s absolute or relative error won’t exceed 10−4. In other words, if your answer is a and the jury answer is b, then it must hold that |a−b|max(1,b)≤10−4.

Examples
inputCopy

1
outputCopy
1.000000000000
inputCopy
2
outputCopy
1.500000000000
Note
In the second example, the best scenario would be: one contestant fails at the first question, the other fails at the next one. The total reward will be 12+11=1.5 dollars.

题意:有t个人是你的对手,有s个回答错误的。每一轮得到的奖励为 s/t.给你一个n问你最大获得的奖励为多少???

解析:1/n+1/(n-1)+…+1/1 即答案最优


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1000;
double sum;
int n; 
int main()
{
	scanf("%d",&n);
	sum=0.0;
	for(int  i=1;i<=n;i++)
	{
		sum=sum+((1.0)/(i*1.0));
	}
	printf("%.12lf\n",sum);
} 


发布了309 篇原创文章 · 获赞 6 · 访问量 5270

猜你喜欢

转载自blog.csdn.net/qq_43690454/article/details/104071209