G - Card Game

G - Card Gameicon-default.png?t=M5H6https://vjudge.csgrandeur.cn/problem/Gym-102263G

Zeyad and Ehab are playing a simple card game, each player initially has a deck of nn cards numbered from 11 to nn, the game lasts nn turns and in each turn both players privately choose one card and then both players reveal the chosen cards, the player that chose the card with the higher number earns points equal to that number, for example if Ehab chooses 44 and Zeyad chooses 66 Zeyad earns 66 points, if the numbers chosen are equal no one earns any point, the cards chosen do not return to the deck, they are discarded instead.

Ehab doesn't care about winning or losing, he cares about mathematical values of the game, specifically he wants to know the expected number of points he'll earn considering all possible outcomes, can you help him?

Input

The first and only line of input contains a single integer n(1 \leq n \leq 10^6)n(1≤n≤106).

Output

Print a real number, the expected number of points Ehab will earn in the game.

The answer is considered correct if the absolute or relative error is not greater than 10^{-6}10−6.

Sample 1

InputcopyOutputcopy
3
2.6666666667

Sample 2

InputcopyOutputcopy
7
16.0000000000

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    double ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=ans+i*1.0*(i-1)/n;
    }
    printf("%.6lf",ans);
    return 0;
}

 题解:

就是算数学期望,对于选择的i,只有对手选择1~i-1时才能得分,所以期望是对于所有i,i*(i-1)/n的和。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值