Codeforces Round #554 (Div. 2) 选做
C. Neko does Maths
题意
给 \(a,b\) ,求一个最小的 \(k\) 使得 \(\text{lcm}(a+k,b+k)\) 最小。
\(a,b\le 10^9\)
题解
\(\gcd (a+k,b+k) = \gcd(b-a,a+k)\) 。
只需枚举 \(b-a\) 的因数作为 \(\gcd\) ,容易算出最小的 \(k\) ,然后更新答案即可。
code
#include<cstdio>
long long mn=1ll<<60;
int a,b,k;
inline int gcd(int x, int y) {
return y?gcd(y,x%y):x;
}
void solve(int x)
{
int y=((a-1)/x+1)*x-a;
long long tmp=1ll*(a+y)*(b+y)/gcd(a+y,b+y);
if(tmp<mn) mn=tmp,k=y;
}
int main()
{
scanf("%d%d",&a,&b);
if(a>b) a^=b^=a^=b;
const int c=b-a;
for(int i=1;i*i<=c;++i)
if(c%i==0)
{
solve(i);
if(i*i!=c) solve(c/i);
}
printf("%d",k);
}
D. Neko and Aki's Prank
题意
给 \(n\) ,将长度为 \(2n\) 的合法括号序列放到 \(\text{trie}\) 里,求 \(\text{trie}\) 树的最大匹配,对 \(10^9+7\) 取模。
\(n\le 1000\)
题解
可以考虑直接 dp 最大匹配,但这样会涉及取 \(\max\) 操作,显然是不行的。
我们考虑贪心匹配,每次把第 \(2n-1\) 层的点全部向第 \(2n\) 点匹配,然后第 \(2n-3\) 层的点全部向第 \(2n-2\) 层的点匹配。以此类推。这样答案就为深度为奇数的点的个数。
设 \(f[i][j]\) 为深度为 \(i\) ,有 \(j\) 个左括号的点的个数。注意右括号个数始终不能超过左括号个数,左括号个数不能 \(>n\) 。转移显然。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2005,Mod=1e9+7;
int f[N][N];
int main()
{
int n,ans=0;
scanf("%d",&n),n<<=1;
f[0][0]=1;
for(int i=1;i<=n;++i)
for(int j=0;j<=i;++j) // ( : j
{
if(j>n/2) continue;
int k=i-j; // ) : k
if(j>=1&&j-1>=k) f[i][j]=(f[i][j]+f[i-1][j-1])%Mod;
if(k>=1&&j>k-1) f[i][j]=(f[i][j]+f[i-1][j])%Mod;
ans=(ans+(i%2==1)*f[i][j])%Mod;
}
printf("%d",ans);
}
Codeforces Round #554 (Div. 2) 选做的更多相关文章
- Codeforces Round #568 (Div. 2) 选做
A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...
- Codeforces Round #554 ( div.2 ) 总结
应该经常需要锻炼一下英语阅读理解能力和代码能力,所以以后还是需要多打打CF. 今天大概就是水一水找找感觉. A. Neko Finds Grapes $n$个箱子,$m$个钥匙 ($n,m \leq ...
- Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索
https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...
- Codeforces Round #554 (Div. 2)自闭记
A 签到 #include<bits/stdc++.h> using namespace std; ],t[],ans; int main() { scanf("%d%d&quo ...
- Codeforces Round #554 (Div. 2) C. Neko does Maths (简单推导)
题目:http://codeforces.com/contest/1152/problem/C 题意:给你a,b, 你可以找任意一个k 算出a+k,b+k的最小公倍数,让最小公倍数尽量小,求出 ...
- Codeforces Round #554 (Div. 2) 1152B. Neko Performs Cat Furrier Transform
学了这么久,来打一次CF看看自己学的怎么样吧 too young too simple 1152B. Neko Performs Cat Furrier Transform 题目链接:"ht ...
- Codeforces Round #554 (Div. 2) 1152A - Neko Finds Grapes
学了这么久,来打一次CF看看自己学的怎么样吧 too young too simple 1152A - Neko Finds Grapes 题目链接:"https://codeforces. ...
- Codeforces Round #554 (Div. 2)-C(gcd应用)
题目链接:https://codeforces.com/contest/1152/problem/C 题意:给定a,b(<1e9).求使得lcm(a+k,b+k)最小的k,若有多个k,求最小的k ...
- Codeforces Round #554 (Div. 2) C. Neko does Maths (数论 GCD(a,b) = GCD(a,b-a))
传送门 •题意 给出两个正整数 a,b: 求解 k ,使得 LCM(a+k,b+k) 最小,如果有多个 k 使得 LCM() 最小,输出最小的k: •思路 时隔很久,又重新做这个题 温故果然可以知新❤ ...
随机推荐
- P1135奇怪的电梯
P1135奇怪的电梯 #include <iostream> #include <cstdio> #include <cstring> #include <a ...
- Java--API解读之Method Summary
参考来源:Java 中静态方法 实例方法 具体方法区别与联系 JAVA Method Summary网页 * Static Method :"静态方法",直接引用,无需创建对象: ...
- python学习第一课
第一课: 1.不要使用来路不明的软件 2.下载杀毒软件 3.不懂技术的人在技术人面前会显得愈发无知 4.python无所不能 需要掌握的知识: 1.python基本语法 2.文件处理 3.函数 4.模 ...
- SpringBoot + redis + @Cacheable注解实现缓存清除缓存
一.Application启动类添加注解 @EnableCaching 二.注入配置 @Bean public CacheManager cacheManager(RedisTemplate redi ...
- 【PAT甲级】1005 Spell It Right (20 分)
题意: 给出一个非零整数N(<=10^100),计算每位之和并用英文输出. AAAAAccepted code: #include<bits/stdc++.h> using name ...
- IIS URL Rewrite(URL 重写)-使用教程
IIS URL Rewrite(URL 重写)-使用教程 作者:vkvi 来源:千一网络(原创) 日期:2011-8-17 http://www.cftea.com/c/2011/08/9CRXOL ...
- Linux centosVMware Linux监控平台介绍、zabbix监控介绍、安装zabbix、忘记Admin密码如何做
一.Linux监控平台介绍 cacti.nagios.zabbix.smokeping.open-falcon等等 cacti.smokeping偏向于基础监控,成图非常漂亮 cacti.nagios ...
- 捣鼓Haskell
最近想学这门语言,于是做了一些准备工作,配置好一切后,打算玩一玩. 先扔一段官方简介: Introduction Haskell is a computer programming language. ...
- Windows密码安全性测试
一.本地管理员密码如何直接提取 1.1直接通过mimikatz读取管理员密码 (不能交互式,不能在webshell下用,图形化界面很好用) 第一条:privilege::debug ...
- Linux--如何实现虚拟机与主机之间的文件传输无需第三方,即可轻松设置共享文件夹(适合所有人群)
无需第三方插件,设置共享文件夹 第一步:虚拟机->设置 第二步:选项->共享文件夹->总是启用->添加 第三步:点击下一步 第四步:浏览(选择主机路径)->下一步 第五步 ...