Educational Codeforces Round 63

A

题目大意就不写了.

挺简单的,若果字符本来就单调不降,那么就不需要修改

否则找到第一次下降的位置和前面的换就好了.

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cctype>
  4. #include<algorithm>
  5. #include<queue>
  6. using namespace std;
  7. const int N = 3e5 + 3;
  8. char s[N];
  9. int n;
  10. int x,y;
  11. inline bool check(){
  12. int last = -1;
  13. for(int i = 1;i <= n;++i){
  14. if(last > s[i]) {
  15. x = i - 1,y = i;
  16. return false;
  17. }
  18. last = s[i];
  19. }
  20. return true;
  21. }
  22. int main(){
  23. scanf("%d",&n);
  24. scanf("%s",s + 1);
  25. if(check()) printf("NO\n");
  26. else printf("YES\n%d %d\n",x,y);
  27. return 0;
  28. }

B

题目大意:给一个数字串,每个人可以轮流拿掉其中任何一个数字,串长为\(11\)(保证串长大于\(11\)且为奇数)时结束,这是如果开头为\(8\),则先手获胜,问先手是否有必胜策略

刚开始以为是个博弈论,推了\(20\)分钟,发现,我们设两人一共的操作次数为\(k\),能够影响答案的只有前\(k + 1\)个数,我们将\(8\)看作\(1\),非$8 $看作\(0\)

如果前\(k\)个数\(1\)比较多,那么先手必胜,因为后手拿不玩

反之如果\(0\)比较多,那么先手必败

如果一样多,则取决于第\(k + 1\)的数

  1. #include<cstdio>
  2. #include<cstring>
  3. using namespace std;
  4. const int N = 3e5 + 3;
  5. char s[N];
  6. int n;
  7. int main(){
  8. scanf("%d",&n);
  9. scanf("%s",s + 1);
  10. bool flag = 1;
  11. int need = (n - 11);
  12. int sum1 = 0,sum2 = 0;
  13. for(int i = 1;i <= need;++i)
  14. if(s[i] == '8') sum1++;
  15. else sum2++;
  16. if(sum1 > sum2) printf("YES\n");
  17. else if(sum1 < sum2) printf("NO\n");
  18. else{
  19. if(s[need + 1] == '8') printf("YES\n");
  20. else printf("NO\n");
  21. }
  22. return 0;
  23. }

C

题目大意:给定数组\(x\)与\(y\),问是否存在\(y_i\)和\(b\)将\(x\)中所有的数表示为\(ky_i + b\)的形式(\(x\)数组单调)

看样子自己的数学功底还是不行的

我们试想一下

对于\(a_i\)和\(a_{i + 1}\),如果存在\(y_i\)符合题意,那么一定有\(a_{i + 1} - a_i = ky_i\),也就是说

\(y_i\)要是所有数与其相邻的数差最大公约数的一个因子(这样才能用\(ky_i\)表示出所有的差).

而\(b\)的值,很明显选择\(x_1\)就好了

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cmath>
  4. #define LL long long
  5. using namespace std;
  6. const int N = 3e5 + 3;
  7. LL a[N],b[N];
  8. inline LL read(){
  9. LL v = 0,c = 1;char ch = getchar();
  10. while(!isdigit(ch)){
  11. if(ch == '-') c = -1;
  12. ch = getchar();
  13. }
  14. while(isdigit(ch)){
  15. v = v * 10 + ch - 48;
  16. ch = getchar();
  17. }
  18. return v * c;
  19. }
  20. int n,m;
  21. inline LL gcd(LL x,LL y){
  22. return y == 0 ? x : gcd(y,x % y);
  23. }
  24. int main(){
  25. n = read(),m = read();
  26. for(int i = 1;i <= n;++i) a[i] = read();
  27. for(int i = 1;i <= m;++i) b[i] = read();
  28. LL g = a[2] - a[1];
  29. for(int i = 3;i <= n;++i) g = gcd(g,a[i] - a[i - 1]);
  30. LL ans = -1;
  31. for(int i = 1;i <= m;++i) if(g % b[i] == 0){
  32. ans = i;
  33. break;
  34. }
  35. if(ans == -1) puts("NO");
  36. else{
  37. puts("YES");
  38. cout << a[1] << " " << ans << endl;
  39. }
  40. return 0;
  41. }

D

