Codeforces 570B Simple Game

本文介绍了一道来自Codeforces的竞赛题目,题目名称为'简单游戏'。作者分享了解题思路,包括如何选择最优策略来增加胜利概率,并特别注意到了n=1的特殊情况。提供了一个简洁的O(1)复杂度的AC代码,帮助读者理解如何通过数学分析和逻辑判断来解决此类问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Simple Game

题目链接:

http://codeforces.com/problemset/problem/570/B

解题思路:

Lets find which variant is interesting. For Andrew is no need a variant wherein |a-m|>1 because we can increase probability of victory if we will be closer to m. Then we consider two variants,a=c-1 and a=c+1. Probability of victory will be (c-1)/n for first variant and (n-c+1)/n for second.

We need to choose better variant, also we must keep in mind case of n=1.

O(1)

比赛的时候忘了考虑n=1的情况,幸好被别人hack了,及时发现了这个问题。。。不然这题的分就全没了。。。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        if(n == 1){
            printf("1\n");
            continue;
        }
        if(n-m > m-1)
            printf("%d\n",m+1);
        else
            printf("%d\n",m-1);
    }
    return 0;
}


### 推荐适合程序员团队建设的游戏活动 #### 1. 编程竞赛 编程竞赛能够激发团队成员的竞争意识和技术平。通过参加在线平台上的编程比赛,如Codeforces、LeetCode或HackerRank,团队可以在限定时间内解决一系列算法问。这类活动不仅能提高编码技巧,还可以培养解决问的能力。 ```python def coding_competition(): participants = ["Alice", "Bob", "Charlie"] problems_solved = {participant: 0 for participant in participants} # Simulate solving some problems during the competition for problem_id in range(5): for p in participants: if random.choice([True, False]): problems_solved[p] += 1 return max(problems_solved.items(), key=lambda item:item[1])[0] winner = coding_competition() print(f"The winner is {winner}!") ``` [^1] #### 2. Escape Room(密室逃脱) Escape room是一种非常适合团队协作的体验,在规定的时间内找到线索并逃离房间。这种游戏鼓励沟通交流、逻辑推理和创造性思维,有助于加强同事间的信任感与默契度。 #### 3. Git Game Git game是一款基于版本控制系统的学习工具,它模拟了一个真实的git仓库环境供玩家练习各种命令操作。参与者们可以通过创建分支、提交更改等方式熟悉git的工作流程,这对于日常工作中频繁使用的源码管理至关重要。 ```bash $ git clone https://github.com/udacity/git-game.git $ cd git-game/ $ python main.py start ``` [^4] #### 4. Code Golf Challenge 在这个游戏中,目标是以尽可能少的字符数实现给定的功能函数。这不仅考验了参赛者的创造力和技术功底,还促进了简洁高效的代码风格养成。 ```javascript // Example of a simple code golf challenge to reverse string s. function rev(s){return [...s].reverse().join('')} console.log(rev("hello")); // Output: olleh ``` [^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值