Mashmokh and Numbers CodeForces - 415C】的更多相关文章

题意:就是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…
题目链接: 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; …
Magic Numbers CodeForces - 628D dp函数中:pos表示当前处理到从前向后的第i位(从1开始编号),remain表示处理到当前位为止共产生了除以m的余数remain. 不一定要把a减一,也可以特判a自身,或者直接改记忆化搜索. #include<cstdio> #include<cstring> #define md 1000000007 typedef long long LL; LL m,d,ans1,ans2,len1; LL ans[][][]…
题意:给你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…
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks…
http://codeforces.com/contest/851/problem/D 分区间操作 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <time.h> #include <string> #include <set> #include <map> #include <list&…
221B - Little Elephant and Numbers 思路: 水题: 代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ; ]; int main() { scanf("%d",&n); int pos=n; ) i…
B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of…
大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小. 和/2为偶数最小差一定为0, 和/2为奇数一定为1. 显然可以通过某个前缀和删去一个数得到. #include <iostream> #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #inclu…
题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数. 注意离散化,为了速度更快需存入数组查找. 不要每次memset,记录下已有的长度下符合条件的个数. 数位dp肯定是从高位到低位. 记录数字已经有多大,还有lcm,递归传下去. #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include…
大意: 给定集合a, 求a的按位与和等于0的非空子集数. 首先由容斥可以得到 $ans = \sum \limits_{0\le x <2^{20}} (-1)^{\alpha} f_x$, 其中$\alpha$为$x$二进制中$1$的个数, $f_x$表示与和等于$x$的非空子集数. $f_x$是一个$20$维前缀和, 按传统容斥做法的话显然要超时, 可以每次求一维的和, 再累加 比方说对于2维前缀和, 用容斥的求法是这样 for (int i=1; i<=n; ++i) { for (in…
大意: 给定n结点树, 有k桶水, p块钱, 初始可以任选不超过k个点(不能选根结点), 在每个点放一桶水, 然后开始游戏. 游戏每一轮开始时, 可以任选若干个节点关闭, 花费为关闭结点储存水的数量和, 然后未关闭的非根结点上的水会流入父结点, 然后再开始新的一轮. 当所有非根结点无水后游戏结束, 假设第$i$轮流入根节点的水为$w_i$, 游戏共进行了$l$轮, 求$max(w_1,w_2,...,w_l)$ 可以发现最优时一定是一段深度相邻的水, 所以双指针维护一段连续的区间就行了. 考虑每…
大意: 对于一个数$x$, 每次操作可将$x$变为$x$二进制中1的个数 定义经过k次操作变为1的数为好数, 求$[1,n]$中有多少个好数 注意到n二进制位最大1000位, 经过一次操作后一定变为1000以内的数, 所以可以暴力求出1000以内的数变为1的操作次数, 记$G_i$为$[1,n]$中二进制中1的个数为i的个数, 数位dp求出$G_i$后, 再用乘法原理就可以得出结果 要特判k为0和1的情况, k=1时会将1多算一次最后减去1 #include <iostream> #inclu…
题意: 找出区间[li,ri]内有多少数满足,这个数的每一个位的非0数都能把这个数整除 题解: 因为这个数每一位的值都可以把这个数整除,那也就是说这个数是它所有位数的公倍数,但是可能不是最小公倍数. 1.2.3.4.5.6.7.8.9的最小公倍数是2520 那么我就可以让我们要判断的那个数去取余2520来实现我们记忆化操作 因为1--9的最小公倍数是2520,所以1--9中任意几个数的最小公倍数肯定是2520的余数,所以我们只需要找出来1--2520之中所有2520的余数就可以了.最后找出来也就…
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard output Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory a…
第一次参加CF的比赛,MSK19.30,四个小时的时差真心累,第一次CODE到这么夜-- 一开始做了A,C两题,后来做B题的时候我体力和精神集中度就很低了,导致一直WA在4-- 今天起床后再刷B,终于过了--坑爹. 来看题目: A. Mashmokh and Lights time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mash…
Lucky Numbers CodeForces - 630C 小希称只含7和8的数是幸运数,那么不超过n位的幸运数有多少个? Input 一个整数 n (1 ≤ n ≤ 55) Output 输出幸运数的数量 Example Input 2 Output 6 sol:这和0,1有个屁区别 ----摘自yj大佬原话 结论非常显然小学生都知道 2n+1-2 #include <bits/stdc++.h> using namespace std; typedef long long ll; in…
参考资料: [1]:数位dp总结 之 从入门到模板 [2]:浅谈数位DP 题目一览表 来源 考察知识点 A 4352 "XHXJ's LIS" hdu 数位DP+状压DP+LIS B 55D "Beautiful numbers" codeforces 数位DP+数论基础知识+离散化处理…
这场有点难,QAQ.补了好久(。• ︿•̀。) ,总算能写题解了(つд⊂) A. Beautiful numbers CodeForces - 55D 题意 ​ 求\([l,r](1\le l_i\le r_i\le 9\cdot 10^{18})\)的中的 可以被自己每一位上的数字整除的数 的个数. 题解: ​ 知识:如果m%a=0,则任意x, x%a = (x%m)%a. ​ 2520是2~9的lcm.因此任何时候都有2520%pre_lcm==0. ​ 因为2520%pre_lcm==0,…
A - Restoring Three Numbers CodeForces - 1154A Polycarp has guessed three positive integers aa, bb and cc. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum o…
第一次就去拉了点思维很神奇的CF题目 2018省赛赛第一次训练 # Origin Title     A CodeForces 607A Chain Reaction     B CodeForces 385C Bear and Prime Numbers     C CodeForces 670D2 Magic Powder - 2     D CodeForces 360B Levko and Array     E CodeForces 68B Energy exchange     F…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
[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…
 Phone Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 151B Description Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, ord…
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if…
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory limit per test 256 megabytes 问题描述 Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his proble…
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains…
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/556/problem/B Description Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famou…
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/problem/A Description You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon…