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题解的更多相关文章

  1. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  2. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  3. Codeforces Round #604(Div. 2,

    // https://codeforces.com/contest/1265/problem/D /* 感觉像是遍历的思维构造题 有思路就很好做的 可以把该题想象成过山车或者山峰...... */ # ...

  4. 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 ...

  5. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  6. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  7. 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 ...

  8. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  9. Codeforces Round #604 (Div. 2) 部分题解

    链接:http://codeforces.com/contest/1265 A. Beautiful String A string is called beautiful if no two con ...

随机推荐

  1. June 30th, 2019. Week 26th, Sunday

    It's so easy to be careless, it takes courage and courage to care. 不在乎很容易,但在乎却需要很多勇气. Sometimes it w ...

  2. React 以两种形式去创建组件 类或者函数(二)

    08==>创建组件以 1类的形式 或者以 2函数的形式 09==>使用组件 在src下创建components文件夹 是放组件的 CompType.js 组件 组件开头大写(重要) Com ...

  3. windows下配置ngnix服务器经常出现503问题解决办法

    自己网站在windows server2008下安装的ngnix,然后配置php,网站访问流量并不大,但是经常出现503问题.经过查看ngnix服务器错误日志,发现: (10061: No conne ...

  4. 【Oracle】SQL的一些关键字

    1. distinct 关键词 DISTINCT 用于返回唯一不同的值: 只可以在select中使用: 既可以对一列,也可以对多列使用: distinct对NULL是不进行过滤的,即返回的结果中是包含 ...

  5. WPF 后台获得 数据模板里的内容控件(DataTemplate)

    原文:WPF 后台获得 数据模板里的内容控件(DataTemplate) 假如      <Window.Resources> 里 有一个 Datatemplate 我想获得TextBlo ...

  6. Luogu P5298 [PKUWC2018]Minimax

    好劲的题目啊,根本没往线段树合并方面去想啊 首先每种权值都有可能出现,因此我们先排个序然后一个一个求概率 由于此时数的值域变成\([1,m]\)(离散以后),我们可以设一个DP:\(f_{x,i}\) ...

  7. C# params 可变参数使用注意

    今天在一个 .NET Core 项目中调用一个自己实现的使用 params 可变参数的方法时触发了 null 引用异常,原以为是方法中没有对参数进行 null 值检查引起的,于是加上 check nu ...

  8. 参数检查(@property)

    绑定属性时,如果直接把属性暴露出去,虽然写起来很简单,但无法对参数进行检查,导致属性被随便修改 因此,可以通过在类内定义get()获取属性值,定义set()对属性值进行设定并对设定值进行检查 但通过定 ...

  9. IT兄弟连 Java语法教程 流程控制语句 循环结构语句1

    循环语句可以在满足循环条件的情况下,反复执行某一点代码,这段被重复执行的代码被称为循环体,当反复执行这个循环体时,需要在合适的时候把循环条件该为假,从而结束循环,否则循环将一直执行下去,形成死循环.循 ...

  10. 史上最全HashMap遍历方式

    java Hashmap Map TreeMap 的几种遍历方式,全网最全,全网最强 package Collec2; import java.util.HashMap; import java.ut ...