【CF55D】Beautiful numbers】的更多相关文章

[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的时候前面所有数的\(lcm\)要压进\(dp\)值中. 又因为\(lcm\)的余数也是有意义的,但是又不能暴力记, 所以记录一下\([1,9]\)所有数的\(lcm\)也就是\(2520\)就好了. 但是数组太大,实际上,有意义的\(lcm\)个数只有不到\(50\)个,重新编号就可以压缩状态了.…
[CF55D]Beautiful numbers 题面 洛谷 题解 考虑到如果一个数整除所有数那么可以整除他们的\(lcm\),而如果数\(x\)满足\(x\bmod Lcm(1,2...,9)=r\),且\(r\bmod Lcm\{x有的数\}=0\),那么这个数一定满足条件. 因为\(Lcm(1,2...,9)=2520\)比较小,所以我们可以存下来. 考虑数位dp,我们设\(f[i][lcm][r]\)表示目前\(dp\)到第\(i\)位,当前已选的数的\(lcm\)为\(lcm\),前面…
[HDU3117]Fibonacci Numbers 题面 求斐波那契数列的第\(n\)项的前四位及后四位. 其中\(0\leq n<2^{32}\) 题解 前置知识:线性常系数齐次递推 其实后四位还是比较好求,矩阵快速幂就可以了,主要是前四位. 先用线性常系数齐次递推求出斐波那契数列的通项公式 \[ f_n=\frac{\sqrt 5}{5}\left((\frac{1+\sqrt5}{2})^n-(\frac{1-\sqrt5}{2})^n\right) \] 因为数列的前\(39\)项我们…
[CF628D]Magic Numbers 题意:求[a,b]中,偶数位的数字都是d,其余为数字都不是d,且能被m整除的数的个数(这里的偶数位是的是从高位往低位数的偶数位).$a,b<10^{2000},m \le 2000 ,0 \le d \le 9$ 题解:用f[i][j]表示有i+1位,第i位是d,且%m=j的数的个数.(这个状态可能有点奇怪,不过比较便于转移)然后转移方式还是惯用的方法,判一下如果原数的偶数位不是d或者奇数位是d则停止计算即可. 对了,题意有bug.题里说个位数的偶数位…
目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM 题目描述 NIBGNAUK 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 divisib…
[链接] 我是链接,点我呀:) [题意] 让你找到长度为n的数字 这个数字只由a或者b组成 且这n个数码的和也是由a或者b组成的 求出满足这样要求的数字的个数 [题解] 枚举答案数字中b的个数为y,那么a出现的个数就为n-y 那么和就是na + (b-a)y; 这个数字最多就7位的样子 很容易检查是不是只包含a或者b 然后如果满足只包含a或者b 则答案加上C(n,y) 即n个位置中选择y个放b,其他的放a 组合数取余的话,预处理一下阶乘以及阶乘的逆元就好 [代码] import java.io.…
4692: Beautiful Spacing Time Limit: 15 Sec  Memory Limit: 128 MBSubmit: 46  Solved: 21[Submit][Status][Discuss] Description 文章是一些单词组成的序列,单词由字母组成.你的任务是将一篇文章的单词填充到一个网格中,其中网格包含W列和足够多的行.为了布局之美,以下限制都需要满足. 1.文章中的文字需要按照原有的顺序放置.下图表示了将4个单词的文章“This is a pen”放入…
1. Beautiful Soup的简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: Beautiful Soup提供一些简单的.python式的函数用来处理导航.搜索.修改分析树等功能.它是一个工具箱,通过解析文档为用户提供需要抓取的数据,因为简单,所以不需要多少代码就可以写出一个完整的应用程序. Beautiful Soup自动将输入文档转换为Unicode编码,输出文档转换为utf-8编码.你不需要考虑编码方式,除非文档没有指…
转载自:Beautiful Soup库(bs4)入门 该库能够解析HTML和XML 使用Beautiful Soup库:      from bs4 import BeautifulSoup import requests r = requests.get('http://www.23us.so/') html = r.text soup = BeautifulSoup(html,'html.parser') print soup.prettify() 1.Beautiful Soup库的理解:…
Beautiful Soup是一个第三方的网页解析的模块.其遵循的接口为Document Tree,将网页解析成为一个树形结构. 其使用步骤如下: 1.创建对象:根据网页的文档字符串 2.搜索节点:名称.属性.文字. 3.处理节点: BeautifulSoup(文档字符串, 'html.parser' 解析器,from_encoding='utf8') find_all(名称,属性,文字):可以传入字符串 也可以传入正则表达式. node.name 名称 node['href'] 属性 node…
Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers from List A got left out. Can you find out the…
Sorting is often useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses also. Challenge Given a list of unsorted numbers, can you find the numbers that have the smallest absol…
题目如下: Given a positive integer N, return the number of positive integers less than or equal to N that have at least 1 repeated digit. Example 1: Input: 20 Output: 1 Explanation: The only positive number (<= 20) with at least 1 repeated digit is 11. E…
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets…
打表大军是一股邪恶势力→_→ #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cctype> #include <cmath> #include <numeric> #include <algorithm> #include <limits.h> #include <ve…
题目大意:给你一个区间$[l,r]$,求在该区间内有多少整数在二进制下$0$的数量$≥1$的数量.数据范围$1≤l,r≤2*10^{9}$. 第一次用记忆化dfs写数位dp,感觉神清气爽~(原谅我这个蒟蒻,原先写的四不像数位dp至少需2h,用真记忆化dfs不到半小时写出) 我们用$f[i][j]$表示在最后的$i+j$为中,用了$i$个$0$,$j$个$1$的方案数(第$i+j$位也可以是$0$).该方程转移显然为$f[i][j]=f[i-1][j]+f[i][j-1]$. 于是我们用记忆化df…
题意:给你一个数n,让你找m个非负整数,使得它们的和为n,并且按位或起来以后的值最小化.输出这个值. 从高位到低位枚举最终结果,假设当前是第i位,如果m*(2^i-1)<n的话,那么说明这一位如果填零,剩下的位不论怎么填,都绝对凑不出n来,所以这一位必须填1.如果m*(2^i-1)>=n,这一位就填1,然后把n变为max(n mod 2^i , n-m*2^i),重复这个过程即可. 要用高精度. import java.util.*; import java.io.*; import java…
题意:给定一个数字n,最多可以交换其两个数位k次,求交换后的最大值与最小值,最小值不能有前导0 n,k<=1e9 思路: 当k>=n的位数时只需要无脑排序 k<n时有一个显然的贪心是从高位到低位,如果当前位置不是可取的最值的话就从比现在低的位置挑一个最值换上来 问题在于可能有多个低位上的数字相同,而且这个问题没有正确的贪心策略 所以只能记录下它们的位置,依次搜索 搜索最小值时第一位不能是0 #include<cstdio> #include<cstring> #i…
题意: 思路:From https://blog.csdn.net/qq_36553623/article/details/76683438 大概就是把1e6里面的质因子能除的都除光之后借助两者gcd中有最大质因子的条件分类讨论 其实也就5类,重点是如何设分类的标准,其实唯一的标准就是对答案的贡献 int128本机环境跑不了,只能交上去的时候改,总觉得有朝一日要掉坑里 #include<bits/stdc++.h> using namespace std; typedef long long…
题意:From https://blog.csdn.net/m0_37809890/article/details/102886956 思路: 可以发现转移就是右上角的一个区间前缀和 std只要开1倍空间,个人习惯开2倍滚动数组, 1倍有时候没想清楚的前提下初始化或者求前缀和顺序手抖就会gg,反正时空只有常数倍差距 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int ui…
题目如下: Return all non-negative integers of length N such that the absolute difference between every two consecutive digits is K. Note that every number in the answer must not have leading zeros except for the number 0 itself. For example, 01 has one l…
传送门 Luogu 解题思路 毒瘤数位DP,发现一个前缀我们只需要记录它对 \(\operatorname{lcm}(1,2,3,\cdots,9)=2520\) 取模的值即可,所以我们在 DP 时记录一下当前的前缀模2520的值,以及前缀每一位数字的 \(\operatorname{lcm}\) 即可,至于空间的问题,只需要对2520的所有约数离散一下就好了. 细节注意事项 咕咕咕 参考代码 #include <algorithm> #include <iostream> #in…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS 日期 题目地址:https://leetcode.com/problems/numbers-with-same-consecutive-differences/ 题目描述 Return all non-negative integers of length N such that the absolute difference between…
[10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses (2019年2月13日) 给了一个N,生成N对括号的所有情况的字符串. n = 3 [ "((()))", "(()())", "(())()", "()(())", "()()()" ] 题解:dfs生成. c…
链接:https://leetcode.com/tag/divide-and-conquer/ [4]Median of Two Sorted Arrays [23]Merge k Sorted Lists [53]Maximum Subarray (2019年1月23日, 谷歌tag复习) 最大子段和. 题解: follow up 是divide and conquer If you have figured out the O(n) solution, try coding another…
人生的大起大落莫过如此,下一场我一定要回紫. [A]Points on the line 题意: 一个直线上有\(n\)个点,要求去掉最少的点,使得最远两点距离不超过\(d\). 题解: 暴力两重for,更新答案. #include<cstdio> #include<algorithm> using namespace std; #define F(i,a,b) for(int i=(a);i<=(b);++i) int n,q,ans=0; int a[100001]; i…
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/9797184.html [7]Reverse Integer (2018年12月23日, review) 给了一个32位的整数,返回它的reverse后的整数.如果reverse后的数超过了整数的范围,就返回 0. Example 1: Input: 123 Output: 321 Example 2:…
[175]Combine Two Tables (2018年11月23日,开始集中review基础) Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId | int | | FirstName | varchar | | LastName | varchar | +-------------+---------+ PersonId is the pr…
题目 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 just count the quantity of beautiful…
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁先挤奶的顺序.她们甚至也不能通过仍硬币的方式. 所以她们通过"round number"竞赛的方式.第一头牛选取一个整数,小于20亿.第二头牛也这样选取一个整数.如果这两个数都是 "round numbers",那么第一头牛获胜,否则第二头牛获胜. 如果一个正整数N的二…