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 ...
随机推荐
- Git 在小团队中的管理流程
目标读者:了解 Git 的基本概念,能够使用 Git 进行基本的本地和远程操作. 有关 Git 的基础知识可以参见 知乎回答-怎样使用 GitHub?,天猪(刘勇)给出了一些很好的学习资料. 本文介绍 ...
- AcWing 836. 合并集合
地址 https://www.acwing.com/problem/content/838/ 一共有n个数,编号是1~n,最开始每个数各自在一个集合中. 现在要进行m个操作,操作共有两种: “M a ...
- Java Web 学习(3) —— MVC
MVC 一. MVC 模式 MVC 代表 Model-View-Controller (模型-视图-控制器) 模式. Model:模型代表 DAO (Data Access Object 数据访问对象 ...
- 2019 SDN上机第5次作业
2019 SDN上机第5次作业 1.浏览RYU官网学习RYU控制器的安装和RYU开发入门教程,提交你对于教程代码的理解,包括但不限于: 描述官方教程实现了一个什么样的交换机功能? 答:官方教程实现了一 ...
- 使用ArcPy拓扑检查的基本步骤
拓扑检查是GIS的特性,在ArcGIS可使用多种方法进行检查,包括: 1.在数据集上右键按向导建立: 2.使用拓扑工具箱的一系列工具分步建立: 3.创建模型工具,制作专门的拓扑工具: 4.利用ArcP ...
- Paper | PyTorch: An Imperative Style, High-Performance Deep Learning Library
目录 0. 摘要 1. 简介 2. 背景 3. 设计原则 4. 针对易用性的核心设计 4.1 让深度学习模块不过是Python程序 4.2 互用性和可拓展性 4.3 自动差分 5. 针对高性能的PyT ...
- Unity Settings Deamon crash in 16.04 every time after boot
安装ubuntu 16.04的时候,出现这样一个错误: unity-settings-deamon crashed with SIGSEGV in up_exported_dae (can't rea ...
- 大话设计模式Python实现-组合模式
组合模式(Composite Pattern):将对象组合成成树形结构以表示“部分-整体”的层次结构,组合模式使得用户对单个对象和组合对象的使用具有一致性. 下面是一个组合模式的demo: #!/us ...
- 由浅入深,讲解 spring 实战详细使用——spring 源码篇
首先,这篇文章不会详细的深入底层源码,只是基于注解和配置来说说我们的 spring 的使用,别小看基础,保证有你没用过的注解和配置,走起. 我们先来建立一个 maven 项目,引入 spring 文件 ...
- 安装 Java
1.rpm下载地址 https://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm?AuthParam=1570520 ...
