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. JAVA跨域、RestTemplate高并发下异常与配置、JSON数据Long转String

    ## 跨域支持 import org.springframework.context.annotation.Bean; import org.springframework.context.annot ...

  2. MongoDB学习笔记(一、MongoDB入门)

    目录: 为什么要使用nosql mongo的简介 应用场景 入门demo 为什么要使用nosql: 随着互联网的发展,用户数量激增,访问量的上涨,传统的关系型数据库的性能也趋于瓶颈. 关系型数据库难以 ...

  3. Windows10 下利用Hyper-V安装CentOS系统

    开启Windows10的Hyper-v功能(需要重启电脑) 控制面板→程序→启用或关闭Windows功能→打开Hyper-v→确定 创建虚拟机 在Windows管理工具中找到Hyper-v管理器并双击 ...

  4. Paper | Attention Is All You Need

    目录 1. 动机详述 2. 相关工作 3. 转换器结构 3.1 注意力机制详解 3.1.1 放缩的点积注意力机制 3.1.2 多头注意力机制 3.2 全连接网络 3.3 编码位置信息 [这是一篇400 ...

  5. celery定时器

    Celery 1.什么是Clelery Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统 专注于实时处理的异步任务队列 同时也支持任务调度 Celery架构 Celery的架构由三部分组 ...

  6. Pandas入门系列(一)-- Series

    Series的创建 ##数据分析汇总学习 https://blog.csdn.net/weixin_39778570/article/details/81157884 # 使用列表创建 >> ...

  7. 实用小工具:VNC的安装

    安装xen时,需要使用vnc工具来进行图形化安装,安装好后启动失败,试了很多办法,最终解决. 1.使用yum安装:yum install tigervnc-server tigervnc-server ...

  8. Google工作法

    本文转自:https://www.yuque.com/heqingbao/msfy2c/zg56gm 这几天去上海参加Google开发者大会,利用空闲时间读了一本快餐书,书名叫<Google工作 ...

  9. SQL Server字符串函数STUFF的使用

    前言: 最近有个实践练习是将学生报名数据表student中的[st_id]字段的第二个和第三个字符删除,然后在此位置插入新的字符串“200900”,其实就是替换的意思,生成新的字符串. STUFF 函 ...

  10. Kettle实现从数据库中提取数据到Excel

    因为有个日常提数,工作日每天都要从数据库中提取数据,转换为excel,再以邮件的形式发给用户. 刚好近期同事在研究使用kettle自动提数且完成邮件的发送,觉得很实用又挺有意思的就学了一下这个技能~ ...