codeforces1152 div2
C
gcd(a+k, b+k) == gcd(a+k, b-a)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
typedef long long ll;
ll ans=0;
ll mn;
ll a, b;
void work(ll x){
ll k = (x-a%x)%x;
ll aa = k+a, bb = k+b;
ll temp = aa/__gcd(aa, bb)*bb;
if(temp<mn){
ans = k;
mn = temp;
}
else if(temp == mn &&ans>k){
ans = k;
}
}
int main(){
scanf("%lld%lld", &a, &b);
if(a>b) swap(a, b);
if(a == b){
printf("0\n");
return 0;
}
mn = a/__gcd(a, b)*b;
ll d = b-a;
for(int i=1; i*i<=d; ++i){
if(d%i==0){
work(1ll*i), work(1ll*d/i);
}
}
printf("%lld\n", ans);
return 0;
}
D
题意
括号串形成的trie树的最大的匹配(选择的两条边不能有公共的节点)。
记忆化dp
奇数层必定有孩子,因此只能取得一个边
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3+10;
typedef long long ll;
const int mod = 1e9+7;
int dp[maxn][maxn];
//奇数层一定有孩子
int dfs(int n, int now){
if(n == 0){
if(now == 0) return dp[n][now] = 0;
else return dp[n][now] = -2;
}
if(dp[n][now]!=-1) return dp[n][now];
if(n<now||now<0) return dp[n][now] = -2;
ll temp = 0;
bool has = false;
if(dfs(n-1, now+1)>=0){
temp += dp[n-1][now+1]+(n%2==0);
has = true;
}
if(dfs(n-1, now-1)>=0){
temp += dp[n-1][now-1]+(n%2==0);
has = true;
}
if(has){
return dp[n][now] = temp%mod;
}
else return dp[n][now] = -2;
}
int main(){
int n;
scanf("%d", &n);
memset(dp, -1, sizeof(dp));
dfs(2*n, 0);
printf("%d\n", dp[2*n][0]);
return 0;
}
codeforces1152 div2的更多相关文章
- bc#54 div2
用小号做的div2 A:竟然看错了排序顺序...白白WA了两发 注意读入一整行(包括空格):getline(cin,st) [gets也是资瓷的 #include<iostream> us ...
- $('div a') 与$('div>a'),.div+.div2与.div~.div2
$('div a'):div标签下所有层次a元素的jquery对象 $('div>a'):div标签下子元素层次a元素的jquery对象 <body> <div class=' ...
- SRM 657 DIV2
-------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforce Round #211 Div2
真的是b到不行啊! 尼玛C题一个这么简单的题目没出 aabbccddee 正确的是aabccdee 我的是 aabcdee 硬是TM的不够用,想半天还以为自己的是对的... A:题... B:题. ...
- Topcoder srm 632 div2
脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...
- TopCoder 603 div1 & div2
div2 250pts MiddleCode 题意:s串长度为奇数时,将中间字符取掉并添加到t末尾:长度为偶数时,将中间两个较小的字符取掉并添加到末尾. 分析:直接做,学习了一下substr(s, p ...
- TopCoder 649 div1 & div2
最近一场TC,做得是在是烂,不过最后challenge阶段用一个随机数据cha了一个明显错误的代码,最后免于暴跌rating,还涨了一点.TC题目质量还是很高的,非常锻炼思维,拓展做题的视野,老老实实 ...
- 220 DIV2 B. Inna and Nine
220 DIV2 B. Inna and Nine input 369727 output 2 input 123456789987654321 output 1 题意:比如例子1:369727--& ...
随机推荐
- 异常详细信息: System.IO.FileLoadException: 未能加载文件或程序集“Office, Version=7.0.3300.0,
导出Excel程序调试起来很正常,发布到服务器上却出错. 错误:未能加载文件或程序集“Office, Version=2.2.0.0, Culture=neutral, PublicKeyToken= ...
- EF的默认映射以及如何使用Data Annotations和Fluent API配置数据库的映射
I.EF的默认映射 上节我们创建项目,通过定义实体类就可以自动生成数据库,并且EF帮我们自动设置了数据库的主键.外键以及表名和字段的类型等,这就是EF的默认映射.具体分为: 数据库映射:Code Fi ...
- IIS 常用命令
Ø 简介 本文主要介绍 IIS 常用的命令,主要包含以下内容: 1. IIS 重启方法 2. 站点重启方法 3. 应用程序池重启方法 1. IIS 重启方法 1) 重启 IIS ...
- C# 类型转换的开销
先来个测试: static void Main(string[] args) { Stopwatch stopwatch; string strStr = "string"; ob ...
- python中的图像数据库PIL
from PIL import Image im = Image.open("图片路径") im.function() 常用的函数: 1.im.crop(x,y,x1,y1) 对图 ...
- cmd切换代码页,切换字体,cmd不能输入中文
cmd终端切换编码:437:美国英语.936:中文gbk编码.65001:UTF8 小知识: 如果cmd不能调用中文输入法,也就是不能输入中文,是因为目前激活的代码页不是936 使用 chcp 936 ...
- python2 线程基础
1,感谢菜鸟教程, 线程基础:导入,创建函数,创建线和运行 import thread import time # 为线程定义一个函数 def print_time(threadName, delay ...
- LeetCode第十八题-四数之和
4Sum 问题简介:定n个整数和整数目标的数组nums,是否有元素a,b,c,d在nums中,使a+b+c+d=target? 举例: 给定数组 nums = [1, 0, -1, 0, -2, 2] ...
- git本机服务器配置(四):git+TortoiseGit+gitblit配置本机服务器
1.配置本机git服务器 1.1 打开gitblit服务器,登录之前设置的服务页面localhost:1081 1.2.登录账号,账号在(三)中有提到. 1.3 打开用户中心 1.4 点击SSH Ke ...
- vue面试题总结
1.vue双向绑定的实现原理2.js的继承和原型链3.es6语法箭头函数和普通函数的区别 普通函数的this总是指向它的直接调用者. 在严格模式下,没找到直接调用者,则函数中的this是undefin ...