写之前,先发表下感慨:好久没写题解了,也许是因为自己越来越急利了,也可以说是因为越来越懒了。

A. Diverse Substring

直接找一找有没有相邻的两个不同的字符即可。

B. Vasya and Books

分别记录书本摆放顺序$a[]$,取书顺序$b[]$,每本书的位置$pos[]$,每本书在不在书堆上$in[]$,书堆最顶端的书的位置$top$(因为用的是数组,元素位置是固定的)。

然后,按照题意枚举输入的取书顺序$b[]$,同时记录答案$ans$,更新$top$即可。

C. Vasya and Robot

过滤掉目的地坐标累加和的绝对值和指令长度奇偶性不相同的情况。然后,剩余的所有情况,要么指令步数不够,要么一定有解。此时,答案满足单调性(如果不提前过滤掉奇偶性不同的情况,答案不满足单调性),二分答案即可。具体做法是,预处理出$x$轴方向的前缀和(向右$+1$,向左$-1$)和后缀和,以及$y$轴方向的前缀和(向上$+1$,向下$-1$)和后缀和,二分答案时,直接枚举区间左端点,然后$O(1)$检查枚举区间之外的$x$轴方向和$y$轴方向所需要改变的步数是不是小于二分枚举的区间长度。注意,这个地方只能用$\le$,不能用$==$,否则,会错在这样的样例上:

RRRRRRR
 

具体代码如下(附个人自用的测试样例):

#include<bits/stdc++.h>
using namespace std;
int n;
];
int dx,dy;
],postx[];
],posty[];

bool can(int len){
    ;i+len-<=n;++i){
        ]+postx[i+len]));
        ]+posty[i+len]));
        if(needx+needy==len){
            ;
        }
    }
    ;
}

int main() {
    ,cnty=;
    scanf(,&dx,&dy);
    ;i<=n;++i){
        prex[i]=prex[i-],prey[i]=prey[i-];
        if(s[i]=='L')prex[i]--,cntx--;
        else if(s[i]=='R')prex[i]++,cntx++;
        else if(s[i]=='D')prey[i]--,cnty--;
        else if(s[i]=='U')prey[i]++,cnty++;
    }
    ;--i){
        postx[i]=postx[i+],posty[i]=posty[i+];
        if(s[i]=='L')postx[i]--;
        else if(s[i]=='R')postx[i]++;
        else if(s[i]=='D')posty[i]--;
        else if(s[i]=='U')posty[i]++;
    }
    !=(abs(cntx)+abs(cnty))%);
    ,high=n+,mid;
    ){
        mid=(low+high)/;
        if(can(mid))high=mid;
        else low=mid;
    }
    )printf("%d\n",high);
    else puts("-1");
    ;
}
/*
7
RRRRRRR
3 0
7
LRLRLRR
3 2
3
UUU
0 2
7
RRRUUUU
1 5
6
UUUUUU
0 6
5
DDDDD
0 1
7
RRRUUUL
7 0
4
URDL
0 0
3
DDD
0 0
2
RR
0 0

16
UUUUUUUUUUUUUUUU
0 15
2
LD
-1 -1
5
RURUU
-2 3
6
RRRUUU
2 -2

**/

D. Berland Fair

①先考虑$T$大于序列和的情况:此时,$ans+=\frac{T}{序列和}*序列长度$,同时$T%=序列和$;

②当$T$小于序列和时,枚举序列的所有元素,如果$a[i]\le T$,那么$T-=a[i],ans+=1$,并且把$a[i]$放到一个临时序列中,同时记录这些$a[i]$的和,枚举原序列结束后,用临时序列替换原序列,回到步骤①。当临时序列为空时,说明没有$a[i]\le T$,那么,退出循环,输出答案。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb(x) push_back(x)
LL n,a[];
int main() {
    LL tot,sum=,ans=;
    vector<LL> v,tmp;
    scanf("%lld%lld",&n,&tot);
    ;i<=n;++i)scanf("%lld",a+i),v.pb(a[i]),sum+=a[i];
    ){
        if(tot>=sum){
            ans+=(tot/sum)*(LL)v.size();
            tot%=sum;
        }
        tmp.clear();
        sum=;
        ;i<v.size();++i){
            if(v[i]<=tot){
                tot-=v[i];
                sum+=v[i];
                ans++;
                tmp.pb(v[i]);

            }
        }
        )break;
        v.assign(tmp.begin(),tmp.end());
    }
    printf("%lld\n",ans);
    ;
}
/*
3 1000000000000000000
1000000000 1000000000 1000000000
7 1000000000000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
6 1000000000000000000
1 1000000000 1 1000000000 1000000000 1000000000
**/

E. Segment Sum

裸的数位$dp$。$dp[pos][sum][bit]$表示前面的数位累加和为$sum$,前面使用过的数字的二进制表示为$bit$时,从$pos$位开始往下搜索,后面的数位随意组合,可以搜索到的满足条件的数字个数以及他们的和。$dp$数组用$pair<long\ long,long\ long>$表示。注意,$dp[pos][sum][bit].second$是表示从$pos$位开始往下搜索,搜到的满足条件的数字的后$pos$位的和。前面的权值部分不算,否则就乱套了。另外,是和,也就是权值和,相当于取后半截作为一个数字的值,而不是数位和。

