Gift?! UVA - 10120

问题

https://vjudge.net/problem/UVA-10120

分析

第一想法是模拟,但是会超时,随后想到找规律,但是太菜了,找不出来。
参考:https://www.cnblogs.com/zjbztianya/archive/2013/04/14/3019693.html

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn=1000000+5;
int n,m;

bool dfs(int cur,int d){
    if(cur==m) return true;
    int len=(d<<1)-1;
    if(cur-len>0 && dfs(cur-len,d+1)) return true;
    if(cur+len<=n && dfs(cur+len,d+1)) return true;
    return false;
}

int main(void){
    while(scanf("%d%d",&n,&m)==2 && n){
        if (n>=49) printf("Let me try!\n");
        else if(dfs(1,2)) printf("Let me try!\n");
        else printf("Don't make fun of me!\n");

    }
    return 0;
}
发布了180 篇原创文章 · 获赞 3 · 访问量 3455

猜你喜欢

转载自blog.csdn.net/zpf1998/article/details/105033349