UVA10120 - Gift?!

题目链接

题意:有n个石头,编号从1到n,礼物藏在编号为m的石头上,第i次跳2*1-1格,可以向前跳也可以向后跳,问是否能拿到礼物。

思路:简单的DFS。重点是有规律,就是n>=50时,不管m为何值,都是可以抵达m石头,所以只要搜索50以下就可以了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n, m, flag;

void dfs(int cur, int d) {
    if (flag)
        return;
    if (cur == m) {
        flag = 1;
        return;
    }
    int step = 2 * (d + 1) - 1;
    if (cur + step <= n && cur + step >= 1) {
        dfs(cur + step, d + 1);
    }
    if (cur - step >= 1 && cur - step <= n) {
        dfs(cur - step, d + 1);
    }
    return;
}

int main() {
    while (scanf("%d %d", &n, &m) != EOF) {
        if (m == 0 && n == 0)
            break;
        if (n >= 50) {
            printf("Let me try!\n");
            continue;
        }
        flag = 0;
        dfs(1, 1);
        if (flag)
            printf("Let me try!\n");
        else
            printf("Don't make fun of me!\n");
    }
    return 0;
}

UVA10120 - Gift?!

时间: 2024-10-12 23:28:56

UVA10120 - Gift?!的相关文章

Ch’s gift

Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing and turning, he decides to get to his

Up to 8% free bonus for runescape 2007 gp on Rsorder as july best gift&Enjoy Telos During 7.1-7.22

Now, a small band of freedom fighters struggle to end the osrs gold  long, dark night of Daein's oppression. The big blog news of the day is that Vox Media has acquired Curbed Network. As an amulet you should be wearing an amulet of glory and if you

CodeForces 76A Gift - 最小生成树

The kingdom of Olympia consists of N cities and M bidirectional roads. Each road connects exactly two cities and two cities can be connected with more than one road. Also it possible that some roads connect city with itself making a loop. All roads a

bzoj 2056: gift? 高精度?

2056: gift? 高精度? Time Limit: 10 Sec  Memory Limit: 1 MB Description Input 输入的第一行为一个整数t. 接下来t行,每行包含九个自然数. Output 输出t行 每行一个整数,表示2^a+2^b+2^c+2^d+2^e+2^f+2^g+2^h+i. Sample Input 1 21 30 0 0 0 0 0 0 2147483647 Sample Output 3223322629 HINT [数据规模]40% t<=10

USACO Train 1.1.2 Greedy Gift Givers

这道题大意就是几个人互送礼物,让你求每个人的盈利. 原题给的样例数据: 5(人的个数.) =========(下面是人名,输出按照这顺序)davelauraowenvickamr ==========(下面是每个人的要给的人)dave200 3lauraowenvick ----------owen500 1dave ----------amr150 2vickowen -----------laura0 2amrvick ----------vick0 0 这题使用模拟算法就行了,就是注意输入

Secrets To Getting Amazon gift card codes To Complete Tasks Quickly And Efficiently

Amazon gift card are not as easy to get if you do not know how to complet a survey . Amazon gift card are difficult and as hard to combact with the survey . So please do not hurry you should try the new method to get free amazon gift card codes . For

HDU5171 GTY&#39;s birthday gift(矩阵快速幂)

Problem Description FFZ's birthday is coming. GTY wants to give a gift to ZZF. He asked his gay friends what he should give to ZZF. One of them said, 'Nothing is more interesting than a number multiset.' So GTY decided to make a multiset for ZZF. Mul

【Best Coder】#29 B GTY&#39;s birthday gift(快速幂|mod的时候记得负!)

题目大意:查看相关场次即可看到. 思路:推公式的题目,可以用快速幂加公式快速解决,也可以用二进制拆分运算的方法加快速度. 需要注意的一点在于:今后在mod之后有涉及到运算的都要加上一个mod之后再mod,或者统一都加一个mod 顺便复习一下二进制拆分的方法!! 二进制拆分的做法AC代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<cstdio> usin

codeforces 505A. Mr. Kitayuta&#39;s Gift 解题报告

题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母,使得新得到的字符串成为回文串. /**************************************(又到自我反省时刻) 做的时候,通过添加一个单位使得长度增加1,找出中点,检验前一半的位置,找出对称位置替换成对应的前一半位置的字符,然后原字符串剩下的部分追加到后面,再判断回文.但是由于