C. MaratonIME plays Nim

time limit per test : 2.0 s
memory limit per test : 64 MB
inputstandard input
outputstandard output
Ai Fox!
UNIONFIND, GERMANO
You open your eyes, but everything remains dark. The world is dark, and everything shakes. You realize you are locked in, but before desperation takes hold, you hear the door opening and the light invades your sight and blinds you for a few moments.

They help you out, you had been locked inside a trunk. You don't know the masked faces before you, but remember that in the last competitive programming practice they told you that "the beginning is yet to come". "So this is the fabled MaratonIME's initiation challenge", you had heard rumors of this event, and you feel honored to be chosen.

After walking into and abandoned building, they sit you on an old chair. The first test is to watch a soccer game without any show of excitement. Easy. The second is to install Linux on a notebook in less than 5 minutes. You were prepared, carrying the Arch Linux pendrive as usual, just in case. You face more tests, and manage to pass all of them despite a few difficulties.

Hours go by, the members remove their masks, and each take a coin out of their pocket. "I won! And I even got rich" you think, but realize they place the coins in a table in front of you, divided in two piles. Renzo, MaratonIME's great boss, takes a chair and sits in front of you. You will play a match of Nim, and if you win you will become an honorary member of MaratonIME, that is, you win a balloon.

Nim is a game of two players, alternating their turns. Two piles of coins are placed on a table and in each turn you can remove any non zero quantity of coins from one of the piles. The last player to take their turn (leaving both piles empty) wins.

You start the game. So it would not be unfair, it is guaranteed that it is possible for you to win. Write a program than beats Renzo 100% of the time.

Input

In the first line, two integers, x and y, the size of the piles, such that 0 ≤ x, y ≤ 104. It is guaranteed that you can win the game.

Interaction

In your turn, print two integers, i and x, where i is the number of the pile from which you will remove the coins (), and x is the number of coins you will remove (x ≥ 1, such that i has at least x coins).

In Renzo's turn, read two integers, in the same format as in your turn.

Example

input

2 1
1 1

output

1 1
2 1

Note
Of course we do not do an initiation challenge like this :P

In the example, we have a pile with 2 coins and another with 1. You remove 1 coin from the first pile, and now no matter what coin Renzo removes, you can remove the other and win.

Remember, after printing your play, flush the output, like: fflush(stdout); in C, cout.flush(); in C++, or sys.stdout.flush() in Python.

题意

A和B进行nim博弈,A先手,并且当前局势A是必胜的,怎么拿可以保证结果是A必胜的

Input的第一行是原本两堆的石子数,接下来有若干行,每行第一个数字是B取第一堆或第二堆,第二个数字是取的个数

output输出每次A拿石子的方案,第一个数代表拿第几堆,第二个数是拿走的个数

思路

每次A取完石子后,保证剩下的两堆石子数目相同就可以保证B必败

代码

 1 #include <bits/stdc++.h>
2 #define ll long long
3 #define ull unsigned long long
4 #define ms(a,b) memset(a,b,sizeof(a))
5 const int inf=0x3f3f3f3f;
6 const ll INF=0x3f3f3f3f3f3f3f3f;
7 const int maxn=1e6+10;
8 const int mod=1e9+7;
9 const int maxm=1e3+10;
10 using namespace std;
11 int main(int argc, char const *argv[])
12 {
13 ios::sync_with_stdio(false);
14 cin.tie(0);
15 int x,y,i,n;
16 cin>>x>>y;
17 if(x==0)
18 cout<<2<<" "<<y<<endl;
19 else if(y==0)
20 cout<<1<<" "<<x<<endl;
21 else
22 {
23 if(x>y)
24 cout<<1<<" "<<x-y<<endl;
25 else if(x<y)
26 cout<<2<<" "<<y-x<<endl;
27 while(cin>>i>>n)
28 {
29 if(i==1)
30 cout<<2<<" "<<n<<endl;
31 else if(i==2)
32 cout<<1<<" "<<n<<endl;
33 }
34 }
35 return 0;
36 }

