补了一场Edu round。

A : Marketing Scheme

水题

  1. #include <cstdio>
  2. #include <algorithm>
  3. typedef long long ll;
  4. int T,l,r;
  5.  
  6. template <typename T>
  7. inline void read(T &x){
  8. x = 0; char ch = getchar(); int f = 1;
  9. for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
  10. for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  11. x *= f;
  12. }
  13. int main(){
  14. read(T);
  15. while(T--){
  16. read(l); read(r);
  17. if(l * 2 > r) printf("YES\n");
  18. else printf("NO\n");
  19. }
  20. return 0;
  21. }

B :Reverse Binary Strings

水构造

  1. #include <cstdio>
  2. #include <algorithm>
  3. typedef long long ll;
  4. const int M = 200010;
  5. int T,n,cnt1,cnt2;
  6. int a[M];
  7.  
  8. template <typename T>
  9. inline void read(T &x){
  10. x = 0; char ch = getchar(); int f = 1;
  11. for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
  12. for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  13. x *= f;
  14. }
  15. int main(){
  16. read(T);
  17. while(T--){
  18. read(n); cnt1 = cnt2 = 0;
  19. for(int i = 1;i <= n; i++){
  20. char ch = getchar();
  21. for(;ch != '0' && ch != '1'; ch = getchar()) ;
  22. a[i] = ch - '0';
  23. if(i != 1){
  24. if(a[i] == a[i - 1] && a[i] == 1) cnt1++;
  25. else if(a[i] == a[i - 1] && a[i] == 0) cnt2++;
  26. }
  27. }
  28. printf("%d\n",std::max(cnt1,cnt2));
  29. }
  30. return 0;
  31. }

C : Chef Monocarp

比较奇怪的背包,照理压成一维。

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <cstring>
  5. typedef long long ll;
  6. const int M = 210;
  7. int T,n;
  8. int t[M], dp[M];
  9.  
  10. template <typename T>
  11. inline void read(T &x){
  12. x = 0; char ch = getchar(); int f = 1;
  13. for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
  14. for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  15. x *= f;
  16. }
  17. int main(){
  18. read(T);
  19. while(T--){
  20. read(n);
  21. for(int i = 1;i <= n; i++) read(t[i]);
  22. std::sort(t + 1,t + n + 1);
  23. memset(dp,0x3f,sizeof(dp));
  24. dp[0] = 0;
  25. for(int i = 1;i <= n << 1; i++)
  26. for(int j = n;j >= 1; j--)
  27. dp[j] = std::min(dp[j],dp[j - 1] + abs(i - t[j]));
  28. printf("%d\n",dp[n]);
  29. }
  30. return 0;
  31. }

D :Minimal Height Tree

因为是bfs,所以直接按照性质模拟即可。

  1. #include <cstdio>
  2. #include <algorithm>
  3. typedef long long ll;
  4. const int M = 200010;
  5. int T,n;
  6. int a[M];
  7.  
  8. template <typename T>
  9. inline void read(T &x){
  10. x = 0; char ch = getchar(); int f = 1;
  11. for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
  12. for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  13. x *= f;
  14. }
  15. int main(){
  16. read(T);
  17. while(T--){
  18. read(n);
  19. for(int i = 1;i <= n; i++) read(a[i]);
  20. int dep = 0, cur = 0, sum = 1;
  21. for(int i = 2,j;i <= n; i++){
  22. if(!cur){
  23. cur = sum; dep++;
  24. }
  25. cur--; j = i;
  26. while(j <= n){
  27. if(a[j] < a[j + 1]){
  28. j++; sum++;
  29. }
  30. else break;
  31. }
  32. i = j;
  33. }
  34. printf("%d\n",dep);
  35. }
  36. return 0;
  37. }

E :Make It Increasing

贪心。直接在每个被b圈定的区间内贪心,记录不需要更改的点个数。

