A. Reverse a Substring

容易看出,只要符合递增顺序就符合\(NO\),否则则可以找到一组,每次记录最大值比较即可。

#include <cstdio>
#include <iostream>
using namespace std;
const int N = 300010;
int n;
char s[N];
int main(){
scanf("%d%s", &n, s + 1);
int maxn = s[1], k = 1;
for(int i = 2; i <= n; i++){
if(s[i] < maxn){
printf("YES\n%d %d\n", k, i);
return 0;
}
if(s[i] > maxn){
maxn = s[i];
k = i;
}
}
printf("NO\n");
return 0;
}

B. Game with Telephone Numbers

\(Vasya\)用尽所有轮次可以把几个\(8\)扔到最前面,只要这个数大于轮次,就说明\(Petya\)无法逆天改命。

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 100010;
int n;
char s[N];
int main(){
scanf("%d%s", &n, s + 1);
int round = (n - 11) >> 1;
int cnt = 0;
for(int i = 1; i <= round && round <= n; i++){
if(s[i] == '8')cnt++, round ++;
}
int i = round + 1;
while(s[i] == '8' && i <= n) i++, cnt++;
if(cnt > (n - 11) >> 1) puts("YES");
else puts("NO");
return 0;
}

C. Alarm Clocks Everywhere

显然,y设置为\(x[1]\)即可,因为即使设置在之前,还是要经过\(x[1]\),还是以\(p\)往上跳,是没有区别的。

我们只要找到一个\(p_j\),使其满足\(p_j | a[i + 1] - a[i] (1 <= i < n)\)。(整除的意思)

#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 300010;
int n, m;
LL x[N], p[N];
LL gcd(LL a, LL b){
return b ? gcd(b, a % b) : a;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%lld", x + i);
for(int i = 1; i <= m; i++)
scanf("%lld", p + i); LL ans = x[2] - x[1];
for(int i = 2; i < n; i++)
ans = gcd(ans, x[i + 1] - x[i]); for(int i = 1; i <= m; i++){
if(ans % p[i] == 0){
printf("YES\n%lld %d\n", x[1], i);
return 0;
}
}
printf("NO");
return 0;
}

D. Beautiful Array

想到了对数列总和最大贡献,但是其实最大贡献不一定能最大化答案,于是惨遭\(WA10\)。

\(WA\)炸代码:

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 300010, INF = 2147483647;
typedef long long LL;
int n, x, L[N];
LL a[N], f[N];
int main(){
scanf("%d%d", &n, &x);
for(int i = 1; i <= n; i++)
scanf("%lld", a + i); if(x < 0){
f[1] = a[1];
L[1] = 1;
LL minn = f[1];
int k = 1;
for(int i = 2; i <= n; i++) {
if(f[i - 1] + a[i] < a[i]){
L[i] = L[i - 1];
f[i] = f[i - 1] + a[i];
}else{
L[i] = i;
f[i] = a[i];
} if(f[i] < minn){
minn = f[i], k = i;
}
}
if(minn < 0){
for(int i = L[k]; i <= k; i++)
a[i] *= x;
}
}else{ f[1] = a[1];
L[1] = 1;
LL maxn = f[1];
int k = 1;
for(int i = 2; i <= n; i++) {
if(f[i - 1] + a[i] > a[i]){
L[i] = L[i - 1];
f[i] = f[i - 1] + a[i];
}else{
L[i] = i;
f[i] = a[i];
} if(f[i] > maxn){
maxn = f[i], k = i;
}
}
if(maxn > 0){
for(int i = L[k]; i <= k; i++)
a[i] *= x;
} } f[1] = a[1];
LL maxn = f[1];
for(int i = 2; i <= n; i++){
f[i] = max(f[i - 1] + a[i], a[i]);
maxn = max(maxn, f[i]);
}
printf("%lld\n", max(maxn, 0ll));
return 0;
}

看了题解直接自闭掉,实际上,可以设

\(f[0]\)为当前以\(i\)为右端点,未加入\(x\)的极大值,那么它必须大于\(0\)

\(f[1]\)代表开始连续计算\(* x\)了,如果这时候还没有\(f[0]\)大,那么它也没用了

\(f[2]\)代表乘完了的,探究是否还能再加入\(a[i]\)

如果\(x > 0\),那么\(f[2] + a[i]\)一定不会最优

