牛客多校第十场 B
- 题意:
- 求字符串的第n项的第k到第k+9个字符,输出
- 类似个斐波那契数列
- 题解:
- 基础递归,记录每个字符串的长度,和第n-2个比较,模拟着写就行
- 代码:
#include <bits/stdc++.h> using namespace std; #define ll long long const ll inf = 1e13; const int maxx = 505; string s[2] = {"COFFEE","CHICKEN"}; ll t,n; ll a[maxx]; ll k; char solve(ll x,ll y) { if(x <= 2){ return s[x-1][y-1]; } else if(a[x-2] >= y){ return solve(x-2,y); } return solve(x-1 , y - a[x-2]); } void init() { a[1] = 6,a[2] = 7; for(int i=3;i<=maxx;i++) a[i] = min(inf , a[i-1]+a[i-2]); return ; } int main() { cin>>t; init(); while(t--) { cin>>n>>k; for(ll i=k;i<=min(k+9,a[n]);i++) { cout<<solve(n,i); } cout<<endl; } return 0; }
```