codeforces 897 D Ithea Plays With Chtholly(交互)

来源:互联网 发布:做数据是什么 编辑:程序博客网 时间:2024/05/11 18:01

题意:

每次给你一个数,让你放到一个长度为n 的数组里,直到这个数组填满并且是不递减函数为止。需要 在m步内完成


c是给出的数的范围。


解题思路:

一种显然的暴力方法就是从1开始扫描,遇到第一个大于x的或是a[i]==0的就放。

但是还有显然的卡掉这种暴力的做法,就是把数n-1逐个给出,就每次要替换,这样的话就需要n^2次,显然不行。

所以应该能想到从两边,开始扫描,让大于c/2的从n开始往下扫描,这样刚刚那组数据就可以过了,复杂度正好是n*c/2。

赛时想到往两边放了,但是产生了需要开两个数组的错觉,然后无法合并两个数组,就开始乱搞了。。其实放一个数组里两种不同方法就能搞定,这需要抽象一下。。。


代码:

#include <bits/stdc++.h>#define LL long longusing namespace std;const int maxn=1e5+5;const LL inf=1e18+7;LL dp[maxn];char str1[100]="What are you doing at the end of the world? Are you busy? Will you save us?";char str2[100]="What are you doing while sending \"@\"? Are you busy? Will you send \"@\"?";int l1, l2;char solve(int n, LL k){    if(n==0)return str1[k-1];    int i, j;    for(i=0; i<l2; i++)    {        if(str2[i]=='@')        {            if(dp[n-1]>=k)            {                return solve(n-1, k);            }                   k-=dp[n-1];        }        else         {            k--;            if(k==0)            {                return str2[i];            }        }    }    return '.';}int main(){    l1=strlen(str1);    l2=strlen(str2);    dp[0]=l1;    for(int i=1; i<=100000; i++)    {        dp[i]=min(dp[i-1]*2LL+l2-2LL, inf);    }    int n, q, i, j;    LL k;    cin>>q;    while(q--)    {        cin>>n>>k;        if(k>dp[n])        {            printf(".");        }         else printf("%c", solve(n, k));    }        }


阅读全文
0 0
原创粉丝点击