签到,乘以两个相邻的合数
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
long long n;
cin>>n;
cout<<9*n<<" "<<8*n<<endl;
return 0;
}
这里的加数取模相当于移位,把两个序列排序后,遍历移位对应情况就可以。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[20010];
ll B[40010];
int main () {
ll n,m;
cin>>n>>m;
for(int i = 0; i < n; i++) {
cin>>A[i];
}
for(int i = 0; i < n; i++) {
cin>>B[i];
}
sort(A, A+n);
sort(B, B+n);
for(int i = 0; i < n; ++i){
B[i + n] = B[i];
}
ll ans = (ll)1<<63-1;
for(ll i = 0; i < n; ++i){
ll diff = (B[i]-A[0]+m)%m;
bool flag = 1;
for(int j = 0; j < n; ++j){
if((A[j]+diff)%m != B[i+j]) {
flag = 0;
break;
}
}
if(flag){
ans = min(ans, diff);
}
}
cout << ans << endl;
}
取前k个,后面的数,要么是前k个的重复出现,要么是从第k个往前,是如果是9则变零,找到第一个不是9的加一。重复输出就可以。
#include<bits/stdc++.h>
using namespace std;
char a[200010];
char b[200010];
int main()
{
int m,k;
cin>>m>>k;
//scanf("%s",a);
int flag = 1;
for (int i = 0; i < m; ++i)
{
cin>>a[i];
}
//memset(b, 0, sizeof(b));
for (int i = 0; i < m; ++i)
{
if (a[i%k]<a[i])
{
flag = 0;
break;
}
if(a[i%k]>a[i])
{
flag = 1;
break;
}
}
//用来记录重叠的部分
for (int i = 0; i < k; ++i)
{
b[i] = a[i];
}
if (flag)
{
cout<<m<<endl;
for (int i = 0; i < m; ++i)
{
cout<<b[i%k];
}
cout<<endl;
}
else
{
//先增加, 从尾部开始;
for (int i = k-1; i >=0 ; --i)
{
if (b[i]!='9')
{
b[i] += 1;
//flag = 1;
break;
}
else
{
b[i]='0';
}
}
cout<<m<<endl;
for (int i = 0; i < m; ++i)
{
cout<<b[i%k];
}
cout<<endl;
}
return 0;
}