zoukankan      html  css  js  c++  java
  • codeforces Epic Game 题解

    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 nstones. 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 ab and n who wins the game.

    Input

    The only string contains space-separated integers ab 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 test(s)
    input
    3 5 9
    
    output
    0
    input
    1 1 100
    
    output
    1

    这种题目一般都能够找公式的,可是本题却是找不到什么好的公式了。

    仅仅有暴力去模拟玩这个游戏了。还好由于其数据不大。故此或许出题者也是没有公式的。


    namespace{
    
    	int GCD(int a, int b)
    	{
    		if (1 == a || b == 1) return 1;
    		while (b)
    		{
    			int t = b;
    			b = a%b;
    			a = t;
    		}
    		return a;
    	}
    }
    
    void EpicGame()
    {
    	int a, b, c, d;
    	cin>>a>>b>>c;
    	bool goGame = 0;
    	while (c >= 0)
    	{
    		if (goGame) d = GCD(b, c);
    		else d = GCD(a, c);
    		c -= d;
    		goGame = !goGame;
    	}
    	cout<<goGame;
    }





  • 相关阅读:
    springboot 时间戳和 数据库时间相差14个小时
    财富的起源读书笔记1
    高性能mysql读书笔记1
    springboot项目使用 apollo 配置中心
    MongoDB图形化管理工具
    oracle体系结构详解
    三、oracle 体系结构
    用DOS批处理实现FTP自动上传、下载、清理文件
    ORA-01033:ORACLE initialization or shutdown in progress
    从WEB SERVICE 上返回大数据量的DATASET
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6753137.html
Copyright © 2011-2022 走看看