codeforces C. Mashmokh and Numbers】的更多相关文章

题意:给你n和k,然后让你找出n个数使得gcd(a1,a2)+gcd(a3,a4)+......的和等于k: 思路:如果n为奇数,让前n-3个数的相邻两个数都为1,n-2和n-1两个数gcd为k-ans:ans为前n-3个数的和.为偶数的话,让前n-2个数的相邻两个数都为1,n和n-1两个数gcd为k-ans: #include <cstdio> #include <cmath> #include <cstring> #include <vector> #i…
题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh wri…
, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109. Input The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; …
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and…
codeforces 414D Mashmokh and Water Tanks 题意 题解 \(a_i\):第 \(i\) 层的结点个数. \(b_i\):第 \(i\) 层初始有水的结点个数. 如果不允许关闭水塔,最后的答案就是 \(max\{a_i\}\). 现在允许关闭部分水塔,我们可以把一些连续层数的水汇聚到同一层.假设我们汇聚 \([l, r]\) 范围的水,总花费是 \(\Sigma_{i=l}^r\{b_i*(r-i)\}\). 双指针实现即可. 代码 #include<bits…
题意:就是n个数和k,每次按顺序那两个数,最大公约数的和为k. 思路:注意:当n=1,k>0时一定不存在,还有n=1,k=0时为1即可. 然后再正常情况下,第一组的最大公约数为k-n/2+1即可,后面是含有素数.(本来,配的是素数和素数+1, 然后会怕第一组会重复,后来直解两个素数了,因为第一组要么是特殊的素数要么是合数所以么有必要担心重复) #include<iostream> using namespace std; #define N int(1e7+10) int prime[N…
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integers a and b (1≤a,b≤104). We paint all the numbers in increasing number first we paint 0, then we paint 1, then 2 and so on. Each number is painted whi…
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers - the first column containing inte…
http://codeforces.com/problemset/problem/449/D 题意:给n个数,求and起来最后为0的集合方案数有多少 思路:考虑容斥,ans=(-1)^k*num(k),num(k)代表至少有k个数字and起来为1的方案数,那么怎么求num呢? 考虑and起来至少为x的方案数:那么一定是2^y-1,其中y代表有多少个数&x==x,问题就变成有多少数"包含"了某个数(二进制下),用dp解决这个问题:如果某一位数字是1,那么它一定能转移到它不是1的那…
http://codeforces.com/problemset/problem/414/B 题目大意: 题意:一个序列B1,B2...Bl如果是好的,必须满足Bi | Bi + 1(a | b 代表a整除b), 求长度为K,元素大小小于等于N的序列个数 思路:f[i][j] 代表在序列的第i位,当前数字为j的方案数 #include<cstdio> #include<cmath> #include<algorithm> #include<cstring>…