ZOJ 1229 M-Gift?!
https://vjudge.net/contest/67836#problem/M
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?'
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 (1<=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.
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!
代码:
#include <bits/stdc++.h>
using namespace std; int N, Gift;
bool flag[55]; void dfs(int i, int sum) {
if(sum <= 0 || sum >= N + 1)
return ;
flag[sum] = true;
dfs(i + 1, sum + 2 * i - 1);
dfs(i + 1, sum - 2 * i + 1);
} int main() {
while(~scanf("%d%d", &N, &Gift)) {
if(!N && !Gift) break; if(N >= 50)
printf("Let me try!\n");
else {
memset(flag, false, sizeof(flag));
dfs(2, 1);
if(flag[Gift])
printf("Let me try!\n");
else
printf("Don't make fun of me!\n");
}
}
return 0;
}
ZOJ 1229 M-Gift?!的更多相关文章
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
随机推荐
- Invoice Helper
using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messag ...
- java中子类会继承父类的构造方法吗?
参考: https://blog.csdn.net/wangyl_gain/article/details/49366505
- 基于Geomesa服务查询轨迹数据无法根据空间和时间范围进行结果查询
一.Geomesa - QuickStart(教程工程包) 百度网盘下载地址:geomesa-tutorials-master.7z 二.解压后,IDEA编译如下 百度网盘下载地址:IDEA201 ...
- FPGA软硬协同设计学习笔记及基础知识(一)
一.FPGA软件硬件协同定义: 软件:一般以软件语言来描述,类似ARM处理器的嵌入式设计.硬件定义如FPGA,里面资源有限但可重配置性有许多优点,新的有动态可充配置技术. Xilinx开发了部分动态可 ...
- BZOJ3209(luogu 4317)花神的数论题题解
题目 设 sum(i) 表示 i 的二进制表示中 1 的个数.给出一个正整数 N ,花神要问你 派(Sum(i)),也就是 sum(1)—sum(N) 的乘积(n<=1e15). 分析 好吧,一 ...
- 理解C指针: 一个内存地址对应着一个值
一个内存地址存着一个对应的值,这是比较容易理解的. 如果程序员必须清楚地知道某块内存存着什么内容和某个内容存在哪个内存地址里了,那他们的负担可想而知. 汇编语法对“一个内存地址存着一个对应的数” ...
- mongoengine中collection名称自动生成机制浅探
项目碰到要使用mongodb的场景,以前只听过这一强大的文档数据库,但一直没有真正使用过,参考一下项目中已有的使用代码,是通过import mongoengine这一模块实现python服务对db中c ...
- 北京Uber优步司机奖励政策(3月15日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 笔记本ubuntu安装wifi驱动(未完成)
1. 用联想E440,Ubuntu14.04,安装完之后,没有检查到wifi的驱动,所以需要安装.
- DSP5509的定时器实验-第2篇
1. 导入Easy5509开发板的例程EX02_TIME,5509有2个16位的定时器,有点少啊 2. 直接编译,提示找不到CSL.h,其实我也好奇,CSL库是从哪里来的?RTS库从哪里来的?头文件在 ...