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. Netlink 内核实现分析 1

    Netlink 是一种IPC(Inter Process Commumicate)机制,它是一种用于内核与用户空间通信的机制,在一般情况下,用户态和内核态通信会使用传统的Ioctl.sysfs属性文件 ...

  2. 七:Redis的持久化

    1.RDB(Redis DataBase) 1.1 定义:在指定的时间间隔内将内存中的数据集快照写入磁盘,也就是行话讲的snapshot快照,他恢复时是将快照文件直接读到内存里 是什么:Redis会单 ...

  3. SpringBoot Redis切换数据库遇到的坑

    项目不同业务的redis数据存在不同的库中,操作数据需要切换redis库,在网上找了一段代码,确实可以切换数据库.但是使用一段时间后发现部分数据存储的数据库不正确,排查后发现setDatabase是线 ...

  4. ClickHouse数据库数据定义手记之数据类型

    前提 前边一篇文章详细分析了如何在Windows10系统下搭建ClickHouse的开发环境,接着需要详细学习一下此数据库的数据定义,包括数据类型.DDL和DML.ClickHouse作为一款完备的D ...

  5. 【转】Java工程师知识图谱

    一.Java工程师知识图谱(思维导图版) 二.Java工程师知识图谱(文字链接版) 专业基石 数据结构 数组 链表 队列 栈 哈希表 堆 树 图 BitMap 算法思想 排序 查找 分支算法 动态规划 ...

  6. netsniff使用

    1 netsniff安装与使用 首先直接下载源码包进行部署 安装一些前置包(安装完成的自动忽略) sudo apt install pkg-config sudo apt install libcli ...

  7. 在Camtasia中对录制视频进行转换编辑

    在我们的日常学习生活中,课件是我们经常需要接触的东西,一份精美的课件会让我们的学习生活看起来不那么的枯燥,学习也就不会索然无味.当精美的课件加上老师的谆谆教导,学习便会变成一件非常简单的事情.将课件制 ...

  8. 巧妙使用MindManager图像功能,能够让你的思维导图更精彩

    MindManager是一款多功能思维导图工具软件,有其他软件无法媲美的项目管理和商业规划高级功能.用户们制作思维导图时一定要注意图文并茂,单纯的文字会过于单调.所以接下来,小编就为大家详细介绍Min ...

  9. ABBYY FineReader 15 安装教程

    ABBYY FineReader 是一款出名的OCR文字识别工具,它包含文档转换.数据捕获等功能,文字识别率较高.能够带来快速.简单.易用的文字识别体验,从而提高工作效率.下面就为大家讲解ABBYY ...

  10. MathType在AutoCAD中的应用方法

    我们都知道CAD是一款鼎鼎有名设计与绘图软件,有不少朋友可能用过或听说过CAD,相较而言,用过MathType的人可能要少一些,虽然它也是理科生与工科生的专用工具之一. 通过MathType我们能够在 ...