Codeforces Edu Round 63 A-E
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的更多相关文章
- Codeforces Beta Round #63 (Div. 2)
Codeforces Beta Round #63 (Div. 2) http://codeforces.com/contest/69 A #include<bits/stdc++.h> ...
- codeforces水题100道 第九题 Codeforces Beta Round #63 (Div. 2) Young Physicist (math)
题目链接:http://www.codeforces.com/problemset/problem/69/A题意:给你n个三维空间矢量,求这n个矢量的矢量和是否为零.C++代码: #include & ...
- Codeforces Edu Round 63(Rated for Div. 2)
感觉现在Edu场比以前的难多了…… A: 温暖人心 /* basic header */ #include <iostream> #include <cstdio> #incl ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- [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 ...
- Educational Codeforces Round 63部分题解
Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...
- Codeforces Beta Round #59 (Div. 2)
Codeforces Beta Round #59 (Div. 2) http://codeforces.com/contest/63 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- 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]中有多少个数 ...
随机推荐
- vscode remote wsl 的NoPermissions permission denied问题
在 wsl这个目录 code-insiders . 之后会报这个错 无法打开"wsl": Unable to read file (NoPermissions (FileSyst ...
- 基于FFmpeg的Dxva2硬解码及Direct3D显示(四)
初始化硬解码上下文 目录 初始化硬解码上下文 创建解码数据缓冲区 创建IDirectXVideoDecoder视频解码器 设置硬解码上下文 解码回调函数 创建解码数据缓冲区 这一步为了得到 LPDIR ...
- 适合 Go 新手学习的开源项目——在 GitHub 学编程
作者:HelloGitHub-小鱼干&卤蛋 故事要从 2007 年说起.因为受够了 C++ 煎熬的 Google 首席软件工程师 Rob Pike 召集 Robert Griesemer 和 ...
- 文本多行省略号(CSS最优方案)
Float定位溢出隐藏 优点: 纯CSS实现,性能好,不用js调优 兼容性高 多行省略,自动显示 缺点: 单词截断 代码如下: <div class="ellipses-div&quo ...
- 5G时代,URL Rewrite 还吃香吗
URL Rewrite是网站建设中经常用到的一项技巧,通过 rewrite 我们能够屏蔽服务器运行态的信息,包括服务的程序.参数等等,给用户呈现美化后的URL,同时对搜索引擎更加友好,方便我们网站的推 ...
- FL studio系列教程(十):FL Studio中如何新建样本
FL Studio中强调以样本为核心的编曲模式.样本其实就是一个小的音序片段,可以是单独的乐器或单独的打击乐,还可以是他们组合的一个小音序片段,它是我们学习编曲的最基础知识.所以本文主要为大家讲解的是 ...
- redis-cli 持久化,复制,哨兵,事务,流水线
一.持久化: 快照文件RDB 保存"开始"创建新快照一刻的内存快照,创建过程的内存变化不会被记录 创建快照的办法有几种 1.客户端可以通过想Redis发送BGSAVE来创建一个快照 ...
- IEEE浮点数标准
IEEE浮点数标准 阅读笔记:Computer System : A Programmmer's Perspective 基本概念 IEEE浮点数标准采用 \[V=(-1)^s\times M\tim ...
- 痞子衡嵌入式:一个奇怪的Keil MDK下变量链接强制对齐报错问题(--legacyalign)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是一个奇怪的Keil MDK下变量链接强制对齐报错问题. 痞子衡最近一直在参与恩智浦SBL项目(就是一个适用LPC和i.MXRT的完整OT ...
- Calendar类、 System类、 StringBulider类、 包装类
Calendar类 概念 java . util . Calendar 日历类,抽象类,在Date类后出现的,替换掉了很多Date类中的方法.该类将所有的可能用到的时间信息封装为静态成员变量. ...