还有一个明显的转化,具体见代码。

  1. #include <cstdio>
  2. #include <algorithm>
  3. typedef long long ll;
  4. const int M = 500010;
  5. int n,k,ans;
  6. int a[M], b[M];
  7.  
  8. template <typename T>
  9. inline void read(T &x){
  10. x = 0; char ch = getchar(); int f = 1;
  11. for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
  12. for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  13. x *= f;
  14. }
  15. int sta[M], top = 0;
  16. int main(){
  17. read(n); read(k);
  18. for(int i = 1;i <= n; i++)
  19. read(a[i]), a[i] -= i;
  20. for(int i = 1;i <= k; i++) read(b[i]);
  21. a[n + 1] = 1e9; a[0] = -1e9;
  22. b[k + 1] = n + 1;
  23. for(int i = 0,l,r;i <= k; i++){
  24. l = b[i]; r = b[i + 1];
  25. if(a[l] > a[r]){
  26. printf("-1\n"); return 0;
  27. }
  28. top = 0;
  29. for(int j = l + 1;j < r; j++)
  30. if(a[l] <= a[j] && a[j] <= a[r]){
  31. int it = std::upper_bound(sta + 1,sta + top + 1,a[j]) - sta;
  32. if(it == top + 1) sta[++top] = a[j];
  33. else sta[it] = a[j];
  34. }
  35. ans += r - l - 1 - top;
  36. }
  37. printf("%d\n",ans);
  38. return 0;
  39. }

F :Emotional Fishermen

既然是记录方案数,那应该是dp了。具体见代码,注意特判。

  1. #include <cstdio>
  2. #include <algorithm>
  3. typedef long long ll;
  4. const int M = 5010, mod = 998244353;
  5. int n;
  6. int a[M], pre[M];//表示最大的j使得a[j] * 2 <= a[i]
  7. int dp[M];//表示以i点为最大值的方案数
  8.  
  9. template <typename T>
  10. inline void read(T &x){
  11. x = 0; char ch = getchar(); int f = 1;
  12. for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
  13. for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  14. x *= f;
  15. }
  16. inline ll q_pow(ll x,ll num){
  17. ll ret = 1;
  18. for(;num; num >>= 1){
  19. if(num & 1) ret = (1ll * ret * x) % mod;
  20. x = (1ll * x * x) % mod;
  21. }
  22. return ret;
  23. }
  24. int fac[M], ifac[M];
  25. inline void pre_work(){
  26. fac[0] = fac[1] = ifac[0] = 1;
  27. for(int i = 2;i <= n; i++) fac[i] = (1ll * fac[i - 1] * i) % mod;
  28. ifac[n] = q_pow(fac[n],mod - 2);
  29. for(int i = n - 1;i >= 1; i--) ifac[i] = (1ll * ifac[i + 1] * (i + 1)) % mod;
  30. }
  31. inline int A(int i,int j){
  32. if(i > j || i < 0 || j < 0) return 0;
  33. return (1ll * fac[j] * ifac[j - i]) % mod;
  34. }
  35. int main(){
  36. read(n);
  37. for(int i = 1;i <= n; i++) read(a[i]);
  38. std::sort(a + 1,a + n + 1);
  39. int l = 0;
  40. for(int i = 1;i <= n; i++){
  41. while(a[l + 1] << 1 <= a[i]) l++;
  42. pre[i] = l;
  43. }
  44. if(pre[n] != n - 1){
  45. printf("0\n"); return 0;
  46. }
  47. dp[0] = 1; pre[0] = -1;
  48. pre_work();
  49. for(int i = 1;i <= n; i++)
  50. for(int j = 0;j <= pre[i]; j++)
  51. dp[i] = (1ll * dp[i] + 1ll * dp[j] * A(pre[i] - pre[j] - 1,n - pre[j] - 2) % mod) % mod;
  52. printf("%d\n",dp[n]);
  53. return 0;
  54. }

G :Death DBMS

后缀自动机,不会。

