D. Two Arithmetic Progressions
time limit per test
memory limit per test
input
output
a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R andx = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0.
Input
a1, b1, a2, b2, L, R (0 < a1, a2 ≤ 2·109, - 2·109 ≤ b1, b2, L, R ≤ 2·109, L ≤ R).
Output
x.
Examples
input
2 0 3 3 5 21
output
3
input
2 4 3 0 6 17
output
2
题解:让你找出符合x = a1k' + b1 = a2l' + b2,且 L ≤ x ≤ R的x的个数。
这题被人hack了。(待补。。。数学题)。。。
E. Generate a String
time limit per test
memory limit per test
input
output
zscoder
n
x seconds to insert or delete a letter 'a' from the text file and y
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n
Input
n, x and y (1 ≤ n ≤ 107, 1 ≤ x, y ≤ 109) — the number of letters 'a' in the input file and the parameters from the problem statement.
Output
t
Examples
input
8 1 1
output
4
input
8 1 10
output
8
题解:初始化有一个空的文本,要求生成得到n 个‘a’字母, 插入或删除一个‘a’需要x秒,复制目前的字符串需要y秒,问你达到n个‘a’字母最少要几秒。
设dp[i]表示第 i 个‘a’字符最少要多少秒。
那么初始化dp[1]=x。
如果 i 等于奇数。则dp[i]=min(dp[i-1]+x,dp[(i+1)/2]+x+y);只可能是插入或删除,或插入或删除和复制都有。
如果 i 等于偶数。则dp[i]=min(dp[i/2]+y,dp[i-1]+x)。只可能是复制以及插入或删除。
代码:
#pragma comment(linker, "/STACK:102400000,102400000")//#include#include#include#include#include#include#include#include
暂时没有评论,来抢沙发吧~