URAL 1639 Chocolate 2 (博弈论)

1639. Chocolate 2

Time limit: 1.0 second

Memory limit: 64 MB

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 in m rows and n columns 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 integers m and n (1 ≤ mn ≤ 50).

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]=:]

题意:有划了n*m条线的巧克力,两人轮流沿线对折,第一个不能对折的那个人为输。

解析:简单博弈论。

AC代码:

#include <cstdio>

int main(){
    int n, m;
    while(scanf("%d%d", &n, &m)==2){
        if(n * m & 1) puts("[second]=:]");
        else puts("[:=[first]");
    }
    return 0;
}
时间: 2024-10-18 09:51:49

URAL 1639 Chocolate 2 (博弈论)的相关文章

ural 1058 chocolate

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1058 Description Fishburg confectionery factory produces convex polygon-shaped chocolates. Little Boy and Karlsson bought one and wanted to break

URAL 1924 Four Imps (博弈论 + 规律)

1924. Four Imps Time limit: 1.0 second Memory limit: 64 MB The world is in danger. One famous swindler passed away recently (by the way, nobody knows his real name, so let's call him Ostap). Having got to the hell he decided to make a deal with the D

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums ar

codeforces 598E E. Chocolate Bar(区间dp)

题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you ma

hdu 1536 S-Nim 博弈论,,求出SG&#39;函数就可以解决

S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4975    Accepted Submission(s): 2141 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now

1639: [Usaco2007 Mar]Monthly Expense 月度开支

1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 593  Solved: 295[Submit][Status] Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N<=100,000)个工作日中每一天的花费moneyi(1<=money

Ural 1081 Binary Lexicographic Sequence(DP)

题目地址:Ural 1081 先用dp求出每个长度下的合法序列(开头为1)的个数.然后求前缀和.会发现正好是一个斐波那契数列.然后每次判断是否大于此时长度下的最少个数,若大于,说明这一位肯定是1,若小于,则肯定是0.就这样不断输出出来即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #in

URAL 1684. Jack&#39;s Last Word KMP

题目来源:URAL 1684. Jack's Last Word 题意:输入a b 把b分成若干段 每一段都是a的前缀 思路:b为主串 然后用a匹配b 记录到b的i位置最大匹配的长度 然后分割 分割的时候要从后往前 如果a = abac b = abab 那么如果从前往后 首先覆盖了aba 然后b就不能覆盖了 从后往前就可以了 首先覆盖ab 下一次还是ab 因为已经记录了到i位置的最大匹配长度 根据长度从末尾倒退 每次倒退的时候只要是最大的匹配的长度 因为如果在某一次的递推 记录的最大匹配的前缀

[BZOJ] 1639: [Usaco2007 Mar]Monthly Expense 月度开支

1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1077  Solved: 533[Submit][Status][Discuss] Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N<=100,000)个工作日中每一天的花费moneyi(1