码农知识堂 - 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的和。 

  • 相关阅读:
    element 搜索框静态查询
    导数基础:概念与运算
    Windows——关于service
    PCB工艺规范及PCB设计安规原则
    SAAS堡垒机安全吗?为什么性价比那么高?
    实用 | 盘点抓包修改响应结果的 2 种方式
    剑指 Offer 33. 二叉搜索树的后序遍历序列
    前端框架-echarts
    第三章 链路层
    小白操作Win10扩充C盘(把D盘内存分给C盘)亲测多次有效
  • 原文地址:https://blog.csdn.net/QZZ_PP/article/details/125631895
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号