题意:
有一个巧克力由很多小方块组成,每次掰开一半,最后一次没巧克力掰的人算输(所有巧克力都被掰开成一个最小的方块了)。
Little Boy is mad at Karlsson, who ate all the sweets in the flat and even went to the neighbours to eat their sweets too. Now Little Boy's parents brought home a chocolate bar, and, sure enough, Karlsson
is here already and wants to eat it. However, this time Little Boy has firmly decided that not a single piece of chocolate will go to this glutton. Little Boy wants to use Karlsson's addiction to the games of chance and suggests playing the following game.
A chocolate bar can be considered as a rectangle of square “units” arranged inmrows andncolumns and separated by “lines”. Two players take alternate turns. At his turn, a player must take one piece of chocolate and split it into two along
one of the lines. If a player can't make a legal move (which happens when all pieces of chocolate consist of a single unit square), he loses, and the winner takes all the chocolate.
But Karlsson is smart enough! He immediately understood who should make the first turn in order for Karlsson to win, assuming that players take optimal turns. Can you guess that?
Input
The only line of the input contains space-separated integersmandn<nobr>(1 ≤<em>m</em>,<em>n</em>≤ 50)</nobr>.
Output
If Karlsson should start the game in order to win, output “[:=[first]”; otherwise, output “[second]=:]”.
Samples
input
output
2 4
|
[:=[first]
|
1 3
|
[second]=:]
|
这里使用减治法,时间效率就是O(lg(min(m,n)),min(m,n)是指行和列最小的值,因为下面程序特殊处理了一下:
//认真注意几处计算的地方
int chocolateDivisor(int m, int n)
{
if (m <= 1) return n-1;
int sum = chocolateDivisor(m>>1, n);
sum <<= 1;
if (m % 2) sum += n;
return sum+1;
}
void Chocolate2()
{
int m, n;
cin>>m>>n;
if (m > n) swap(m, n);
if (chocolateDivisor(m, n) % 2) cout<<"[:=[first]";
else cout<<"[second]=:]";
}
分享到:
相关推荐
资源分类:Python库 所属语言:Python 资源全名:timus-sender-0.1.1.post1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
acm.timus.ru 1709 problem
Timus ... Problems code. (Mainly Java implementation) Chinese 刷题代码,主要是java实现,可能会有其他语言代码 代码来自LeetCode / NowCoder / timus 等 site url LeetCode NowCoder Timus LeetCode-cn
acm.timus.ru最全代码
Timus图表 将图表添加到Timus Online Judge个人资料中 特征 概要文件中和比较期间已解决问题的计数图表 向图表添加更多用户,删除它们,自定义图例颜色 缓存配置文件数据 隐藏图表 (可选)突出显示最近两个月内接受...
acm.timus.ru解决方案 这些是我对ACM.TIMUS.RU问题的解决方案
timus-online-judge Timus Online Judge 是俄罗斯最大的带有自动评判系统的编程问题档案。 问题主要是从在乌拉尔联邦大学、乌拉尔锦标赛、乌拉尔 ACM ICPC 次区域比赛和彼得罗扎沃茨克训练营举办的比赛中收集的。 ...
将图表添加到Timus Online Judge配置文件 该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。 功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除它们,自定义...
timus.ru_solutions 使用的语言:Python 使用的Python版本:3.9 我可以用Python语言解决的一些问题在“ python”目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 不知道为什么我...
语言:English将图表添加到Timus Online Judge个人资料中该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除...
Timus上习题解答与代码参考,这一部分对应于Timus上的Beginner部分的习题
NYTD在线法官-omegaUp-熊猫在线法官-PEG法官-POJ-QDUOJ-SPOJ-Timus-Toph-URI在线法官-USACO-USACO培训-UVa在线法官-虚拟法官-Yandex竞赛解析器可用于以下网站:-AtCoder-百joon在线法官-CodeChef-Codeforces-COJ-CSU...
Timus Testcases- 1002 Phone numbers
timus.ru_solutions_python 使用的python:3.9 我可以用Python语言解决的一些问题在python目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 我不知道为什么
timus:Timus在线法官问题
timus OJ 1197 lonesome kinght
蒂莫斯 该文件夹包含用Python编写的文件(主要是Python2.7,有些是Python3.4)我通过这些文件在timus上通过了相应的测试。
首先,确保已安装libxml2和libxslt的开发包 假设您正在运行基于Debian的发行版,则可以使用以下方法安装它们: apt-get install python-dev libxml2-dev libxslt1-dev zlib1g-dev 通过运行以下命令安装所需的...
http://acm.timus.ru 俄罗斯乌拉尔大学在线题库 SGU http://acm.sgu.ru/ 俄罗斯圣萨拉托夫州大学在线题库 ELJ http://acm.mipt.ru/judge/bin/problems.pl?lang=en file:///M|/acm/ACM大量习题题库及建议培养计划.txt...
Pascal acm_timus_ural_1148.pas