#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)
typedef long long LL;
typedef pair<LL,LL> pll;
LL x,y,k;
;
],dn;
pll dp[][][];
LL pow10[];
pll dfs(int pos,int sum,int bit,bool limit,bool lead){
    )return __builtin_popcount(bit)<=k?mk(1LL,0LL):mk(0LL,0LL);
    )return dp[pos][sum][bit];
    pll ans=mk(,);
    ,top=limit?digit[pos]:;i<=top;++i){
        pll pp=dfs(pos-,sum+i,lead&&i==?bit:bit|(<<i),limit&&i==top,lead&&i==);
        ans.first+=pp.first%mod;
        ans.second+=(i*pow10[pos-]%mod*pp.first%mod+pp.second)%mod;
        if(ans.second>=mod)ans.second%=mod;
    }
    if(!limit)dp[pos][sum][bit]=ans;
    return ans;
}

LL solve(LL v){
    );
    dn=;
    ){
        digit[++dn]=v%;
        v/=;
    }
    ,,,).second;
}

int main() {
    pow10[]=1LL;
    ;i<=;++i)pow10[i]=pow10[i-]*10LL;
    memset(dp,-,sizeof(dp));
    scanf("%lld%lld%lld",&x,&y,&k);
    printf())%mod);
    ;
}
/*
1 100000000 9
**/

F. Choosing Two Paths

G. Yet Another LCP Problem

Codeforces-Educational Codeforces Round 53题解的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. [codeforces][Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair]

    http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...

  4. Codeforces Educational Codeforces Round 54 题解

    题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...

  5. Codeforces Educational Codeforces Round 57 题解

    传送门 Div 2的比赛,前四题还有那么多人过,应该是SB题,就不讲了. 这场比赛一堆计数题,很舒服.(虽然我没打) E. The Top Scorer 其实这题也不难,不知道为什么这么少人过. 考虑 ...

  6. Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学

    E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...

  7. Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法

    D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...

  8. Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集

    C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...

  9. Codeforces Educational Codeforces Round 5 B. Dinner with Emma 暴力

    B. Dinner with Emma 题目连接: http://www.codeforces.com/contest/616/problem/A Description Jack decides t ...

随机推荐

  1. 数据库与java的连接

    jdbc: java database connection,也就是java的数据库连接. 作用: 完成数据库数据和内存数据的交互. 为了屏蔽不同数据库的差异,在内存和各种数据库之间建立了一个接口标准 ...

  2. 谈谈 SOA

    为什么要 讨论 SOA 呢 ? 请参考我写的另一篇文章 <论 微服务 和 Entity Framework 对 数据 的 割裂>    https://www.cnblogs.com/KS ...

  3. 配置zabbix当内存剩余不足15%的时候触发报警

    zabbix默认的剩余内存报警:Average Lack of available memory on server {HOST.NAME}{Template OS Linux:vm.memory.s ...

  4. 怎么检测浏览器有没有flash播放器

    虽然现在大多浏览器都支持了HTML5的新特性,可以直接在网页上播放视频,通过<video>标签即可,但是大多数的浏览器对H5支持还是不够完整,或者很多用户还没有把浏览器升级到最新的版本,尤 ...

  5. requestAnimationFrame 知识点

    与setTimeout相比,requestAnimationFrame最大的优势是由系统来决定回调函数的执行时机.具体一点讲,如果屏幕刷新率是60Hz,那么回调函数就每16.7ms被执行一次,如果刷新 ...

  6. Spring Boot中对自然语言处理工具包hanlp的调用详解

    概 述 HanLP 是基于 Java开发的 NLP工具包,由一系列模型与算法组成,目标是普及自然语言处理在生产环境中的应用.而且 HanLP具备功能完善.性能高效.架构清晰.语料时新.可自定义的特点, ...

  7. C# MD5位加密

    /// <summary> /// 方法一:通过使用 new 运算符创建对象 /// </summary> /// <param name="strSource ...

  8. App音频内录 录音

    1.android模拟器 天天模拟器+BlueStacks 2.高清内录软件 Audio Record Wizard.exe 3.音频剪切软件 Adobe Audition CS6

  9. ArrayBlcokingQueue,LinkedBlockingQueue与Disruptor三种队列对比与分析

    一.基本介绍 ArrayBlcokingQueue,LinkedBlockingQueue是jdk中内置的阻塞队列,网上对它们的分析已经很多,主要有以下几点: 1.底层实现机制不同,ArrayBlco ...

  10. Mysql 性能优化4 mysql参数配置

    mysql 参数的介绍 大概450项参数,大多保持默认就可以了 错误的参数 崩溃,错误,运行缓慢. 参数最好在生产环境前配置好.最好不要在生产环境 中 直接配置,有可能不会立即生效,或者之前的数据和配 ...