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

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$,不能用$==$,否则,会错在这样的样例上:

  1. RRRRRRR

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n;
  4. ];
  5. int dx,dy;
  6. ],postx[];
  7. ],posty[];
  8.  
  9. bool can(int len){
  10. ;i+len-<=n;++i){
  11. ]+postx[i+len]));
  12. ]+posty[i+len]));
  13. if(needx+needy==len){
  14. ;
  15. }
  16. }
  17. ;
  18. }
  19.  
  20. int main() {
  21. ,cnty=;
  22. scanf(,&dx,&dy);
  23. ;i<=n;++i){
  24. prex[i]=prex[i-],prey[i]=prey[i-];
  25. if(s[i]=='L')prex[i]--,cntx--;
  26. else if(s[i]=='R')prex[i]++,cntx++;
  27. else if(s[i]=='D')prey[i]--,cnty--;
  28. else if(s[i]=='U')prey[i]++,cnty++;
  29. }
  30. ;--i){
  31. postx[i]=postx[i+],posty[i]=posty[i+];
  32. if(s[i]=='L')postx[i]--;
  33. else if(s[i]=='R')postx[i]++;
  34. else if(s[i]=='D')posty[i]--;
  35. else if(s[i]=='U')posty[i]++;
  36. }
  37. !=(abs(cntx)+abs(cnty))%);
  38. ,high=n+,mid;
  39. ){
  40. mid=(low+high)/;
  41. if(can(mid))high=mid;
  42. else low=mid;
  43. }
  44. )printf("%d\n",high);
  45. else puts("-1");
  46. ;
  47. }
  48. /*
  49. 7
  50. RRRRRRR
  51. 3 0
  52. 7
  53. LRLRLRR
  54. 3 2
  55. 3
  56. UUU
  57. 0 2
  58. 7
  59. RRRUUUU
  60. 1 5
  61. 6
  62. UUUUUU
  63. 0 6
  64. 5
  65. DDDDD
  66. 0 1
  67. 7
  68. RRRUUUL
  69. 7 0
  70. 4
  71. URDL
  72. 0 0
  73. 3
  74. DDD
  75. 0 0
  76. 2
  77. RR
  78. 0 0
  79.  
  80. 16
  81. UUUUUUUUUUUUUUUU
  82. 0 15
  83. 2
  84. LD
  85. -1 -1
  86. 5
  87. RURUU
  88. -2 3
  89. 6
  90. RRRUUU
  91. 2 -2
  92.  
  93. **/

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$,那么,退出循环,输出答案。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. #define pb(x) push_back(x)
  5. LL n,a[];
  6. int main() {
  7. LL tot,sum=,ans=;
  8. vector<LL> v,tmp;
  9. scanf("%lld%lld",&n,&tot);
  10. ;i<=n;++i)scanf("%lld",a+i),v.pb(a[i]),sum+=a[i];
  11. ){
  12. if(tot>=sum){
  13. ans+=(tot/sum)*(LL)v.size();
  14. tot%=sum;
  15. }
  16. tmp.clear();
  17. sum=;
  18. ;i<v.size();++i){
  19. if(v[i]<=tot){
  20. tot-=v[i];
  21. sum+=v[i];
  22. ans++;
  23. tmp.pb(v[i]);
  24.  
  25. }
  26. }
  27. )break;
  28. v.assign(tmp.begin(),tmp.end());
  29. }
  30. printf("%lld\n",ans);
  31. ;
  32. }
  33. /*
  34. 3 1000000000000000000
  35. 1000000000 1000000000 1000000000
  36. 7 1000000000000000000
  37. 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
  38. 6 1000000000000000000
  39. 1 1000000000 1 1000000000 1000000000 1000000000
  40. **/

E. Segment Sum

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb(x) push_back(x)
  4. #define mk(x, y) make_pair(x, y)
  5. typedef long long LL;
  6. typedef pair<LL,LL> pll;
  7. LL x,y,k;
  8. ;
  9. ],dn;
  10. pll dp[][][];
  11. LL pow10[];
  12. pll dfs(int pos,int sum,int bit,bool limit,bool lead){
  13. )return __builtin_popcount(bit)<=k?mk(1LL,0LL):mk(0LL,0LL);
  14. )return dp[pos][sum][bit];
  15. pll ans=mk(,);
  16. ,top=limit?digit[pos]:;i<=top;++i){
  17. pll pp=dfs(pos-,sum+i,lead&&i==?bit:bit|(<<i),limit&&i==top,lead&&i==);
  18. ans.first+=pp.first%mod;
  19. ans.second+=(i*pow10[pos-]%mod*pp.first%mod+pp.second)%mod;
  20. if(ans.second>=mod)ans.second%=mod;
  21. }
  22. if(!limit)dp[pos][sum][bit]=ans;
  23. return ans;
  24. }
  25.  
  26. LL solve(LL v){
  27. );
  28. dn=;
  29. ){
  30. digit[++dn]=v%;
  31. v/=;
  32. }
  33. ,,,).second;
  34. }
  35.  
  36. int main() {
  37. pow10[]=1LL;
  38. ;i<=;++i)pow10[i]=pow10[i-]*10LL;
  39. memset(dp,-,sizeof(dp));
  40. scanf("%lld%lld%lld",&x,&y,&k);
  41. printf())%mod);
  42. ;
  43. }
  44. /*
  45. 1 100000000 9
  46. **/

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. GraphQL Gateway Architectures

    转自: https://tomasalabes.me/blog/graphql/node/microservices/2018/08/11/graphql-architectures.html Gra ...

  2. tile38 一款开源的geo 数据库

    tile38 是基于golang 编写的geo 数据库,支持地理空间索引.实时地理围栏,同时也支持leader-flower 的部署模型 备注: 下边测试一个简单的地理围栏功能 环境准备 docker ...

  3. tomcat源码阅读之BackupManager

    一. 配置: <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOpti ...

  4. Quest for sane signals in Qt - step 1 (hand coding a Q_OBJECT)

    探索qt的信号ref: http://crazyeddiecpp.blogspot.hk/2011/01/quest-for-sane-signals-in-qt-step-1.html If it ...

  5. 标 题: JavaScript真的要一统江湖了

    http://www.newsmth.net/nForum/#!article/Python/125347?p=4 标  题: JavaScript真的要一统江湖了 发信站: 水木社区 (Fri Se ...

  6. spring boot 学习资料

    spring boot 学习资料: 学习资料 网址 Spring Boot Cookbook-极客学院 http://wiki.jikexueyuan.com/project/spring-boot- ...

  7. apache的MultipartEntityBuilder文件上传

    本文讲解多文件上传方法,不比较上传有几种方法和效率,而是定向分析apache的httpmime包的MultipartEntityBuilder类,源码包:httpmime-4.5.2.jar 一.常用 ...

  8. C# 集合、字典、栈和队列

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. Elasticsearch集成HanLP分词器

    1.通过git下载分词器代码. 连接如下:https://gitee.com/hualongdata/hanlp-ext hanlp官网如下:http://hanlp.linrunsoft.com/ ...

  10. 【python】多线程详解

    一.进程与线程关系 一个进程至少包含一个线程. 二.线程基础 1.线程的状态 线程有5种状态,状态转换的过程如下图所示: 2.线程同步(锁) 多线程的优势在于可以同时运行多个任务(至少感觉起来是这样) ...