Codeforces Round #604 (Div. 2) 练习A,B题解
A题

思路分析:
因为只需要做到相邻的不相同,利用三个不同的字母是肯定可以实现的,
所以直接先将所有的问号进行替换,比如比前一个大1,如果与后面的冲突,则再加一代码(写的很烂):
#include <bits/stdc++.h>
using namespace std;
int check( string a)
{
for (int i = 0; i < a.length(); ++i)
{
if (i==0)
{
if (a[i]==a[i+1])
{
return 0;
}
}
else if (a[i]==a[i-1])
{
return 0;
}
else{
if (a[i-1]==a[i]||a[i+1]==a[i])
{
return 0;
}
}
}
return 1;
}
int main(int argc, char const *argv[])
{
int t;
cin>>t;
string a;
while(t--)
{
cin>>a;
for (int i = 0; i < a.length(); ++i)
{
if (i==0)
{
if (a[i]=='?')
{
a[i]=((a[i+1]+1)%97)%3 + 97;
if (a[i]==a[i+1])
{
a[i] = ((a[i]+1)%97)%3+97;
}
}
}
else if (i==a.length()-1 )
{
if (a[i]=='?')
{
a[i]=((a[i-1]+1)%97)%3 + 97;
}
}
else
{
if (a[i]=='?')
{
a[i]=((a[i-1]+1)%97)%3 +97;
if (a[i] == a[i+1])
{
a[i]=((a[i]+1)%97)%3 +97;
}
}
}
}
if (check(a))
{
cout<<a<<endl;
}
else
cout<<"-1"<<endl;
}
return 0;
}
B题
思路分析:
如果有1到m的一个排列,那么肯定1到m的所有的数的位置最大值减去最小值的差是m-1
所以可以利用一个数组将pos信息存起来,从小到大遍历就可以代码:
#include <bits/stdc++.h>
using namespace std;
int pos[200001];
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int t;
int n;
cin>>t;
int k;
while(t--)
{
cin>>n;
for (int i = 0; i < n; ++i)
{
cin>>k;
pos[k-1] = i;
}
int maxpos = 0;
int minpos = n-1;
for (int i = 0; i < n; ++i)
{
minpos = min(minpos, pos[i]);
maxpos = max(maxpos, pos[i]);
cout<<(maxpos-minpos==i?1:0);
}
cout<<endl;
}
return 0;
}
Codeforces Round #604 (Div. 2) 练习A,B题解的更多相关文章
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #604(Div. 2,
// https://codeforces.com/contest/1265/problem/D /* 感觉像是遍历的思维构造题 有思路就很好做的 可以把该题想象成过山车或者山峰...... */ # ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors
链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) 部分题解
链接:http://codeforces.com/contest/1265 A. Beautiful String A string is called beautiful if no two con ...
随机推荐
- CentOS系统登陆root用户后发现提示符显示-bash-4.2#(已解决)
问题: 在root用户下终端显示,如图所示: 尝试退出登陆root用户依然不能解决 原因: root主目录下缺失.bash_profile和.bashrc文件 Tip: /etc/profile: 此 ...
- apache httpd反向代理的用法
代理方式有三种:正向代理.透明代理和反向代理 正向代理 httpd通过ProxyRequests指令配置正向代理的功能.例如: ProxyRequests On ProxyVia On <Pro ...
- webdriver-键盘操作 for java
2017年01月17日 17:08:25 阅读数:2044 import java.awt.AWTException;import java.awt.Robot;import java.awt.eve ...
- 移位寄存器及verilog代码
通用移位寄存器 作用:后续补全 )( :] Data_out, output MSB_out, LSB_out, :] Data_in, input MSB_in, LSB_in, input s0, ...
- react的this.setState中的坑
react的this.setState中的有两个. 1.this.setState异步的,不能用同步的思维讨论问题 2.在进行组件通讯的回调的时候,this指向子组件,没有指向父亲这,怎么办呢.在 c ...
- 参数检查(@property)
绑定属性时,如果直接把属性暴露出去,虽然写起来很简单,但无法对参数进行检查,导致属性被随便修改 因此,可以通过在类内定义get()获取属性值,定义set()对属性值进行设定并对设定值进行检查 但通过定 ...
- css的伪元素 ::after ::before 和 图标字体的使用
浅谈css的伪元素::after和::before css中的::after和::before已经被大量地使用在我们日常开发中了,使用他们可以使我们的文档结构更加简洁.但是很多人对::after和 ...
- Saiku默认给数据类型的数据添加小数点问题处理(三十一)
Saiku默认给数据类型的数据添加小数点问题处理 不知道大家有没有遇到过saiku定义的维度信息,数据类型时 展示出来的数据会自动加上 .0的后缀. 比如我定义了一个维度为 年, 在数据库中为 int ...
- IT兄弟连 HTML5教程 HTML5的学习线路图 第二、三阶段
第二阶段编写用户交互功能 通过第一阶段的学习虽说可以完成页面制作,但并不完美,不能算是合格的前端工程师,所以要继续学习如图1.13中的第二阶段内容.现在的Web页面都融入了大量的特效,并且多数需要与用 ...
- redis安装等其他操作
重启:./redis-server或者 ./redis-server redis.conf ps -ef|grep redis 得到了进程号 xxxx 然后 ls -l /proc/xxxx/cwd ...
