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 ...
随机推荐
- Nginx 外的另一选择,轻量级开源 Web 服务器 Tengine 发布新版本
新版发布 近日,轻量级开源 Web 服务器 Tengine 发布了2.3.0版本,新增如下特性: ngx_http_proxy_connect_module,该模块让 Tengine 可以用于正向代理 ...
- 使用PHP类TCPDF生成PDF文档
转自:http://www.blhere.com/1180.html 这两天遇到一个项目中,需要php自动处理生成pdf文档.在网上找了好几个类,最后决定使用TCPDF,使用的时候真是发现这个类真是强 ...
- 集合--Set&&HashSet和TreeSet
特点:元素无序,不可重复 1.添加元素 set.add("tanlei"); set.addAll(Arrays.asList(44,"磊","磊&q ...
- javaScript之split与join的区别
共同点: split与join函数通常都是对字符或字符串的操作: 两者的区别: split() 用于分割字符串,返回一个数组,例如 var str="How are you doing to ...
- iOS 通知观察者的被调函数不一定运行在主线程
Tony in iOS | 08/08/2013 iOS 通知观察者的被调函数不一定运行在主线程 今天修复Bug时候发现的一个小细节,记录下. 问题描述 事情是这样的:我在A视图(UITableVie ...
- 2018-2-13-win10-uwp-获取按钮鼠标左键按下
title author date CreateTime categories win10 uwp 获取按钮鼠标左键按下 lindexi 2018-2-13 17:23:3 +0800 2018-2- ...
- Linux的 crontab定时任务小记
编辑任务 crontab -e 查看任务 crontab -l 任务配置基本格式:* * * * * command分(0-59) 时(0-23) 天(1-31) 月(1-12) 周(0-6,0代 ...
- ansible基础☞第一条命令
我的两个测试机: 系统: ubuntu 16.04.2 ansible-master: 192.168.0.107 ansible-slave: 192.168.0.108 ansible版本: ro ...
- oracle函数 MAX([distinct|all]x)
[功能]统计数据表选中行x列的最大值. [参数]all表示对所有的值求最大值,distinct只对不同的值求最大值,默认为all 如果有参数distinct或all,需有空格与x(列)隔开. [参数] ...
- @loj - 3039@ 「JOISC 2019 Day4」蛋糕拼接 3
目录 @description@ @solution@ @accepted code@ @details@ @description@ 今天是 IOI 酱的生日,所以她的哥哥 JOI 君给她预定了一个 ...