如果\(x < 0\),有可能有这种情况,前面负数后面正数

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 300010, INF = 2147483647;
typedef long long LL;
int n, x, L[N];
LL a[N], f[3], ans = 0;
int main(){
scanf("%d%d", &n, &x);
for(int i = 1; i <= n; i++)
scanf("%lld", a + i); for(int i = 1; i <= n; i++){
f[0] = max(f[0] + a[i], 0ll);
f[1] = max(f[0], f[1] + a[i] * x);
f[2] = max(f[1], f[2] + a[i]);
ans = max(ans, f[2]);
}
printf("%lld\n", ans);
return 0;
}

E. Guess the Root

高斯消元\(/\)拉格朗日插值法都不会,咕咕咕。

Codeforces Edu Round 63 A-E的更多相关文章

  1. Codeforces Beta Round #63 (Div. 2)

    Codeforces Beta Round #63 (Div. 2) http://codeforces.com/contest/69 A #include<bits/stdc++.h> ...

  2. codeforces水题100道 第九题 Codeforces Beta Round #63 (Div. 2) Young Physicist (math)

    题目链接:http://www.codeforces.com/problemset/problem/69/A题意:给你n个三维空间矢量,求这n个矢量的矢量和是否为零.C++代码: #include & ...

  3. Codeforces Edu Round 63(Rated for Div. 2)

    感觉现在Edu场比以前的难多了…… A: 温暖人心 /* basic header */ #include <iostream> #include <cstdio> #incl ...

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

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

  5. [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 ...

  6. Educational Codeforces Round 63部分题解

    Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...

  7. Codeforces Beta Round #59 (Div. 2)

    Codeforces Beta Round #59 (Div. 2) http://codeforces.com/contest/63 A #include<bits/stdc++.h> ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

随机推荐

  1. c++ priority_queue应用(重要)

    自定义排序 重写仿函数 struct cmp{ bool operator() ( Node a, Node b ){//默认是less函数 //返回true时,a的优先级低于b的优先级(a排在b的后 ...

  2. python pip install指定国内源镜像

    有时候安装一些依赖包,网不好,直接超时,或者这个包就是死都下不下来的时候,可以指定国内源镜像. pip install -i 国内镜像地址 包名 e.g. pip install -i  http:/ ...

  3. 【java从入门到精通】day10-Java流程控制2-switch多选择结构

    1.switch多选择结构 switch case语句判断一个变量与一系列值中某个值是否相等,每个值称为一个分支. switch语句中的变量类型可以是: byte.short.int或者char 从j ...

  4. mon磁盘满重启的问题

    问题 Ceph monitors 100% full filesystem, refusing start 问题原文 I have an issue with a (not in production ...

  5. Guitar Pro 7 中文界面的介绍

    用过Guitar Pro这款软件的小伙伴们都知道,Guitar Pro这款吉他软件因为是国外开发商研发的,所以软件最初都是英文版本,对于国内的的吉他爱好者来说,在软件使用上还是很不方便的.随着Guit ...

  6. ABBYY FineReader 与尚书七号OCR的对比

    ABBYY FineReader 与尚书七号OCR都是帮助我们识别文字的工具,使用的都是OCR技术,如今文字识别工具是我们学习和工作经常会使用的,它们的功能是否实用和好用?现在通过对比的方式来探讨. ...

  7. 将多个PDF文件整合成一个文件

    pdfFactory不仅可以将单个文件创建为PDF文件进行打印,还可以将多个文件整合为一个PDF文件,同时,也可以随时删除其中的一些文件,创建新的PDF文件. 图1:pdfFactory工具界面 一. ...

  8. 用过MindManager后才知道思维导图原来这么简单

    哈喽大家好!时间过得真是太快了,一眨眼这一年就接近尾声了,相信我们都度过了不平凡但十分充足的一年,不知道大家在2020年中有没有令自己满意的收获呢? 相信大家各自都有精彩的收获,我们不妨把它们总结一下 ...

  9. python搭建本地共享文件服务器

    1.安装python 去官网下载python最新版,然后安装配置好环境 2.运行命令 在终端上输入以下命令 python3 -m http.server 当你执行完这个命令的时候,你的电脑会监听 80 ...

  10. Non Super Boring Substring 题解(hash+思维)

    题目链接 题目大意 给你一个长度为d(d<=1e5)的字符串,要你求有多少个子串满足这个子串不包含长度大于等于k的回文子串 题目思路 首先可以hash预处理,然后O(1)用前缀hash值和后缀h ...