Codeforces Gym-100985C: MaratonIME plays Nim(交互题&博弈)的更多相关文章

  1. Gym - 101375H MaratonIME gets candies 交互题

    交互题介绍:https://loj.ac/problem/6 题意:输出Q X ,读入><= 来猜数,小于50步猜出就算过样例 题解:根本不需要每次输出要打cout.flush()... ...

  2. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  3. Codeforces Gym 100269A Arrangement of Contest 水题

    Problem A. Arrangement of Contest 题目连接: http://codeforces.com/gym/100269/attachments Description Lit ...

  4. Codeforces Gym 100463B Music Mess Hash 逻辑题

    Music Mess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments ...

  5. codeforces Gym 100187H H. Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  6. codeforces Gym 100500H H. ICPC Quest 水题

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  7. Vladik and Favorite Game CodeForces - 811D (思维+BFS+模拟+交互题)

    D. Vladik and Favorite Game time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. Codeforces Gym 100513F F. Ilya Muromets 水题

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  9. 交互题[CF1103B Game with modulo、CF1019B The hat、CF896B Ithea Plays With Chtholly]

    交互题就是程序与电脑代码的交互. 比如没有主函数的程序,而spj则给你一段主函,就变成了一个整体函数. 还有一种就是程序和spj之间有互动,这个用到fflush(stdout);这个函数就可以实现交互 ...

随机推荐

  1. 前端1 — HTML — 更新完毕

    1.首先来了解一个东西 -- W3C标准( 全称是:World Wide Web Consortium ) 万维网联盟(外语缩写:W3C)标准不是某一个标准,而是一系列标准的集合 -- 这个其实每天都 ...

  2. 假期对html,css,前端的再学习

    1.观看了相关教学视频40分钟. 2.学习内容: 一 HTML 介绍 1. 什么是 HTML? 超文本标记语言: 超文本:比普通文本功能更加强大 标记语言:使用一组标签对内容进行描述的一门语言,它不是 ...

  3. 运算符重载+日期类Date

    Hello,一只爱学习的鱼 大学学习C++运算符重载的时候,老师出了一道"运算符重载+类"的综合练习题,让我们来一起看看吧! 题目: 设计一个日期类Date,包括年.月.日等私有成 ...

  4. 大数据学习day28-----hive03------1. null值处理,子串,拼接,类型转换 2.行转列,列转行 3. 窗口函数(over,lead,lag等函数) 4.rank(行号函数)5. json解析函数 6.jdbc连接hive,企业级调优

    1. null值处理,子串,拼接,类型转换 (1) 空字段赋值(null值处理) 当表中的某个字段为null时,比如奖金,当你要统计一个人的总工资时,字段为null的值就无法处理,这个时候就可以使用N ...

  5. nodeJs-querystring 模块

    JavaScript 标准参考教程(alpha) 草稿二:Node.js querystring 模块 GitHub TOP querystring 模块 来自<JavaScript 标准参考教 ...

  6. java静态方法调用非静态方法

    我们都知道,静态static方法中不能调用非静态non-static方法,准确地说是不能直接调用non-static方法.但是可以通过将一个对象的引用传入static方法中,再去调用该对象的non-s ...

  7. tomcat 之 session服务器 (memcache)

    #: 在tomcat各节点安装memcached [root@node1 ~]# yum install memcached -y #: 下载tomcat所需的jar包(此处在视频中找软件) [roo ...

  8. hive 启动不成功,报错:hive 启动报 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/mapred/MRVersi

    1. 现象:在任意位置输入 hive,准备启动 hive 时,报错: Exception in thread "main" java.lang.NoClassDefFoundErr ...

  9. canal安装与使用

    安装 alpha的版本不是稳定的版本 wget https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deploye ...

  10. Turbine使用

    一.简介 Turbine是聚合服务器发送事件流数据的一个工具,Hystrix的监控中,只能监控单个节点,实际生产中都为集群,因此可以通过Turbine来监控集群下Hystrix的metrics情况 T ...