题目大意给定\(x\)和一个数组\(a\),你可以选择一个区间将其所有元素乘\(x\)(当然也可以不乘),求乘完之后的最大字段和.

这道题不会不应该.

但这也告诉了我一个技巧,当仅可以选择一个区间进项操作,然后求答案是,用\(dp\)将状态分为操作前,操作中和操作后进行考虑

那么转移方程很明显了

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cctype>
  5. #define LL long long
  6. using namespace std;
  7. const int N = 3e5 + 3;
  8. LL dp[N][3];
  9. LL a[N];
  10. int n;LL x;
  11. int main(){
  12. scanf("%d%I64d",&n,&x);
  13. for(int i = 1;i <= n;++i) scanf("%I64d",&a[i]);
  14. dp[1][0] = a[1],dp[1][1] = a[1] * x,dp[1][2] = a[1];
  15. for(int i = 2;i <= n;++i){
  16. dp[i][0] = max(a[i],dp[i - 1][0] + a[i]);
  17. dp[i][1] = max(a[i] * x,max(dp[i - 1][1] + a[i] * x,dp[i - 1][0] + a[i] * x));
  18. dp[i][2] = max(a[i],max(a[i] + dp[i - 1][2],a[i] + dp[i - 1][1]));
  19. }
  20. LL ans = 0;
  21. for(int i = 1;i <= n;++i) ans = max(ans,max(dp[i][0],max(dp[i][1],dp[i][2])));
  22. printf("%I64d\n",ans);
  23. return 0;
  24. }

Educational Codeforces Round 63部分题解的更多相关文章

  1. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  2. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  3. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

  4. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  5. Educational Codeforces Round 63 (Rated for Div. 2) E 带模高斯消元

    https://codeforces.com/contest/1155/problem/E 题意 \(f(x)=a_0+a_1x+a_2x^2+...+a_kx^k,k \leq 10,0 \leq ...

  6. Educational Codeforces Round 63 (Rated for Div. 2) D dp(最大连续子序列)

    https://codeforces.com/contest/1155/problem/D 题意 一个n个数的数组\(a[i]\),可以选择连续的一段乘x,求最大连续子序列的值 题解 错误思路:贪心, ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array (简单DP)

    题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: ...

  8. Educational Codeforces Round 63 选做

    D. Beautiful Array 题意 给你一个长度为 \(n\) 的序列.你可以选择至多一个子段,将该子段所有数乘上给定常数 \(x\) .求操作后最大的最大子段和. 题解 考虑最大子段和的子段 ...

  9. Educational Codeforces Round 16---部分题解

    710A. King Moves 给你图中一点求出它周围有几个可达的点: 除边界之外都是8个,边界处理一下即可: #include<iostream> #include<cstdio ...

随机推荐

  1. request header....

    root@xxx# curl -i --get --include 'http://ali-barcode.showapi.com/barcode?code=6938166920785' -H 'Au ...

  2. 2016 Asia Jakarta Regional Contest L - Tale of a Happy Man UVALive - 7722

    UVALive - 7722 一定要自己做出来!

  3. 通过反射拿到构造方法 Day25

    package com.sxt.constructor; /* * 反射 * Class类拿到构造方法 */ import java.lang.reflect.Constructor; public ...

  4. @atcoder - AGC038F@ Two Permutations

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 N 与两个 0~N-1 的置换 P, Q. 现在你需要找到 ...

  5. Notepad++颜色配置

    目前看着比较顺眼的notepad++配置,记录如下:

  6. mysql统计信息相关

    最近RDS FOR MYSQL5.6的统计信息有问题,一些表明明的数据,但统计信息里去显示为空表,导致执行计划出错,查询效率很低,所以查看下相关的信息. -- 查看服务器系统变量,实际上使用的变量的值 ...

  7. HDFS概念

  8. 提高github下载速度的方法【100%有效】可达到2MB/s

    因为大家都知道的原因,在国内从github上面下载代码的速度峰值通常都是20kB/s.这种速度对于那些小项目还好,而对于大一些的并且带有很多子模块的项目来讲就跟耽误时间.而常见的的方法无非就是修改HO ...

  9. 利用arguments求任意数量数字的和/最大值/最小值

    文章地址 https://www.cnblogs.com/sandraryan/ arguments是函数内的临时数据,用完销毁,有类似于数组的操作,但不是数组. 举个栗子1:利用arguments求 ...

  10. Vue 组件中的data数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...