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;
}

最新文章

  1. Android 笔记 文件存取 day5
  2. linux mail利用外部邮箱地址发邮件
  3. [tmp] hu60@所有人插件
  4. UWP开发笔记——嵌套式页面的实现
  5. 使用SharedPreferences进行简单的储存
  6. C/C++ 跨平台交叉编译、静态库/动态库编译、MinGW、Cygwin、CodeBlocks使用原理及链接参数选项
  7. 遍历nsarray
  8. phpcms V9 首页模板文件解析(转)
  9. struts2-core-2.1.6.jar!/struts-default.xml无法加载的问题
  10. Android通过HTTP协议实现上传文件数据
  11. 学HTTP协议所要知道的基础知识(微总结)
  12. js 学习之路9:运算符
  13. jupyter4.4.0自定义目录
  14. 文件服务器HFS
  15. Codeforces 1043 F - Make It One
  16. 用R的dgCMatrix包来构建稀疏矩阵 | sparse matrix by dgCMatrix
  17. 在Linux中以普通用户开机自动运行脚本程序
  18. 关于Unity中的光照(二)
  19. APICloud-端JS库功能API文档(1)
  20. python json.loads json.dumps(ensure_ascii = False) 汉字乱码问题解决

热门文章

  1. LRU hashMap(拉链) + 双向链表 java实现
  2. go语言设计模式之proxy
  3. 2个ajax的相互调用解决异步问题
  4. WPF (DataGridRowHeaderStyle)实现自义定行样式 并绑定数据
  5. ESA2GJK1DH1K升级篇: STM32远程乒乓升级,基于Wi-Fi模块AT指令TCP透传方式,MQTT通信控制升级(含有数据校验)-APP用户程序制作过程
  6. cartographer 3D运行录制rosbag包
  7. Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水题
  8. python-pandas读取mongodb、读取csv文件
  9. SQL Server设置数据库为状态为只读
  10. 05爬虫-requests模块基础(2)