Codeforces Round #487 (Div. 2)(A B C)

本文介绍了Codeforces Round #487 (Div. 2)比赛中的A、B、C三道题目。A题要求判断字符串中是否存在一个细胞能变为三种颜色,解题关键是检查连续三个字符是否包含ABC。B题询问能否通过转换'.'使字符串变为非周期循环数,解法是找不同或改变'.'。C题需构造特定联通块个数的图,作者采用了特定的构造方法。
摘要由CSDN通过智能技术生成

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值