Educational Codeforces Round 63部分题解
Educational Codeforces Round 63
A
题目大意就不写了.
挺简单的,若果字符本来就单调不降,那么就不需要修改
否则找到第一次下降的位置和前面的换就好了.
#include<iostream>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<queue>
using namespace std;
const int N = 3e5 + 3;
char s[N];
int n;
int x,y;
inline bool check(){
int last = -1;
for(int i = 1;i <= n;++i){
if(last > s[i]) {
x = i - 1,y = i;
return false;
}
last = s[i];
}
return true;
}
int main(){
scanf("%d",&n);
scanf("%s",s + 1);
if(check()) printf("NO\n");
else printf("YES\n%d %d\n",x,y);
return 0;
}
B
题目大意:给一个数字串,每个人可以轮流拿掉其中任何一个数字,串长为\(11\)(保证串长大于\(11\)且为奇数)时结束,这是如果开头为\(8\),则先手获胜,问先手是否有必胜策略
刚开始以为是个博弈论,推了\(20\)分钟,发现,我们设两人一共的操作次数为\(k\),能够影响答案的只有前\(k + 1\)个数,我们将\(8\)看作\(1\),非$8 $看作\(0\)
如果前\(k\)个数\(1\)比较多,那么先手必胜,因为后手拿不玩
反之如果\(0\)比较多,那么先手必败
如果一样多,则取决于第\(k + 1\)的数
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 3e5 + 3;
char s[N];
int n;
int main(){
scanf("%d",&n);
scanf("%s",s + 1);
bool flag = 1;
int need = (n - 11);
int sum1 = 0,sum2 = 0;
for(int i = 1;i <= need;++i)
if(s[i] == '8') sum1++;
else sum2++;
if(sum1 > sum2) printf("YES\n");
else if(sum1 < sum2) printf("NO\n");
else{
if(s[need + 1] == '8') printf("YES\n");
else printf("NO\n");
}
return 0;
}
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\)就好了
#include<cstdio>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
const int N = 3e5 + 3;
LL a[N],b[N];
inline LL read(){
LL v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int n,m;
inline LL gcd(LL x,LL y){
return y == 0 ? x : gcd(y,x % y);
}
int main(){
n = read(),m = read();
for(int i = 1;i <= n;++i) a[i] = read();
for(int i = 1;i <= m;++i) b[i] = read();
LL g = a[2] - a[1];
for(int i = 3;i <= n;++i) g = gcd(g,a[i] - a[i - 1]);
LL ans = -1;
for(int i = 1;i <= m;++i) if(g % b[i] == 0){
ans = i;
break;
}
if(ans == -1) puts("NO");
else{
puts("YES");
cout << a[1] << " " << ans << endl;
}
return 0;
}
D
题目大意给定\(x\)和一个数组\(a\),你可以选择一个区间将其所有元素乘\(x\)(当然也可以不乘),求乘完之后的最大字段和.
这道题不会不应该.
但这也告诉了我一个技巧,当仅可以选择一个区间进项操作,然后求答案是,用\(dp\)将状态分为操作前,操作中和操作后进行考虑
那么转移方程很明显了
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#define LL long long
using namespace std;
const int N = 3e5 + 3;
LL dp[N][3];
LL a[N];
int n;LL x;
int main(){
scanf("%d%I64d",&n,&x);
for(int i = 1;i <= n;++i) scanf("%I64d",&a[i]);
dp[1][0] = a[1],dp[1][1] = a[1] * x,dp[1][2] = a[1];
for(int i = 2;i <= n;++i){
dp[i][0] = max(a[i],dp[i - 1][0] + a[i]);
dp[i][1] = max(a[i] * x,max(dp[i - 1][1] + a[i] * x,dp[i - 1][0] + a[i] * x));
dp[i][2] = max(a[i],max(a[i] + dp[i - 1][2],a[i] + dp[i - 1][1]));
}
LL ans = 0;
for(int i = 1;i <= n;++i) ans = max(ans,max(dp[i][0],max(dp[i][1],dp[i][2])));
printf("%I64d\n",ans);
return 0;
}
Educational Codeforces Round 63部分题解的更多相关文章
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 64 部分题解
Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...
- [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 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- 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 ...
- Educational Codeforces Round 63 (Rated for Div. 2) D dp(最大连续子序列)
https://codeforces.com/contest/1155/problem/D 题意 一个n个数的数组\(a[i]\),可以选择连续的一段乘x,求最大连续子序列的值 题解 错误思路:贪心, ...
- Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array (简单DP)
题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: ...
- Educational Codeforces Round 63 选做
D. Beautiful Array 题意 给你一个长度为 \(n\) 的序列.你可以选择至多一个子段,将该子段所有数乘上给定常数 \(x\) .求操作后最大的最大子段和. 题解 考虑最大子段和的子段 ...
- Educational Codeforces Round 16---部分题解
710A. King Moves 给你图中一点求出它周围有几个可达的点: 除边界之外都是8个,边界处理一下即可: #include<iostream> #include<cstdio ...
随机推荐
- java中的volatile和synchronized
关于volatile和同步相关的东西,网上有太多错误和解释不清的东西, 所以查阅相关书籍和文章后总结如下, 如果还是也存在不正确的内容,请一定要指出来, 以免误人子弟:) 1. 原子性与可视性 原子性 ...
- Notepad++中Python脚本运行出现语法错误:IndentationError: unindent does not match any outer indentation level
使用Notepad++编辑python代码运行遇到了这个问题: IndentationError: unindent does not match any outer indentation leve ...
- Libevent:5events相关
Libevents的基本操作单元是event,每一个event代表了一些条件的集合,这些条件包括: 文件描述符已经准备好读或写 文件描述符正在变为就绪,准备好读或写(仅限于边沿触发) 超时事件 信号发 ...
- 关于redis的问题:RedisException with message read error on connection
最近碰到在REDIS执行一步get操作的时候报出错误:Uncaught RedisException: read error on connection,感觉不可理解,REDIS连接没有发现问题,但是 ...
- Warning!程序员们小心被技术绑架
通常我们说程序员需要在某个技术方向上积累到一定的厚度,要能够运用技术有效地解决实际问题.可是当程序员在某一项技术上浸淫时间长了之后,却经常会出现另外的问题,那就是:看待问题时受限于自身的技术积累. 我 ...
- 跳出手掌心--如何立即触发UIButton边界事件
http://www.cocoachina.com/ios/20150611/12082.html 最近在使用UIButton的过程中遇到一个问题,我想要获得手指拖动button并离开button边界 ...
- oracle函数 TO_DATE(X[,c2[,c3]])
[功能]将字符串X转化为日期型 [参数]c2,c3,字符型,参照to_char() [返回]字符串 如果x格式为日期型(date)格式时,则相同表达:date x 如果x格式为日期时间型(timest ...
- oracle函数 decode(条件,值1,翻译值1,值2,翻译值2,...值n,翻译值n,缺省值)
[功能]根据条件返回相应值 [参数]c1, c2, ...,cn,字符型/数值型/日期型,必须类型相同或null 注:值1……n 不能为条件表达式,这种情况只能用case when then end解 ...
- oracle函数 SUBSTR(c1,n1[,n2])
[功能]取子字符串 [说明]多字节符(汉字.全角符等),按1个字符计算 [参数]在字符表达式c1里,从n1开始取n2个字符;若不指定n2,则从第y个字符直到结束的字串. [返回]字符型 [示例] SQ ...
- Python基础:常用函数
1:enumerate enumerate(sequence, start=0) 该函数返回一个enumerate对象(一个迭代器).其中的sequence参数可以是序列.迭代器或者支持迭代的其他对象 ...