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--) ...
随机推荐
- antd源码分析之——标签页(tabs 1.组件结构)
由于ant Tabs组件结构较复杂,共分三部分叙述,本文为目录中第一部分(高亮) 目录 一.组件结构 antd代码结构 rc-ant代码结构 1.组件树状结构 2.Context使用说明 3.rc-t ...
- python —— 文本特征提取 CountVectorize
CountVectorize 来自:python学习 文本特征提取(二) CountVectorizer TfidfVectorizer 中文处理 - CSDN博客 https://blog.csdn ...
- [Mybatis]执行一句Sql返回一个List<String>
在Mapper.xml如下书写SQL文,其中 resultType告知MyBatis返回的类型: <select id="selectExpiredDate" resultT ...
- ubuntu如何删除刚添加的源?
答: sudo add-apt-repository -r <source_url> 如: sudo add-apt-repository -r ppa:linaro-maintainer ...
- Fragment向下兼容
* android-support-v4都用这个包里的类* 让activity继承FragmentActivity* 获取管理器 getSupportFragmentManager();
- RabbitMQ学习之:(九)Headers Exchange (转贴+我的评论)
From: http://lostechies.com/derekgreer/2012/05/29/rabbitmq-for-windows-headers-exchanges/ RabbitMQ f ...
- 九十:CMS系统之项目结构
目录结构 cms模块 from flask import Blueprint bp = Blueprint('cms', __name__, url_prefix='/cms') @bp.route( ...
- Java 8 新特性之 Stream 流基础体验
Java 8 新特性之 Stream 流基础体验 package com.company; import java.util.ArrayList; import java.util.List; imp ...
- 2019 Unreal Open Day —— 英特尔携手 UE 助力游戏开发生态建设
2019 年 5 月 8 日-5 月 9 日,一年一度的 Unreal Open Day 虚幻引擎技术开放日在上海举办,该活动由 Epic Games 中国倾力打造,是面向虚幻引擎开发者规格最高.规模 ...
- Leetcode之动态规划(DP)专题-714. 买卖股票的最佳时机含手续费(Best Time to Buy and Sell Stock with Transaction Fee)
Leetcode之动态规划(DP)专题-714. 买卖股票的最佳时机含手续费(Best Time to Buy and Sell Stock with Transaction Fee) 股票问题: 1 ...