CF1244F Chips
problem
有一个长度为\(n\)个点连成的环。每个点为黑色或白色。当一个点和与他相邻的两个点颜色不同时。该点的颜色就会改变。
问改变\(K\)次后每个点的颜色。
solution
发现两个性质:
1.发现如果一个点在第一次时就不需要改变。那么他以后都不需要改变。
2.如果有个点在某次不需要改变,那么下一次他相邻的两个点也一定不需要改变。
所有思路就很明显了。从不需要改变的点开始\(bfs\)。得到每个点最早不需要改变的时间。然后与\(K\)取\(min\)后计算出最终颜色就行了。
code
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
const int N = 200010;
ll read() {
ll x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;c = getchar();
}
while(c >= '0' && c <= '9') {
x = x * 10 + c - '0';c = getchar();
}
return x * f;
}
char s[N];
int vis[N];
queue<int>q;
int main() {
int n = read(),K = read();
scanf("%s",s);
memset(vis,-1,sizeof(vis));
for(int i = 0;i < n;++i) {
if(s[i] != s[(i - 1 + n) % n] && s[i] != s[(i + 1) % n]);
else {
q.push(i),vis[i] = 0;
}
}
while(!q.empty()) {
int u = q.front();q.pop();
if(vis[(u - 1 + n) % n] == -1) {
vis[(u - 1 + n) % n] = vis[u] + 1;q.push((u - 1 + n) % n);
}
if(vis[(u + 1) % n] == -1) {
vis[(u + 1) % n] = vis[u] + 1;q.push((u + 1) % n);
}
}
for(int i = 0;i < n;++i) {
if(vis[i] == -1 || vis[i] > K) {
if(K & 1) putchar(s[i] == 'B' ? 'W' : 'B');
else putchar(s[i]);
}
else {
if(vis[i] & 1) putchar(s[i] == 'B' ? 'W' : 'B');
else putchar(s[i]);
}
}
return 0;
}
CF1244F Chips的更多相关文章
- some problem
CF1257F Make Them Similar $solution:$ 折半搜索后考虑如何维护两个数组的和,可以将 $A$ 中每个数减 $A_1$ ,$B$ 中每个数被减 $B_1$ ,$map$ ...
- 【UVALive - 5131】Chips Challenge(上下界循环费用流)
Description A prominent microprocessor company has enlisted your help to lay out some interchangeabl ...
- Codeforces Round #194 (Div. 2) D. Chips
D. Chips time limit per test:1 second memory limit per test:256 megabytes input:standard input outpu ...
- Codeforces Round #194 (Div. 1) B. Chips 水题
B. Chips Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/B D ...
- [2011WorldFinal]Chips Challenge[流量平衡]
Chips Challenge Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- A - Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells ...
- Chips CodeForces - 333B
Chips CodeForces - 333B 题意:有一个n*n的棋盘,其中有m个格子被禁止.在游戏开始前要将一些芯片(?)放到四条边上(但不能是角上).游戏开始后,每次操作将每一个芯片移动到它四周 ...
- [译]Cookies Without Chocolate Chips
Cookies Without Chocolate Chips In the HTTP sense, a cookie is a name with an associated value. A se ...
- Angular Material 学习笔记 Chips
依据 material guidelines, chips 可以用来做 filter https://material.io/design/components/chips.html#filter-c ...
随机推荐
- Effect:Mobile ocd
Satisfy the following two Keep your phone at all times Check your phone even if there's no news Alwa ...
- MySQL数据库~~~~~创建用户和授权、备份和还原
一 MySQL创建用户和授权 1.1 对新用户增删改 1.创建用户: # 指定ip:192.118.1.1的chao用户登录 create user 'chao'@'192.118.1.1' iden ...
- 005.SQLServer AlwaysOn可用性组高可用简介
一 AlwaysOn 可用性组 1.1 AlwaysOn 可用性组概述 AlwaysOn 可用性组功能是一个提供替代数据库镜像的企业级方案的高可用性和灾难恢复解决方案.SQL Server 2012 ...
- 《HTTPS权威指南》读书笔记——SSL/TLS协议
记录协议(record protocol) 负责在传输连接上交换所有底层信息 每一条记录以短标头开始,标头包含记录内容的类型.协议版本和长度 握手协议(handshake protocol) 整个过程 ...
- 权限控制终于来了!Redis 6.0新特性——ACLs
在2019年纽约的Redis Day上,Salvatore Sanfilippo(AKA Antirez)介绍了即将发布的Redis 6.0的新特性.以下是关于ACLs的内容. ACLs简介 在过去的 ...
- 调试seanbell/intrinsic遇到的坑
那些遗忘过去的人注定要重蹈覆辙.——乔治•桑塔亚纳 Authorized error 刚开始按作者 GitHub 上的指示,当运行环境配置好,并且 make 之后,因为生成的 decompose.p ...
- MVC邮箱验证
post请求 [HttpPost] public void Email(Models.Email m,string Txt) { if (Txt!= Session["yzm"]. ...
- 操作系统篇之Linux命令操作和redis安装以及基本使用
电脑操作系统 : windows7,8,10,xp,win98 操作系统 : linux ax unix 以后开发项目是部署在服务器上,服务器一般采用linux. linux的优点:系统稳定,操作速度 ...
- C#中实现文件重命名的方式
场景 在C#中如果是删除文件的话可以直接使用 if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } 但是如 ...
- .Net Core MVC理解新管道处理模型、中间件
.Net Core中间件官网:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/middleware/?view=aspnetcore ...