码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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

     

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. int main()
    4. {
    5. int n;
    6. scanf("%d",&n);
    7. double ans=0;
    8. for(int i=1;i<=n;i++)
    9. {
    10. ans=ans+i*1.0*(i-1)/n;
    11. }
    12. printf("%.6lf",ans);
    13. return 0;
    14. }

     题解:

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

  • 相关阅读:
    [踩坑]特征值计算
    PyTorch搭建卷积神经网络(CNN)进行视频行为识别(附源码和数据集)
    SpringCloud微服务第2章
    技术对接46
    “蔚来杯“2022牛客暑期多校训练营(加赛) D题: Directions
    如何搬运视频赚钱?
    哪里有便宜的云服务器?可以下月付款吗?
    微服务与单体应用有什么区别?
    python基于PHP+MySQL的在线汽车租赁管理系统
    安装elasticsearch
  • 原文地址:https://blog.csdn.net/QZZ_PP/article/details/125631895
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号