CF989B A Tide of Riverscape 思维 第七题
1 second
256 megabytes
standard input
standard output
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string ss of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer pp is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer pp is considered a period of string ss, if for all 1≤i≤|s|−p1≤i≤|s|−p, the ii-th and (i+p)(i+p)-th characters of ssare the same. Here |s||s| is the length of ss.
The first line contains two space-separated integers nn and pp (1≤p≤n≤20001≤p≤n≤2000) — the length of the given string and the supposed period, respectively.
The second line contains a string ss of nn characters — Mino's records. ss only contains characters '0', '1' and '.', and contains at least one '.' character.
Output one line — if it's possible that pp is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
10 7
1.0.1.0.1.
1000100010
10 6
1.0.1.1000
1001101000
10 9
1........1
No
In the first example, 77 is not a period of the resulting string because the 11-st and 88-th characters of it are different.
In the second example, 66 is not a period of the resulting string because the 44-th and 1010-th characters of it are different.
In the third example, 99 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them.
啊啊啊啊啊啊,简直了,佩服我自己,一个等于符号写成赋值符号,调半天bug
题意:给你n个字符串,问你每隔k个是否右不相等的,没有输出"No",有输出一个符合不相等的(注意‘.'可以是0或者1,所以输出的时候'.'是会根据前后的数字发生变化的)
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e6 + ;
const int mod = 1e9 + ;
typedef long long ll;
int main(){
std::ios::sync_with_stdio(false);
ll n, k;
while( cin >> n >> k ) {
string s;
cin >> s;
ll num;
bool flag = false;
for( ll i = ; i < s.length(); i ++ ) {
if( i + k < s.length() ) {
if( s[i] != s[i+k] || ( s[i] == s[i+k] && s[i] == '.' ) ) {
if( s[i] == s[i+k] ) {
s[i] = '', s[i+k] = '';
} else {
if( s[i] == '' ) {
s[i+k] = '';
} else if( s[i] == '' ) {
s[i+k] = '';
} else {
if( s[i+k] == '' ) { //这里等于号写成了赋值符号,调了半天bug,吐血ing
s[i] = '';
} else {
s[i] = '';
}
}
}
flag = true;
break;
}
}
}
if( flag ) {
for( ll i = ; i < s.length(); i ++ ) {
if( s[i] == '.' ) {
cout << "";
} else {
cout << s[i];
}
}
} else {
cout << "No";
}
cout << endl;
}
return ;
}
CF989B A Tide of Riverscape 思维 第七题的更多相关文章
- 《学习OpenCV》练习题第四章第七题abc
题外话:一直是打算把这本书的全部课后编程题写完的,中间断了几个月,一直忙于其他事.现在开始补上. 这道题我不清楚我理解的题意是不是正确的,这道题可以练习用OpenCV实现透视变换(可以用于矫正在3维环 ...
- 经典算法题每日演练——第七题 KMP算法
原文:经典算法题每日演练--第七题 KMP算法 在大学的时候,应该在数据结构里面都看过kmp算法吧,不知道有多少老师对该算法是一笔带过的,至少我们以前是的, 确实kmp算法还是有点饶人的,如果说红黑树 ...
- python在leecode刷题-第一题和第七题
class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] num ...
- 思维|蚂蚁感冒|2014年蓝桥杯A组题解析第七题-fishers
标题:蚂蚁感冒 长100厘米的细长直杆子上有n只蚂蚁.它们的头有的朝左,有的朝右. 每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒. 当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行. 这些蚂蚁中,有 ...
- CTF---Web入门第七题 猫抓老鼠
猫抓老鼠分值:10 来源: 实验吧 难度:难 参与人数:8697人 Get Flag:3740人 答题人数:3944人 解题通过率:95% catch!catch!catch!嘿嘿,不多说了,再说剧透 ...
- CTF---密码学入门第七题 杯酒人生
杯酒人生分值:10 来源: Veneno 难度:易 参与人数:2633人 Get Flag:790人 答题人数:963人 解题通过率:82% 使用古典密码 一喵星人要想喵星发送一段不知道干什么用的密码 ...
- LLLYYY的数字思维(模拟题)
链接:https://ac.nowcoder.com/acm/contest/318/G LLLYYY很喜欢写暴力模拟贪心思维.某一天在机房,他突然抛给了队友ppq一 个问题.问题如下: 有一个函数f ...
- 第一章-第七题( 有人认为,“中文编程”, 是解决中国程序员编程效率一个秘密武器,请问它是一个 “银弹” 么? )--By 侯伟婷
首先,“银弹”在百度百科中的解释是银色的子弹,我们更熟知的“银弹”一词,应该是在<人月神话>中提到的.银弹原本应该是指某种策略.技术或者技巧可以极大地提高程序员的生产力[1].此题目中关于 ...
- leetcode第七题Reverse Integer (java)
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, retu ...
随机推荐
- JDK的可视化工具系列 (四) JConsole、VisualVM
JConsole: Java监视与管理控制台 代码清单1: import java.util.*; public class JConsoleDemo { static class OOMObject ...
- prometheus-kafka-exporter部署
chart地址:https://gkarthiks.github.io/helm-charts/charts/prometheus-kafka-exporter/ 1.下载chart $ helm r ...
- MyBatis 核心配置综述之 ResultSetHandler
目录 ResultSetHandler 简介 ResultSetHandler 创建 ResultSetHandler 处理结果映射 DefaultResultSetHandler 源码解析 我们之前 ...
- 数据结构之堆栈java版
import java.lang.reflect.Array; /* 具体原理在c++版已经说的很清楚,这里不再赘述, 就提一点:java的泛型具有边界效应,一旦离开作用域立马被替换为object类型 ...
- Spring 集成Kafka(完整版)
前面的文章我们已经完成了Kafka基于Zookeeper的集群的搭建了.Kafka集群搭建请点我.记过几天的研究已经实现Spring的集成了.本文重点 jar包准备 集成是基于spring-integ ...
- 【linux】【qt5界面】【系统托盘图标的实现】
前言: 博主最近在做一个聊天软件,虽然技术不咋滴,但遇到点干货肯定是要跟大家分享的啦.下面就给大家分享一个qt实现程序隐藏才系统托盘的技巧. 装备: 系统:linux, qt版本:5.9.2,GCC: ...
- CodeForces 526D Om Nom and Necklace
洛谷题目页面传送门 & CodeForces题目页面传送门 给定字符串\(a\),求它的每一个前缀,是否能被表示成\(m+1\)个字符串\(A\)和\(m\)个字符串\(B\)交错相连的形式, ...
- 安装Windows Server 2008
下面介绍一下,Windows Server操作系统安装,以及在企业中的应用,在小型企业中可以使用不同的版本搭建不同类型的服务,小型企业中可以搭建Web服务,FTP服务,以及DNS和DHCP服务等,在大 ...
- 神盘GCCX,2019必撸大毛!
自从今年5月转型投资以来,已经很少薅羊毛了! 不是不撸,是因为一般的羊毛我真看不上! 撸羊毛能不能发财,能不能日入几百几千! 答案是,可以! 干羊毛,像趣步,云钱包,云比特,环保币,很多人都发财了!前 ...
- (17)ASP.NET Core EF基于数据模型创建数据库
1.简介 使用Entity Framework Core构建执行基本数据访问的ASP.NET Core MVC应用程序.使用迁移(Migrations)基于数据模型创建数据库,你可以在Windows上 ...