Codeforces Round #609 (Div. 2) C. Long Beautiful Integer
链接:
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的更多相关文章
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Codeforces Round #609 (Div. 2) A-E简要题解
contest链接:https://codeforces.com/contest/1269 A. Equation 题意:输入一个整数,找到一个a,一个b,使得a-b=n,切a,b都是合数 思路:合数 ...
- Codeforces Round #609 (Div. 2) 题解
Equation Modulo Equality Long Beautiful Integer Domino for Young K Integers Equation \[ Time Limit: ...
- 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 ...
- Codeforces Round #609 (Div. 2)
A题 给出n,求大于n的两个合数a和b,并且a-b = n 直接输出n的倍数即可 int n; int main() { cin >> n; cout << 9*n <& ...
- Codeforces Round #609 (Div. 2) A到C题
签到,乘以两个相邻的合数 #include<bits/stdc++.h> using namespace std; int main(int argc, char const *argv[ ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
随机推荐
- Jmeter + Ant 构建接口自动化
1.首先安装ANT,解压,建议放根目录. 对应安装包已上传 2.环境变量配置新建 ANT_HOMEANT_HOME:解压的路径path环境配置新增Path:%ANT_HOME%\binclasspat ...
- ubuntu 18.04 安装搜狗输入法
安装 fcitxsudo apt install fcitx 配置输入法打开fcitx配置界面,点击桌面左下角的菜单,弹出如下桌面: 点击: “Input Method”,进入设置界面 点击 “OK” ...
- [C语言]小知识点 持续更新
2019-11-24 1.如果输入: printf(,)); 会得到0: 这和我们的日常判断不相符! 然而,改成: printf(,)); 就可以成功输出“2”: 因此,注意pow函数返回的是浮点数, ...
- pytorch1.0神经网络保存、提取、加载
pytorch1.0网络保存.提取.加载 import torch import torch.nn.functional as F # 包含激励函数 import matplotlib.pyplot ...
- 【转帖】2019年中国5G行业细分市场发展现状和市场前景分析 通信基站数量快速增长
2019年中国5G行业细分市场发展现状和市场前景分析 通信基站数量快速增长 中国有 600多万个基站 平均每200个人 一个基站.. 一个基站十万块钱的话 相当于 每个人 需要分摊 500块钱. ht ...
- Hystrix【异常机制处理】
在之前的老版本中,feign中是默认开启hystrix的,从新版本中默认已经关闭了,如果要通过FeignClient调用服务并开启hystrix的话,需要自定义开启,即:feign.hystrix.e ...
- (十七)springMvc 对表单提交的日期以及JSON中的日期的参数绑定
文章目录 前言 `Ajax`提交表单数据 `Ajax`提交`JSON` 格式数据 解决输出JSON乱码的问题 控制JSON输出日期格式 小记 前言 springMVC 提供强大的参数绑定功能,使得我们 ...
- Windows Subsystem for Linux(wsl)使用
由于项目有一些环境需要在linux环境运行.可用微软win10的WSL来搭配使用 安装wsl 控制面板--程序和功能--启用或关闭windows功能,适用于linux的windows系统 应用商城下载 ...
- 基于UDP的编程
前提:基于Linux系统的学习 服务器端编程模型1 socket(2) 创建通讯端点,返回一个文件描述符fd2 bind(2) 将fd绑定到本地的地址和端口while(1){ 阻塞等待客户端请求数据的 ...
- teamviewer远程控制程序免费版百度云下载
TeamViewer是一个远程共享桌面软件,使远程传输变得简单快速,远程访问安全可靠,能在任何防火墙后台进行远程控制.只需用户在两台计算机上同时运行这个软件就可以开始工作.使用时关闭杀毒软件,防止误报 ...