Codeforces 题面传送门 & 洛谷题面传送门 一道个人感觉挺有意思的交互题,本人一开始想了个奇奇怪怪的做法,还以为卡不进去,结果发现竟然过了,而且还是正解( 首先看到这类题目可以考虑每次删掉一个质数的倍数,即对某个 \(pr_i\) 执行 B 操作,然后对 \(pr_i\) 进行 A 询问,根据询问得到的值是否等于理论上删去这些数后 \(pr_i\) 的倍数个数来判断 \(pr_i\) 是否是 \(x\) 的因数,如果是那么就枚举 \(pr_i\) 的 \(2,3,4,\cdots\)…
题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L-1)前缀和相减的形式.如果一个数能被所有位上数的最小公倍数(lcm)整除,便是符合要求的数. 但是直接传递一个数n的话,dp数组肯定开不下.那么怎么让其传递的值更小呢. 先了解一个等式: sum%(x*n)%x == sum%x 可以将一个数枚举到第pos位之前的值视作sum,x是所有位上数的lcm.那么我们…
Codeforces 题面传送门 & 洛谷题面传送门 人菜结论题做不动/kk 首先考虑此题一个非常关键的结论:我们设整个数列的众数为 \(G\),那么在最优子段中,\(G\) 一定是该子段的众数之一.考虑反证法,如果最优子段中众数出现次数 \(<\) 该子段中出现次数最多的数的出现次数,那么我们考虑向左向右扩展这个区间,显然由于 \(G\) 是整个区间中出现次数最多的数,我们总可以找到一个时刻,满足 \(G\) 的出现次数 \(\ge\) 原子段中出现次数最多的数的出现次数,此时子段的长度肯…
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ k ]:来到 i 位置时,所有非零数的lcm = j,当前数位 k 时含有的 Beautiful numbers 的个数. 但是,由题意得,当前的数 k 可以是个很大的数(9e18),数组根本就开不下,那怎么办呢? 将当前的数 hash 一下,如何hash呢? 假设 a,b,c,d 为[0,9]的数,那么不存…
Codeforces 878 E. Numbers on the blackboard 解题思路 有一种最优策略是每次选择最后面一个大于等于 \(0\) 的元素进行合并,这样做完以后相当于给这个元素乘 \(2\) ,并且不使前面一个元素的值增加了.但是按照这样的策略做不太好维护,考虑做完以后有许多块,除了第一个块以外每一个块都是负的,然后将这些块与第一个块合并.那么用并查集维护一下每个块,每一个元素被乘 \(2\) 的次数就是这个块里面位置比它小的元素个数.定义一个块的和为每个元素乘上其对应系数…
1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the seco…
1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactl…
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得只需要记录搜到当前位出现了哪些数字作为状态即可,明显是假算法...感觉这是一道数位DP好题.可以这样思考:一个数要想被其各位数字分别都整除,等价于它被那些数字的LCM整除.因此记录当前位,当前数对(1~9的LCM)取模的结果,当前出现的数字的LCM这三个值作为状态才合理,即dp[pos][sum][…
1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), 如果作为字符串处理时要注意前面补0 4. 代码 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; bool cmp(char a, char b){ return a>…
1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactl…
PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be…
Codeforces 题目传送门 & 洛谷题目传送门 好家伙,刚拿到此题时我连啥是 huffman 编码都不知道 一种对 \(k\) 个字符进行的 huffman 编码的方案可以看作一个由 \(k\) 个叶节点组成的二叉树,从根节点开始走到左儿子相当于在字符串后面添一个 \(0\),走到右儿子相当于在字符串后面添一个 \(1\),那么一个叶子节点就对应着一个字符的编码. huffman 编码的一个很经典的问题是,我们现在对每个字符定义了一个频率 \(f_i\),我们需构造出一棵有 \(k\) 个…
Description In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: …
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据,看看有没有结论. 2 3 4 5 6 7 8 9 10 11 12 (人数) 1 2 2 3 3 3 4 4 4 4 4 (比赛数) 发现比赛数的增长成斐波那契.维护一个前缀和即可. #include <bits/stdc++.h> #define ll long long using names…
 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/contest/448/problem/C 题目大意:n个1* a [ i ] 的木板,把他们立起来,变成每个木板宽为1长为 a [ i ] 的栅栏,现在要给栅栏刷漆,刷子宽1,刷子可以刷任意长,每次只能横着刷或者竖着刷,问最少需要刷几次?解题思路:参考了这里(https://blog.csdn.net/qq_24451605/article/details/48492573)首先我们能够想到,如果横着刷,为了得到最优解,当前刷的位置的下面也…
E. Compatible Numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Two integers x and y are compatible, if the result of their bitwise "AND" equals zero, that is, a & b = 0. Fo…
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; ; ull base[maxbit], n, k; void preDeal() { ] = ; ; i < maxbit; i++){ *]; } } voi…
C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal…
Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2<=b<=10^{10^6},1<=n<=10^{10^6},1<=c<=10^9\) 简明题解: 因为 \(b\) , \(n\)都太大了.关键是求 \((b)^{n-1}\%c\) 所以,我们可以利用欧拉函数 \(phi()\) 的性质. 对于\(a^{b} \% c\…
wo integers x and y are compatible, if the result of their bitwise "AND" equals zero, that is, a&b = 0. For example, numbers90(10110102) and 36(1001002) are compatible, as 10110102&1001002 = 02, and numbers 3(112) and 6(1102) are not com…
题意: 给出l,r,k,(1 ≤ l ≤ r ≤ 2·109, 2 ≤ k ≤ 2·109) 求在区间[l,r]内有多少个数i满足 k | i,且[2,k-1]的所有数都不可以被i整除 首先,如果k不是素数的话,答案肯定是0 考虑k是素数: fir[i]保存i的第一个素因子,fir[]可以在线性筛的时候得到 我们先把N以内的数线性筛出来 所以其实就是求: [l,r]中满足fir[i] = k 的i的个数 [l,r] = [1,r] - [1,l-1] 所以现在我们要求的就是: [1,r]中满足f…
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…
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input output standard output The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a num…
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/20076297 题目大意:给出一个n,ans = ∑(2≤i≤n)1/(v(i)*u(i)), v(i)为不大于i的最大素数,u(i)为大于i的最小素数, 求ans,输出以分式形式. 解题思路:一開始看到这道题1e9,暴力是不可能了,没什么思路,后来在纸上列了几项,突然想到高中时候求等差数列时候用到…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k …
题目链接:http://codeforces.com/problemset/problem/558/C 题意:把n个数变成相同所需要走的最小的步数易得到结论,两个奇数不同,一直×2不可能有重叠枚举每个数可能到得所有值,以及统计达到该值的时候已经走的步数最终答案就是1到up中num[i]最小的数 Examples input output 2 input output 5 Note In the first sample test, the optimal solution . In the se…
630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦加上前面只有7和8的情况,一共是6位.所以递推式不难写出dp[i]=pow(2,i)+dp[i-1]; 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans[56]; void init ()…
<题目链接> 题目大意: 对于那些各个位数上的非0数小于等于3的数,我们称为 classy number ,现在给你一个闭区间 [L,R]  (1≤L≤R≤1018).,问你这个区间内有多少个classy number 数. 解题分析: 对于这种对数的数位有要求的题目,可以往搜索,dp上想一想,本题可用搜索做.先用搜索将所有符合条件的数放入vector ,然后排序,再用二分函数得到 L,R的坐标,再相减,即可得到 [L,R]区间中满足条件的数的个数. #include <bits/std…