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 ...
随机推荐
- git rebase VS git merge
git rebase VS git merge 写在前面 如果你不能很好的应用 Git,那么这里为你提供一个非常棒的 Git 在线练习工具 Git Online(回复公众号「工具」,获取更多内容) , ...
- 2019暑期北航培训—预培训作业-IDE的安装与初步使用(Visual Studio版)
这个作业属于那个课程 2019北航软件工程暑期师资培训 这个作业要求在哪里 预培训-IDE的安装与初步使用(Visual Studio版) 我在这个课程的目标是 提高自身实际项目实践能力,掌握帮助学生 ...
- 【bcrypt】vue项目中bcrypt安装报错
[报错] 报错时安装方法: npm install bcrypt [解决方法] npm install bcryptjs 用 bcryptjs 替换 bcrypt 即可.
- Spring中声明式事务的注解@Transactional的参数的总结(REQUIRED和REQUIRES_NEW的与主方法的回滚问题)
一.事务的传播行为1.介绍 当事务方法被另一个事务方法调用时,必须指定事务应该如何传播.例如:方法可能继续在现有事务中运行,也可能开启一个新事务,并在自己的事务中运行.2.属性 事务的传播行为可以由传 ...
- java当中JDBC当中请给出一个sql server的helloworld例子
[学习笔记] 1.sql server的helloworld例子: import java.sql.*; public class JdbcHelloSqlServer { public stati ...
- CentOS 7.6出现SSH登录失败的解决方法
CentOS 7.6出现SSH登录失败的解决方案 问题重现: iterm登录 ssh vagrant@192.168.10.10 The authenticity of host '192.168.1 ...
- fputcsv 导出excel,解决内存、性能、乱码、科学计数法问题
在PHP的日常开发中,时常会需要导出 excel ,一般我们会使用 PHPExcel ,性能强大,但是在数据量大的时候,phpexcel 性能差.内存溢出等各种不可控问题就会出现.因此,如果对导出样式 ...
- Python中的if语句——参考Python编程从入门到实践
条件测试 1. 检查是否相等 一个等号表示赋值,两个等号用于判断等号左右两边是否相等,返回值为True或者False. 2. 检查是否相等是需考虑大小写 大小写不同的值视为不相等,例如继续写入代码:c ...
- 手工给程序插入 ShellCode
PE格式是 Windows下最常用的可执行文件格式,理解PE文件格式不仅可以了解操作系统的加载流程,还可以更好的理解操作系统对进程和内存相关的管理知识,而有些技术必须建立在了解PE文件格式的基础上,如 ...
- luogu P4887 莫队二次离线
珂朵莉给了你一个序列$a$,每次查询给一个区间$[l,r]$ 查询$l≤i<j≤r$,且$ai⊕aj$的二进制表示下有$k$个$1$的二元组$(i,j)$的个数.$⊕$是指按位异或. 直接暴力莫 ...