2019牛客暑期多校训练营(第十场)-B- Coffee Chicken

牛客最后一场的签到题之二

我疯狂WA了!!!题目如下

题目链接
Dr. JYY has just created the Coffee Chicken strings, denoted as S(n). They are quite similar to the Fibonacci soup — today’s soup is made by mingling yesterday’s soup and the day before yesterday’s soup:

  • S(1) = \texttt{“COFFEE”}S(1)=“COFFEE”;
  • S(2) = \texttt{“CHICKEN”}S(2)=“CHICKEN”;
  • S(n) = S(n-2) :: S(n-1), where :: denotes string concatenation.
    The length of S(n) quickly gets out of control as n increases, and there would be no enough memory in JYY’s game console to store the entire string. He wants you to find 10 contiguous characters in S(n), starting from the kth character.

输入描述:
The first line of input is a single integer T (1 <= T <= 1000)(1≤T≤1000), denoting the number of test cases. Each of the following T lines is a test case, which contains two integers n, k (1 <= n <= 500, 1 <= k<=\min{|S(n)|, 10{12}})(1≤n≤500,1≤k≤min{∣S(n)∣, 1 0 12 10^{12} 1012}). |S| denotes the length of string S.
输出描述:
For each test case, print the answer in one line. If there are no enough characters from the kth character, output all characters until the end of the string.
示例1
输入
2
3 4
2 7
输出
FEECHICKEN
N

赛时口胡:

觉得很明显也很简单,打个fibo表找规律,或者dp,结果饶了半天规律还是WA,各种造数据卡自己…

就这样,时间过了两小时…

终于发现了,其实就是一个递归按字符找而已。
思路还是打一个fibo表,不过题目虽然说范围是500,但给出了S(n)的范围 1 0 12 10^{12} 1012,所以需要控制一下,打到 1 0 12 10^{12} 1012就行了。
然后递归找字符,观察一下规律可以发现,组成字符串的始终是咖啡机(咖啡机牛逼!),所以即可发现该递归式。

ACCODE:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1LL<<50;
string x[3]={"","COFFEE","CHICKEN"};
ll f[501];
char dfs(ll n,ll k)
{
    if(n==1||n==2) return x[n][k-1];
    if(k>f[n-2]) return dfs(n-1,k-f[n-2]);
    return dfs(n-2,k);
}
int main()
{
    f[1]=6;
    f[2]=7;

    for(int i=3;i<=500;i++)
    {
        
        f[i]=min(inf,f[i-2]+f[i-1]);
 
    }
    int t;
    cin>>t;
    while(t--)
    {
        ll n,k;
        scanf("%lld%lld",&n,&k);
        for(ll i=k;i<k+10;i++) 
		{
			if(i>f[n]) break;
			cout<<dfs(n,i);
		}
        cout<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值