Codeforces 1244F. Chips
显然可以注意到连续的两个相同颜色的位置颜色是不会改变的,并且它还会把自己的颜色每秒往外扩展一个位置
同时对于 $BWBWBW...$ 这样的序列,它每个位置的颜色每一秒变化一次
然后可以发现,对于一个位置 $x$,在 $x$ 左边和右边 连续两个相同颜色 扩展到 $x$ 之前, $x$ 的颜色一定是每秒变化一次
考虑每个位置 $x$ 第 $k$ 秒时的颜色,如果 $x$ 初始往 左或者往右的连续两个相同颜色 扩展到 $x$ 的时间都大于 $k$ ,那么我们可以通过 $k$ 的奇偶性和 $x$ 的初始颜色 求出最终的颜色
如果 $x$ 初始往左或者往右的 连续两个相同颜色 扩展到 $x$ 的时间小于 $k$ ,那么需要时间比较小的那边就会先把 $x$ 同化
所以我们可以通过预处理出每个位置往左和往右第一个 连续两个相同颜色 来判断每个位置最终的颜色
实现看代码吧
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e5+;
int n,m,L[N],R[N];
char s[N],ans[N];
vector <int> pos;
bool vis[N];
int main()
{
n=read(),m=read();
scanf("%s",s+);
for(int i=;i<=n;i++)
{
int l=(i+n-)%n+,r=i%n+;
if(s[l]==s[i]||s[r]==s[i]) pos.push_back(i),vis[i]=;
}
int len=pos.size();
if(!len)
{
for(int i=;i<=n;i++)
ans[i]= (s[i]=='W' ^ (m&)) ? 'W' : 'B';
for(int i=;i<=n;i++) printf("%c",ans[i]); puts("");
return ;
}
int las=pos[len-];
for(int i=;i<=n;i++)
if(vis[i]) las=i;
else L[i]=las;
las=pos[];
for(int i=n;i>=;i--)
if(vis[i]) las=i;
else R[i]=las;
for(int i=;i<=n;i++)
{
if(vis[i]) { ans[i]=s[i]; continue; }
int Ld=(i-L[i]+n)%n,Rd=(R[i]-i+n)%n;
if(min(Ld,Rd)>m)
ans[i]= (s[i]=='W' ^ (m&)) ? 'W' : 'B';
else
ans[i]= (Ld<Rd) ? s[L[i]] : s[R[i]];
}
for(int i=;i<=n;i++) printf("%c",ans[i]); puts("");
return ;
}
Codeforces 1244F. Chips的更多相关文章
- Codeforces 1511G - Chips on a Board(01trie/倍增)
Codeforces 题面传送门 & 洛谷题面传送门 一道名副其实的 hot tea 首先显然可以发现这俩人在玩 Nim 游戏,因此对于一个 \(c_i\in[l,r]\) 其 SG 值就是 ...
- codeforces 333B - Chips
注意:横向纵向交叉时,只要两条边不是正中的边(当n&1!=1),就可以余下两个chip. 代码里数组a[][]第二维下标 0表示横向边,1表示纵向边. #include<stdio.h& ...
- Mango Weekly Training Round #3 解题报告
A. Codeforces 92A Chips 签到题.. #include <iostream> #include <cstdio> #include <cstring ...
- 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 ...
- Chips CodeForces - 333B
Chips CodeForces - 333B 题意:有一个n*n的棋盘,其中有m个格子被禁止.在游戏开始前要将一些芯片(?)放到四条边上(但不能是角上).游戏开始后,每次操作将每一个芯片移动到它四周 ...
- 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 #582 (Div. 3) A. Chips Moving
传送门 题解: 给你n个数的坐标,你需要把他们移动到一个位置,有两种移动方式 1.向左或者右移动2 2.向左或者右移动1,但是耗费1 求最小耗费 题解: 很简单就可以想到,看一下偶数坐标多还是奇数坐标 ...
- CodeForces 176C Playing with Superglue 博弈论
Playing with Superglue 题目连接: http://codeforces.com/problemset/problem/176/C Description Two players ...
- Codeforces Round 582
Codeforces Round 582 这次比赛看着是Div.3就打了,没想到还是被虐了,并再次orz各位AK的大神-- A. Chips Moving 签到题.(然而签到题我还调了20min--) ...
随机推荐
- docker打包项目部署
1.首先在本地安装docker,步骤可参考https://www.cnblogs.com/conswin/p/11055853.html 2.在对应项目目录下增加Dockerfile文件,其内容可参考 ...
- jetbrains 2019 激活 error 1653219 解决办法
我以前用PyCharm按照http://idea.lanyus.com/上的激活码直接可激活. 后来用到IDEA(最新版)了之后激活报错.错误代码为1653219. 后参考博客 解决办法: 把host ...
- Docker 数据管理(Volumes)
Docker 容器产生的数据在可写层,如果不通过 docker commit 生成新的镜像,使得数据成为镜像的一部分保存下来,那么当容器删除后,数据自然也就没有了. Docker 提供了三种数据 Mo ...
- koa 允许跨域
1.安装模块 npm install koa2-cors --save 2.引用 const cors = require('koa2-cors'); ... // 允许跨域访问 app.use(co ...
- ansiblle---roles
使用ansible中的roles来管理主机. 剧本中的roles你现在已经学过 tasks 和 handlers,那怎样组织 playbook 才是最好的方式呢?简单的回答就是:使用 roles ! ...
- [java]将秒数转化为“天时分秒”的格式(转贴+修改)
public class Time { // format seconds to day hour minute seconds style // Exmplae 5000s will be form ...
- 理解MyCat分库分表
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.
- LC 740. Delete and Earn
Given an array nums of integers, you can perform operations on the array. In each operation, you pic ...
- Oracle存储过程、游标、函数
SQL99是什么 (1)是操作所有关系型数据库的规则 (2)是第四代语言 (3)是一种结构化查询语言 (4)只需发出合法合理的命令,就有对应的结果显示 SQL的特点 (1)交互性强,非过程化 (2)数 ...
- selenium 等待时间
三种时间模式:1.隐性等待:①等待页面所有元素都加载完才执行下一步,如果在设定的时间内没有加载完成所有元素,则抛出异常②隐式等待对整个driver周期都起作用,即设置一次后,所有执行都会有效from ...