链接:

https://codeforces.com/contest/1269/problem/C

题意:

You are given an integer x of n digits a1,a2,…,an, which make up its decimal notation in order from left to right.

Also, you are given a positive integer k<n.

Let's call integer b1,b2,…,bm beautiful if bi=bi+k for each i, such that 1≤i≤m−k.

You need to find the smallest beautiful integer y, such that y≥x.

思路:

记录前k个,模拟比大小,要修改值的时候从后往前选第一个不是9的字符修改,同时把9修改为0

代码:

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10; int n, k;
char num[MAXN], ans[MAXN]; bool Check()
{
for (int i = k;i < n;i++)
{
if (num[i] < ans[i%k])
return true;
if (num[i] > ans[i%k])
return false;
}
return true;
} int main()
{
scanf("%d%d", &n, &k);
scanf("%s", num);
for (int i = 0;i < k;i++)
ans[i] = num[i];
ans[k] = 0;
if (Check())
{
printf("%d\n", n);
for (int i = 0;i < n;i++)
printf("%c", ans[i%k]);
printf("\n");
return 0;
}
for (int i = k-1;i >= 0;i--)
{
if (ans[i] != '9')
{
ans[i]++;
break;
}
else
ans[i] = '0';
}
printf("%d\n", n);
for (int i = 0;i < n;i++)
printf("%c", ans[i%k]);
printf("\n"); return 0;
}

Codeforces Round #609 (Div. 2) C. Long Beautiful Integer的更多相关文章

  1. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  2. Codeforces Round #609 (Div. 2) A-E简要题解

    contest链接:https://codeforces.com/contest/1269 A. Equation 题意:输入一个整数,找到一个a,一个b,使得a-b=n,切a,b都是合数 思路:合数 ...

  3. Codeforces Round #609 (Div. 2) 题解

    Equation Modulo Equality Long Beautiful Integer Domino for Young K Integers Equation \[ Time Limit: ...

  4. Codeforces Round #609 (Div. 2) D. Domino for Young

    链接: https://codeforces.com/contest/1269/problem/D 题意: You are given a Young diagram. Given diagram i ...

  5. Codeforces Round #609 (Div. 2)

    A题 给出n,求大于n的两个合数a和b,并且a-b = n 直接输出n的倍数即可 int n; int main() { cin >> n; cout << 9*n <& ...

  6. Codeforces Round #609 (Div. 2) A到C题

    签到,乘以两个相邻的合数 #include<bits/stdc++.h> using namespace std; int main(int argc, char const *argv[ ...

  7. Codeforces Round #609 (Div. 2) 【A,B,C】

    题意:给一个n<=1e7,找两个合数a和b使得a-b的差为n. 构造a=3n,b=2n,必含有公因子n,只有当n是1的时候是特例. #include<bits/stdc++.h> u ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

随机推荐

  1. dotnet core use Redis to publish and subscribe

    安装Redis 同样我这边再次使用Docker, 方便快捷: # 拉取镜像 docker pull redis # 运行镜像 docker run -d -p 6379:6379 --name red ...

  2. [数据库]简单SQL语句总结

    1.在查询结果中显示列名:a.用as关键字:select name as '姓名'   from students order by ageb.直接表示:select name '姓名'   from ...

  3. 剪切板工具:Ditto

    DittoClipboard manager; 剪贴板工具https://ditto-cp.sourceforge.io/ 参考资料 https://www.liutf.com/posts/37207 ...

  4. ~ubuntu1804安装禅道

    一.解压禅道安装包 二.启动禅道 # 开启Apache和Mysql服务 /opt/zbox/zbox start # 停止Apache和Mysql服务 /opt/zbox/zbox stop # 命令 ...

  5. python技巧 — Chrome浏览器中的 XPath Helper

    用于XPath 爬取网页结构的时候使用, 安装后 快捷键调用 左边 ctrl+ shift+x 启动 安装流程: 1. 打开chrome浏览器,扩展程序 .搜索 XPath Helper 下载安装(前 ...

  6. mouseover mouseleave

    mouseover在当鼠标移入元素或其子元素的时候都会触发,是一个重复触发,冒泡的过程.见下面例子,一个父元素包含一个子元素,在其父元素内滑动鼠标,超出子元素的范围时,也会触发事件. 而mouseen ...

  7. [BZOJ3681]Arietta(可持久化线段树合并优化建图+网络流)

    暴力建图显然就是S->i连1,i->j'连inf(i为第j个力度能弹出的音符),j'->T连T[j]. 由于是“某棵子树中权值在某区间内的所有点”都向某个力度连边,于是线段树优化建图 ...

  8. asp.net后台或前端获取TemplateField绑定的文本

    GridView中使用最多的一个是BoundField,还有一个是TemplateField 这两个各有其特点,BoundField的话比较简单,设置好DataField.HeaderText等就可以 ...

  9. 微信小程序 swiper 组件坑

    swiper 组件高度被限制为150px了,所以内容无法撑开. 解决办法 给这组件重新设置个高度,然后在把里面的图片设置为自动适应容器大小.图片模式设置为 宽度不变 自动适应高度 <swiper ...

  10. Topics in CS(difference between compile and interpret)

    编译 Compile:把整个程序源代码翻译成另外一种代码,然后等待被执行,发生在运行之前,产物是「另一份代码」. 解释 Interpret:把程序源代码一行一行的读懂然后执行,发生在运行时,产物是「运 ...