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 ...
随机推荐
- 乐字节Java继承|方法重写、super和final关键字
大家好,乐字节的小乐又来了,上一篇是:乐字节Java|JavaBean.继承与权限修饰,也是属于Java继承的,今天继续Java继承. 一. 方法的重写 父类不满足子类的要求,按需改写.注意 方法签名 ...
- [转帖]新iPhone的黑科技:UWB技术揭秘
新iPhone的黑科技:UWB技术揭秘 http://blog.nsfocus.net/iphone-black-technology-uwb-technology-revealed/ 阅读: ...
- Java串口通信 RXTX 解决过程
背景介绍: 由于第一次用Java与硬件通信,网上查了许多资料,在这进行整理,便于以后学习.本人串口测试是USB串口设备连接电脑,在设备管理器中找到端口名称(也可以通过一些虚拟串口工具模拟). 下面主要 ...
- java FastJson的使用总结
1.前言 1.1.FastJson的介绍: JSON(javaScript Object Notation)是一种轻量级的数据交换格式.主要采用键值对({"name": " ...
- Python进阶:生成器--懒人版本的迭代器
从容器.可迭代对象谈起 所有的容器都是可迭代的(iterable),迭代器提供了一个next方法.iter()返回一个迭代器,通过next()函数可以实现遍历. def is_iterable(par ...
- netty--处理器
编解码器的基类: 编码:MessageToByteEncode 解码:ByteToMessageDecoder
- 用ASP.NET Web API技术开发HTTP接口(一)
开发工具 Visual Studio 2013 SQL Server 2008 R2 准备工作 启动Visual Studio 2013,新建一个ASP.NET Web应用程序,命名为SimpleAP ...
- Bigdecimal除法异常
1.异常信息摘要(详细请见文末): java.lang.ArithmeticException: Non-terminating decimal expansion; no exact represe ...
- swift 有哪些学习资源
Swift有哪些优秀的学习资源呢? 首先要推荐的当然是官方的资料了. 这个地址里放的是苹果官方为开发者提供的Swfit学习资源:https://developer.apple.com/swift/re ...
- 关于Vue-ElementUI修改默认样式不成功问题解决
Element是一个很好用的组件库,但是有时候我们需要修改一些组件的样式以满足我们自己的需求. 我们用浏览器调试找到相应的class,在本地重写这个class时,发现修改不成功. 这是因为在Vue文件 ...