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 ...
随机推荐
- 🎀Markdown介绍与语法
简介 Markdown是一种轻量级的标记语言,由John Gruber于2004年创建.它的设计目标是让人们能够使用易读易写的纯文本格式编写文档,并且可以通过工具将其转换为结构化的HTML(超文本标记 ...
- 【FAQ】HarmonyOS SDK 闭源开放能力 —Health Service Kit
1.问题描述: 按照官方文档调用healthStore API申请用户授权:有拉起授权弹窗,但是无回调,检查权限接口也无回调. 解决方案: 1.接口调用前,需先使用init方法进行初始化,没有回调的问 ...
- 信息资源管理综合题之“SPD属于知识管理工具那一类 与 管理工具与知识库的区别 以及 使用知识地图是否可以用SynchroFLOW替代”
一.案例:1995年10月,微软开发了一项"技能规划与开发(SPD)"的计划,他们把每个系统开发人员的工作能力和这些特定工作需要的知识制作成地图,让那个员工与团队间的配合更加默契, ...
- 如何使用Flutter开发执行操作系统shell命令的工具
@charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...
- C#缩放图片形成新的图片
// 加载原始Bitmap Bitmap originalBitmap = new Bitmap("C:\\Users\\Administrator\\Desktop\\test.bmp&q ...
- C#之动态语言扩展
DLR 在.NET Framework中,DLR2位于System.Dynamic命名空间和System.Runtime.CompilerServices命名空间的几个类中. dynamic 类型 可 ...
- Django startproject, startapp后的配置 总结
(1)在project的settings.py中的INSTALL_APPS中添加新建的各个app的名字. (2)设置templates文件夹的位置(容纳html文件):TEMPLATE_DIR=os. ...
- 前端EXCEL插件智表ZCELL数据源功能详解
一.数据源功能介绍前端EXCEL插件智表ZCELL提供了强大的数据源管理功能,使开发者能够灵活地在电子表格中集成和管理结构化数据.数据源功能主要分为两种类型: 卡片式数据源:适合展示和编辑单个数据记录 ...
- 2.3.net core 工作流WorkFlow流程(流程节点附件设置)
流程节点附件设置 WikeFlow官网:http://www.wikesoft.com 有些流程要求某些节点必须上传附件. 你只需要在流程节点中配置附件的Key,附件名称,是否必传. 如下图: 文件存 ...
- 浅析Java8中default关键字
摘要:介绍Java8新增关键字default,它用于在接口中标记方法为默认方法和编写实现逻辑,方便通过新增方法重构接口,而无需修改所有实现类,目的在于兼容接口已有实现类. 综述 default关键 ...