• CF 1899A 学习笔记


    A. Game with Integers

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Vanya and Vova are playing a game. Players are given an integer 𝑛�. On their turn, the player can add 11 to the current integer or subtract 11. The players take turns; Vanya starts. If after Vanya's move the integer is divisible by 33, then he wins. If 1010 moves have passed and Vanya has not won, then Vova wins.

    Write a program that, based on the integer 𝑛�, determines who will win if both players play optimally.

    Input

    The first line contains the integer 𝑡� (1≤𝑡≤1001≤�≤100) — the number of test cases.

    The single line of each test case contains the integer 𝑛� (1≤𝑛≤10001≤�≤1000).

    Output

    For each test case, print "First" without quotes if Vanya wins, and "Second" without quotes if Vova wins.

    Example

    input

    Copy

     
    

    6

    1

    3

    5

    100

    999

    1000

    output

    Copy

    First
    Second
    First
    First
    Second
    First
    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. int n;
    6. scanf("%d",&n);
    7. while(n--)
    8. {
    9. int num;
    10. scanf("%d",&num);
    11. bool flag=false;
    12. if((num+1)%3==0||(num-1)%3==0) flag=true;
    13. if(flag==true) printf("First\n");
    14. else printf("Second\n");
    15. }
    16. return 0;
    17. }

    题目的意思是说给定一个数字,有两个参赛者,a和b,每个参赛者轮流对该数字进行操作,每一次操作可以加一或者减一,假设a操作之后该数字可以被3整除,就输出First,十次操作之后还不能被3整除就输出Second。

    假设该数字原本可以被3整除,经过一次加一或者减一的操作就一定不可以被3整除,假设a进行加一的操作,b进行加一的操作,原本数字可以被3整除,增加2是不可以被3整除的,此时a再增加一,该数字就可以被3整除了,所以说a增加一,b就一定要减小一,每一次b都使用与a相反的操作,就可以保证a一定无法获得胜利。

    假设该数字不可以被3整除,是什么情况呢?该数字不可以被3整除,那么该数字对3取余的结果是1或2,假设该数字对3取余的结果是1,那么a把该数字减小1就可以使得该数字可以被3整除,a获得胜利,假设该数字对3取余的结果是2,a把该数字增加1就可以使得该数字可以被3整除,a获得胜利。

    综上所述,只需要判断给定的数字能否被3整除即可,可以被3整除就输出Second,不可以被3整除就输出First

     

    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. int t;
    6. scanf("%d",&t);
    7. while(t--)
    8. {
    9. int n;
    10. scanf("%d",&n);
    11. if(n%3==0) printf("Second\n");
    12. else printf("First\n");
    13. }
    14. return 0;
    15. }

    第一份代码是赛时写的,第二份代码明显思路更加清晰

    1. #include
    2. using namespace std;
    3. void solve() {
    4. int n;
    5. cin >> n;
    6. if (n % 3) {
    7. cout << "First\n";
    8. } else {
    9. cout << "Second\n";
    10. }
    11. }
    12. int main() {
    13. int t;
    14. cin >> t;
    15. while (t--) {
    16. solve();
    17. }
    18. }

    第三份代码是官方题解,非常简洁明了 

     

     

  • 相关阅读:
    系列十三、Redis的哨兵机制
    电商项目接口测试实践-postman
    专用神经网络处理器芯片,神经网络芯片的单片机
    大厂密集背后,折叠屏市场“暗战”已起
    Java学习之继承的本质(重要)
    Neo4j-APOC扩展与使用
    整数和字符串比较的坑
    基于长短期记忆神经网络的锂电池寿命预测
    Linux Kernel入门到精通系列讲解(RV-Kernel 篇) 5.5 RTC设备编写与实现
    017-JAVA重载及实例讲解
  • 原文地址:https://blog.csdn.net/L3102250566/article/details/134475965