日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Long Beautiful Integer CodeForces - 1268A(贪心构造)

發布時間:2023/12/15 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Long Beautiful Integer CodeForces - 1268A(贪心构造) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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.

Input
The first line of input contains two integers n,k (2≤n≤200000,1≤k<n): the number of digits in x and k.

The next line of input contains n digits a1,a2,…,an (a1≠0, 0≤ai≤9): digits of x.

Output
In the first line print one integer m: the number of digits in y.

In the next line print m digits b1,b2,…,bm (b1≠0, 0≤bi≤9): digits of y.

Examples
Input
3 2
353
Output
3
353
Input
4 2
1234
Output
4
1313
思路:這個題目其實只要前k位確定了,那么這個數字就確定了。因為任意長度的全是9組成的數字一定符合題意,這樣m一定等于n。那么我們就取給定數字的前k位,剩下的根據這k位去構造。如果大于等于給定的就直接輸出,否則就將前k位的數字+1,然后再根據這k位數字構造。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;string s; int n,k;int main() {char a='a';scanf("%d%d",&n,&k);cin>>s;string t;for(int i=0;i<k;i++) t+=s[i];for(int i=k;i<n;i++) t+=t[i-k];if(t>=s) cout<<n<<endl<<t<<endl;else{for(int i=k-1;i>=0;i--){if(t[i]!='9'){t[i]+=1;break;}else t[i]='0';}for(int i=k;i<n;i++) t[i]=t[i-k];cout<<n<<endl<<t<<endl;}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Long Beautiful Integer CodeForces - 1268A(贪心构造)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。