zoukankan      html  css  js  c++  java
  • UVA 10120


     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个石头,最终目标是m,每次移动1,3,5,7.步,步数递增,次数不限,只要不跳到石头之外就可以了,求是否能跳到m。

    思路:n>=49的话,不管什么位置都可以跳到,<49的时候进行搜索。

    代码:

    #include <stdio.h>
    #include <string.h>
    #include <queue>
    using namespace std;
    
    int n, m;
    struct State {
    	int v, k;
    }p;
    
    bool bfs() {
    	queue<State>Q;
    	p.v = 1; p.k = 3;
    	Q.push(p);
    	while (!Q.empty()) {
    		p = Q.front(); Q.pop();
    		if (p.v == m) return true;
    		State q = p; q.v += q.k; q.k += 2;
    		if (q.v > 0 && q.v <= n)
    			Q.push(q);
    		q = p; q.v -= q.k; q.k += 2;
    		if (q.v > 0 && q.v <= n)
    			Q.push(q);
    	}
    	return false;
    }
    
    void solve() {
    	if (n <= 49 && !bfs()) printf("Don't make fun of me!
    ");
    	else printf("Let me try!
    ");
    }
    
    int main() {
    	while (~scanf("%d%d", &n, &m) && n + m) {
    		solve();
    	}
    	return 0;
    }


  • 相关阅读:
    codeblocks 配置
    2020-7-28
    echarts markPoint在极坐标散点图中不显示value值
    Oracle cve 2020-14644 分析利用以及回显思路
    Openfire Admin Console SSRF&任意文件读取漏洞 CVE-2019-18394 CVE-2019-18393 poc
    Shiro 回显利用工具(burp
    java反序列化提取payload之Xray高级版的shiro回显poc的提取过程
    CVE-2020-3452 CISCO ASA远程任意文件读取 poc
    记事本陈列-历届数学建模大赛优秀论文(含国赛、美赛、研赛)目录
    懒人必备 |通过爬虫 筛选以及查看CSDN 满足相应积分的资源列表 简单好用
  • 原文地址:https://www.cnblogs.com/fuhaots2009/p/3508776.html
Copyright © 2011-2022 走看看