Educational Codeforces Round 97 (Rated for Div. 2)的更多相关文章

  1. Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)

    题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...

  2. Educational Codeforces Round 97 (Rated for Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1437 A. Marketing Scheme 题解 令 \(l = \frac{a}{2}\),那么如果 \(r < ...

  3. Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree (贪心)

    题意:有一个从根节点\(BFS\)得来的序列(每次\(bfs\)子节点的时候保证是升序放入队列的),现在让你还原树(没必要和之前相同),问能构造出的最小的树的深度. 题解:不看根节点,我们从第二个位置 ...

  4. Educational Codeforces Round 97 (Rated for Div. 2) C. Chef Monocarp (DP)

    题意:有\(n\)个菜在烤箱中,每个时刻只能将一个菜从烤箱中拿出来,第\(i\)个时刻拿出来的贡献是\(|i-a[i]|\),你可以在任意时刻把菜拿出来,问将所有菜拿出的最小贡献是多少? 题解: 先对 ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  6. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  7. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  8. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  9. 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 ...

随机推荐

  1. 金蝶k/3 cloud 生产用料清单下推生成调拨单二开记录

    系统默认的生产用料清单下推生成调拨单功能,是根据调拨选单数量来的,有库存和没有库存的都混在一起,导致业务人员审核调拨单的时候需要删除没有库存的分录行,严重影响工作效率. 现通过二开程序,根据生产用料清 ...

  2. 安装MySQL和出现的问题解决

    在Windows下安装mysql,注意自己的Windows是32位还是64位. MySQL官网下载地址:https://dev.mysql.com/downloads/mysql/ 下载完之后,解压放 ...

  3. vulnhub靶机之Quaoar

    Quaoar 靶机非常简单. 扫描端口主机. wordpress建站. 扫到两个用户,分别是wpuser以及admin. 爆破出了后台: 传了一个一句话木马,连上蚁剑又传了个反弹shell. 反弹sh ...

  4. 几个超级好用但很少有人知道的 webstorm技巧

    我总结一些我发现的比较实用的功能,内容来自日常工作中用到的功能.图片来自PPT,是在公司内部的分享. 你不知道的webstorm进阶使用技巧 1.双击shift 全局搜索,可以搜索代码.设置等. 如果 ...

  5. springboot+mybatis集成分页功能

    1.使用idea搭建srpingboot项目 在pom.xml文件中引入如下的依赖: <dependency> <groupId>org.springframework.boo ...

  6. Python字符编码和二进制不得不说的故事

    二进制 核心思想: 冯诺依曼 + 图灵机 电如何表示状态,才能稳定? 计算机开始设计的时候并不是考虑简单,而是考虑能自动完成任务与结果的可靠性, 简单始终是建立再稳定.可靠基础上 经过尝试10进制,但 ...

  7. 055 01 Android 零基础入门 01 Java基础语法 06 Java一维数组 02 数组的概念

    055 01 Android 零基础入门 01 Java基础语法 06 Java一维数组 02 数组的概念 本文知识点:数组的概念 数组的声明创建.初始化 在学习数组的声明创建.初始化前,我们可以和之 ...

  8. 01 百度 AI Studio 基础操作记录(一) Notebook

    转载参考: AI Studio基本操作(一) Notebook篇 一.基础 1.新建文件: 可以使用命令, !cat <<newfile > newfile.py 在项目空间内直接创 ...

  9. 【代码审计】JAVA代码审计

    分享一些Java安全相关文章,其中大部分都涉及到代码的分析与审计. 大家总是在找Java的代码审计的文章,但好像很多人选择性失明. 其实Java没有和PHP一样的简单,所以你觉得你看到的文章不是入门级 ...

  10. Tensorflow学习笔记No.2

    使用函数式API构建神经网络 函数式API相比于keras.Sequential()具有更加灵活多变的特点. 函数式API主要应用于多输入多输出的网络模型. 利用函数式API构建神经网络主要分为3步, ...