Codeforces Round #609 (Div. 2) ABC 题解
A. Equation
题意:找出两个合数a,b使得 a - b = n。
思路:水题,让a = 10n, b = 9n ,那么ab必定都是合数。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
ll n = read();
cout<<10*n<<' '<<9*n<<endl;
return 0;
}
B. Modulo Equality
题意:找到一个最小的x,使得每个(a[i] + x)%m后能在b数组中找到一一对应的。
看到n才2000,尝试暴力一点的思路。从结果入手,a[1]在+x模m后肯定和b数组中的某个数是对应的,借此思路,我们就枚举一遍b数组,假设当前b[p]就是a[1]+x变过去的。这样我们就知道了和b[p]匹配时的x,然后拿这个x遍历一遍a数组看是否合法,合法的话就更新我们的min值。时间复杂度O(n²)
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <unordered_map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 3e3+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[maxn];
ll b[maxn];
unordered_map<ll,ll> Map;
unordered_map<ll,ll> Map1;
int main()
{
ll n = read(), m = read();
rep(i,1,n) a[i] = read();
rep(i,1,n) b[i] = read(), Map[b[i]] ++;
ll mi = inf;
int p = 1;
while(p<=n)
{
Map1.clear();
for(auto it = Map.begin(); it != Map.end(); it++) Map1[it->fi] = it->se;
ll x = 0;
if(a[1] > b[p]) x = m - (a[1] - b[p]);
else x = b[p] - a[1];
rep(i,1,n) Map1[(a[i]+x)%m] -- ;
int flag = 1;
for(auto it = Map1.begin(); it != Map1.end(); it++)
{
if(it->se!=0)
{
flag = 0;
break;
}
}
if(flag) mi = min(mi, x);
p++;
}
cout<<mi<<endl;
return 0;
}
C. Long Beautiful Integer
题意:给一个数x,找到一个y>=x且y[i] = y[i-k](i>=k)。
思路:贪心一下,其实我们需要研究的只是前k个数,要构造的数后面都是这k个的循环。
1.如果我们直接构造x前k个数的循环,如果此时的y还大于等于x话,就是最优的,什么都不用改,直接重复这k段。
2.否则,就让前k段+1,这个时候再重复肯定比x大,而且还能保证是最小的。
所以就按照上面判断条件走一下,如果要+1还要考虑一下进位。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 2e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
string s;
ll n = read(), k = read();
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<<'\n';
cout<<t<<'\n';
}
else
{
int e = 1;
per(i,k-1,0)
{
int cur = t[i] - '0';
int tmp = cur;
cur = (cur + e)%10;
e = (tmp+e)/10;
t[i] = cur + '0';
if(!e) break;
}
cout<<n<<'\n';
rep(i,k,n-1) t[i] = t[i-k];
cout<<t<<'\n';
}
return 0;
}
Codeforces Round #609 (Div. 2) ABC 题解的更多相关文章
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- python,url请求失败重新请求的方法(try、except 应用)
爬虫请求链接,有时候会出现请求失败或者等待时间很长的情况,用下面的方法可以一定程度的解决这个问题 url='https://cl.xxxx.xyz/'+url try: response = requ ...
- app自动化的特殊操作
一.截屏 File srcfile=driver.getScreenshotAs(OutputType.FILE); //得到截图源文件对象 File dstfile=new File("C ...
- python 处理word 分页符、分节符
import docx doc1 =docx.Document(r"C:\Users\Administrator\Desktop\test.docx") doc1.paragrap ...
- Dify 框架连接 PGSQL 数据库与 Sandbox 环境下的 Linux 系统调用权限问题
Dify 框架连接 PGSQL 数据库与 Sandbox 环境下的 Linux 系统调用权限问题 背景 在使用 Dify 框架进行开发时,遇到了两个主要的技术挑战: 代码节点连接到 PGSQL(Pos ...
- 3d xna fbx winfrom 读取
本文通过参考网上资源做的一个例子. 本程序的功能就是通过xna 将3d 图像显示到winfrom 对他进行旋转操作. 首先我们先准备好两个文件夹 model 文件夹放fbx文件,textures 放 ...
- 毒瘤idea合集
给定 \(n,m\) ,求: \[\sum_{i=1}^{n}\sum_{i=1}^{m}max\big(gcd(i,j)^i,lcm(i,j)^j\big) \]
- LSposed hook(学习分享)
Xposed模块编写 参考: https://www.52pojie.cn/thread-1740944-1-1.html https://www.52pojie.cn/thread-1748081- ...
- 【记录】Google|下载 Google 谷歌商店中的应用的多种方式
之前我为了下载猫能玩的平板游戏,又不想下载病毒,就找了很多谷歌商店直接下 APK 的方法,以供大家参考. 对猫游戏感兴趣可参考这篇:[记录]Android|安卓平板 猫游戏(四款,peppy cat, ...
- C++ 迭代器(STL迭代器)iterator详解
要访问顺序容器和关联容器中的元素,需要通过"迭代器(iterator)"进行,迭代器是一个变量,相当于容器和操作容器的算法之间的中介.迭代器可以指向容器中的某个元素,通过迭代器就可 ...
- Reverse Integer——LeetCode进阶路⑦
原题链接https://leetcode.com/problems/reverse-integer/ 题目描述 Given a 32-bit signed integer, reverse digit ...