Problem D. Gift?!
Problem D. Gift?! |
The Problem
There is a beautiful river in a small village. N rocks are arranged in a straight line numbered 1 to N from left bank to the right bank, as shown below.
[Left Bank] - [Rock1] - [Rock2] - [Rock3] - [Rock4] ... [Rock n] - [Right Bank]
The distance between two adjacent rocks is exactly 1 meter, while the distance between the left bank and rock 1 and the distance between Rock n and the right bank are also 1 meter.
Frog Frank was about to cross the river, his neighbor Frog Funny came to him and said,
'Hello, Frank. Happy Children's Day! I have a gift for you. See it? A little parcel on Rock 5.'
'Oh, that's great! Thank you! I'll get it.'
'Wait...This present is for smart frogs only. You can't get it by jumping to it directly.'
'Oh? Then what should I do?'
'Jump more times. Your first jump must be from the left bank to Rock 1, then, jump as many times as you like - no matter forward or backward, but your ith jump must cover 2*i-1 meters. What's more, once you return to the left bank or reach the right bank, the game ends, and no more jumps are allowed.'
'Hmmm, not easy... let me have a think!' Answered Frog Frank, 'Should I give it a try?'
The Input
The input will contain no more than 2000 test cases. Each test case contains a single line. It contains two positive integers N (2<=N<=10^6), and M (2<=M<=N), M indicates the number of the rock on which the gift is located. A test case in which N=0, M=0 will terminate the input and should not be regarded as a test case.
The Output
For each test case, output a single line containing 'Let me try!' If it's possible to get to Rock m, otherwise, output a single line containing 'Don't make fun of me!'
Sample Input
9 5 12 2 0 0
Sample Output
Don't make fun of me! Let me try!
Note
In test case 2, Frank can reach the gift in this way:
Forward(to rock 4), Forward(to rock 9), Backward(to rock 2, got the gift!)
Note that if Frank jumps forward in his last jump, he will land on the right bank(assume that banks are large enough) and thus, lost the game.
打表后发现,N大于48时,每个石头都能到达,所以大于48直接输出,小与48搜就行了。
至于为什么这样不会证明
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,b,a) for(int i = (b); i >= (a); --i)
#define clr(a,x) memset(a,x,sizeof(a))
int N,M;
const int maxn = 1000000 + 5;
int q[2][maxn],size[2];
bool inq[2][maxn];
bool vis[maxn];
bool solve()
{
if (N > 48) return true;
clr(size,0); clr(inq,0);
clr(vis,0);
int cur = 0;
q[cur][size[cur]++] = 1;
for(int i = 2; size[cur] ; ++i) {
rep(j,0,size[cur]) {
int x = q[cur][j];
vis[x] = true;
x += 2*i-1;
if (x <= N && !inq[cur^1][x]) {
inq[cur^1][x] = true;
q[cur^1][size[cur^1]++] = x;
}
x = q[cur][j];
x -= 2*i-1;
if (x >= 1 && !inq[cur^1][x]) {
inq[cur^1][x] = true;
q[cur^1][size[cur^1]++] = x;
}
}
rep(j,0,size[cur]) inq[cur][q[cur][j]] = false;
size[cur] = 0;
cur ^= 1;
}
return vis[M];
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while (scanf("%d%d",&N,&M),N+M) {
puts(solve() ? "Let me try!" : "Don't make fun of me!");
}
}