G - Card Game Gym - 102263G

Zeyad and Ehab are playing a simple card game, each player initially has a deck of n cards numbered from 1 to n, the game lasts n 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 4 and Zeyad chooses 6 Zeyad earns 6 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≤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.

Examples
Input
3
Output
2.6666666667
Input
7
Output
16.0000000000
题解:首先可以退一下概率公式,假设共7张牌,第一张出手,概率为1/7,其余几张留下的概率为6/7,出手的概率均为1/6,所以第二张出手的概率为6/7 * 1/6 = 1/7,其余的同理,可以发现,不管前方有多少张牌,每张牌的概率就是1/n,所以根据期望=sum(np)得,也就很简单了,下面是AC代码:

#include<cstdio>
#include<cstring>
int main(){
    int n,i;
    scanf("%d",&n);
    double ans=0;
    for(i=1;i<=n;i++)
        ans+=(double)(i-1)*1.0*i/n*1.0;//出i时只有对手出1 - i-1才会赢,所以赢得概率为(i-1)/n;

    printf("%.10lf\n",ans);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IoT是物联网(Internet of Things)的缩写,是指通过物理设备和传感器等技术将物理世界与互联网连接起来的概念。Sensor是传感器的意思,是一种能够感知和测量周围环境参数的装置。Gym master是指健身房的管理系统。那么,"IoT-Sensor-Gym-Master"指的是结合物联网、传感器技术和健身房管理系统的项目或产品。 在这个项目中,通过在健身房内部部署各种类型的传感器设备,可以实时感知和监控健身房的各种环境参数以及用户的行为。例如,可以使用体感传感器来监测用户的运动状态,心率传感器来监测用户心率变化,温湿度传感器来监测环境的温度和湿度等等。这些传感器会把收集到的数据通过物联网技术传输到云端服务器进行处理和分析。 在云端服务器上,会有一个健身房管理系统,通过对接收到的传感器数据进行分析和处理,可以提供各种健身相关的功能和服务。例如,可以根据用户的运动状态自动调整健身器材的强度,提供个性化的健身方案;还可以通过用户心率数据实时预警和监控用户的身体状况,保证用户的健康安全;同时,还可以通过温湿度传感器来实时监测健身房的环境,保证用户的舒适度。 总之,"IoT-Sensor-Gym-Master"项目结合了物联网、传感器技术和健身房管理系统的优势,将智能化和个性化服务引入健身领域,为用户提供更好的健身体验和管理服务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值