码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • ZCMU--1431: Epic Game(C语言)


    Description

    Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).

    Your task is to determine by the given a, b and n who wins the game.

    Input

    The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.

    Output

    If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).

    Sample Input

    3  5  9
    1  1  100

    Sample Output

    0
    1
    解析:甲乙分别有个数a,b,石头有n个,两个人轮流来,甲每次取gcd(a,n),乙每次取gcd(b,n),如果某人某次取得时候,石头数量不够了,那个人输,我们开个while模拟每次,直到某个人不满足退出即可。
    注意点:求gcd(a(b),n)时候要先判断n>0,n=0得话进行这个函数就会除以0,发生错误。
    1. #include
    2. int gcd(int a,int b){//求最大公约数
    3. int t=1,max,min;
    4. if(a>=b) max=a,min=b;
    5. else max=b,min=a;
    6. while(t){
    7. t=max%min;
    8. max=min;
    9. min=t;
    10. }
    11. return max;
    12. }
    13. int main()
    14. {
    15. int a,b,n,s,f;
    16. while(~scanf("%d%d%d",&a,&b,&n)){
    17. s=1,f=1;//s=1表示Simon赢,0为输,f用来记录当前是谁进行游戏,f=1是Simon,2为Antisimon
    18. while(1){
    19. //当前是Simon操作
    20. if(f==1){
    21. if(n>0&&n>=gcd(a,n)) n-=gcd(a,n),f=2;//石子数量够
    22. else{
    23. s=1;//石子不够,Simon输
    24. break;
    25. }
    26. }else{
    27. //当前是Antisimon操作
    28. if(n>0&&n>=gcd(b,n)) n-=gcd(b,n),f=1;
    29. else{
    30. s=0;//石子不够,Antisimon输,也就是Simon赢
    31. break;
    32. }
    33. }
    34. }
    35. printf("%d\n",s);
    36. }
    37. return 0;
    38. }

  • 相关阅读:
    器利而工善,以RPA+LCAP赋能企业司库管理数字化升级
    php 安装rabbitmq:如何使用 PHP 安装 RabbitMQ?
    “智”造未来,江西同为科技(TOWE)参展第四届广州“两交会”圆满落幕
    Mac Redis 安装 RedisJSON模块教程
    GBASE 8A v953报错集锦28--使用企业管理器执行 select count(1) into @c from t1;报错
    【03】区块链科普100天-技术研究
    浅谈微服务的发展以及可观测性
    【原创】V2024中化解电力行业设备表的五年难题
    读图数据库实战笔记01_初识图
    7.10飞书一面面经
  • 原文地址:https://blog.csdn.net/qq_63739337/article/details/126458578
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号