Codeforces Round #487 (Div. 2)
PS:没有FST的cf打的好舒服。。。
A题题意:给一个包含A,B,C,'.'的字符串,每个字符代表一个细胞,ABC分别代表三种颜色,每个细胞可以分裂使得两边的细胞染上自己的颜色,问是否存在一个细胞能变为三种颜色。
A题题解:直接判断连续三个字符满足任意顺序的ABC即可。hack点是连续的字符串如AABBCC输出no
AC代码:
/*
* @Author: 王文宇
* @Date: 2018-06-11 21:30:49
* @Last Modified by: 王文宇
* @Last Modified time: 2018-06-11 21:40:09
*/
#include <bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i=a;i<=b;i++)
const int maxn = 105;
char s[maxn];
int main(int argc, char const *argv[])
{
cin>>s;
int l = strlen(s);
_for(i,1,l-2)
{
if(s[i]=='A'||s[i]=='B'||s[i]=='C')
{
if(s[i-1]=='.'||s[i+1]=='.')continue;
if(s[i-1]!=s[i]&&s[i]!=s[i+1]&&s[i-1]!=s[i+1])
{
cout<<"Yes"<<endl;
return 0;
}
}
}
cout<<"No"<<endl;
return 0;
}
B题题意:给定N,P和一个包含0.1."."的字符串,可以将'.'转换为1或0,询问能否使字符串变为一个不是以p为周期的循环数。
B题题解:遍历只要找到一个不相同的即可,否则将'.'转换为和下一个周期的不相同的即可。hack点是全是.....的情况,hack了4个人。。。
AC代码:
/*
* @Author: 王文宇
* @Date: 2018-06-11 21:46:43
* @Last Modified by: 王文宇
* @Last Modified time: 2018-06-11 23:09:04
*/
#include <bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i=a;i<=b;i++)
const int maxn = 2005;
int n,p,a[maxn];
char s[maxn];
int main(int argc, char const *argv[])
{
cin>>n>>p>>s;
int ok = 0;
_for(i,0,n-1)
{
if(s[i]!='.')a[i]=s[i]-'0';
}
_for(i,0,n-p-1)
{
if(s[i]!=s[i+p])
{
ok=1;
if(s[i]=='.')
{
if(s[i+p]=='1')a[i]=0;
else a[i]=1;
}
else if(s[i+p]=='.')
{
if(s[i]=='1')
{
a[i]=1;
a[i+p]=0;
}
else
{
a[i]=0;
a[i+p]=1;
}
}
else
{
a[i]=s[i]-'0';
a[i+p]=s[i+p]-'0';
}
}
else if(s[i]=='.')
{
ok=1;
a[i]=1;
a[i+p]=0;
}
else
{
a[i]=s[i]-'0';
a[i+p]=s[i+p]-'0';
}
}
if(ok==0)cout<<"No";
else _for(i,0,n-1)cout<<a[i];
cout<<endl;
return 0;
}
C题题意:给定a,b,c,d四个整数,构造一个图使得联通块个数分别是a,b,c,d。
C题题解:构造的方法有很多。。我将ab分在25*60,cd分在25*50然后构造联通块即可。(C题拆分后和atc regular093的D相似)(链接:https://arc093.contest.atcoder.jp/tasks/arc093_b)
AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char m[25][50];
void solve(int a,int b)
{
--a;
--b;
for (int i = 0; i < 25 / 2; ++i) {
for (int j = 0; j < 50; ++j) {
m[i][j] = 'A';
}
}
for (int i = 25 / 2; i < 25; ++i) {
for (int j = 0; j < 50; ++j) {
m[i][j] = 'B';
}
}
for (int i = 1; i < 25 / 2; i += 2) {
for (int j = 1; j < 50; j += 2) {
if (a) {
m[i][j] = 'B';
--a;
}
}
}
for (int i = 25 / 2 + 1; i <25; i += 2) {
for (int j = 1; j < 50; j += 2) {
if (b) {
m[i][j] = 'A';
--b;
}
}
}
for (int i = 0; i < 25; ++i) {
for (int j = 0; j <50; ++j) {
cout << m[i][j];
}
cout << '\n';
}
}
void solve2(int a,int b)
{
--a;
--b;
for (int i = 0; i < 25 / 2; ++i) {
for (int j = 0; j < 50; ++j) {
m[i][j] = 'C';
}
}
for (int i = 25 / 2; i < 25; ++i) {
for (int j = 0; j < 50; ++j) {
m[i][j] = 'D';
}
}
for (int i = 1; i < 25 / 2; i += 2) {
for (int j = 1; j < 50; j += 2) {
if (a) {
m[i][j] = 'D';
--a;
}
}
}
for (int i = 25 / 2 + 1; i <25; i += 2) {
for (int j = 1; j < 50; j += 2) {
if (b) {
m[i][j] = 'C';
--b;
}
}
}
for (int i = 0; i < 25; ++i) {
for (int j = 0; j <50; ++j) {
cout << m[i][j];
}
cout << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<"50 50"<<endl;
solve(b,a);
solve2(d,c);
return 0;
}