UVA471 Magic Numbers 题解】的更多相关文章

1.题目 题意很简单:输入n,枚举所有的a,b,使得 (1)满足a/b=n. (2)满足a,b各个位上的数字不相同. 2.思路 (1)对于被除数,要满足各个位上的数字,显然最大枚举到987654321就可以. (2)对于被除数,要枚举n的整数倍以减少枚举次数. 3.代码及实现 分析完这些,这个题的代码就自然而然很简单了,但是要注意 "相邻两组数据之间输出一行空行" #include<bits/stdc++.h> using namespace std; long long…
D. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of…
[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.题里说个位数的偶数位…
D. Magic Numbers 题目连接: http://www.codeforces.com/contest/628/problem/D Description Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere els…
Magic Numbers 题意: 题意比较难读:首先对于一个串来说, 如果他是d-串, 那么他的第偶数个字符都是是d,第奇数个字符都不是d. 然后求[L, R]里面的多少个数是d-串,且是m的倍数. 题解: 数位dp. dp[x][y]代表的是余数为x, 然后剩下的长度是y的情况的方案数是多少. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r&…
Magic Numbers 题意:给定长度不超过2000的a,b;问有多少个x(a<=x<=b)使得x的偶数位为d,奇数位不为d;且要是m的倍数,结果mod 1e9+7; 直接数位DP;前两维的大小就是mod m的大小,注意在判断是否f[pos][mod] != -1之前,要判断是否为边界,否则会出现重复计算: #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define MS1(a) mem…
主题链接:http://acm.timus.ru/problem.aspx?space=1&num=1727 1727. Znaika's Magic Numbers Time limit: 0.5 second Memory limit: 64 MB Znaika has many interests. For example, now he is investigating the properties of number sets. Znaika writes down some set…
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[][][]…
A. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of…
题目 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…
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1, a^p == a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, known as…
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers. Write a program to find and pri…
Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assum…
Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6347   Accepted: 3740 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth…
题意:求[a,b]中,偶数位的数字都是d,其余为数字都不是d,且能被m整除的数的个数(这里的偶数位是的是从高位往低位数的偶数位).a,b<10^2000,m≤2000,0≤d≤9 a,b<10^2000,m≤2000,0≤d≤9 题解:用f[i][j]表示有i+1位,第i位是d,且%m=j的数的个数.(这个状态可能有点奇怪,不过比较便于转移)然后转移方式还是惯用的方法,判一下如果原数的偶数位不是d或者奇数位是d则停止计算即可. 自主AC开心 #include<iostream> #…
题意: 求在[a,b](a,b不含前导0)中的d−magic数中有多少个是m的倍数. 分析: 计数dp Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else. 仔细读题并观察例子就可以明确d−magic数从左到右所有偶数位置上都是d,奇数位上不能是d. 求[a,b],即可转化为求[1,a],[1,b]中的满足条件…
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are n…
Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据范围:\(1\leqslant n,\sum n\leqslant 2\times 10^5\). Solution 看到本题的唯一一篇主席树+二分的题解里面并没有说最巧妙的方法是什么,那我就来给大家讲讲吧qwq. 对于每一个 \(m\),我们不妨弄个双指针 \(l,r\),然后从 \(1\) 的位…
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; int main(){ long long n; cin >>n; while(n){ if(n%10 == 1) n/=10; else if(n%100 == 14 ) n/=100; else if(n%1000 == 144) n/=1000;…
题意:找到[a, b]符合下列要求的数的个数. 1.该数字能被m整除 2.该数字奇数位全不为d,偶数位全为d 分析: 1.dp[当前的位数][截止到当前位所形成的数对m取余的结果][当前数位上的数字是否到达了上限] 2.对于第三维的上限,例如一个数字是54362,那么如果前四位是5436,那么前四位都到达了上限,第五位可以从0枚举所有可能,例如如果第五位是1,那么就没到达上限,如果是6就到达了上限,简而言之,就是个匹配的问题. 需要注意的是,上限不是指第二位数字只能是0~4,第三位数字只能是0~…
http://codeforces.com/contest/320/problem/A #include <cstdio> #include <cstring> using namespace std; ]; int main() { scanf("%s",str); int k=strlen(str); ; i<k; i++) { ') { printf("NO\n"); ; } ') { ) { printf("NO\n&…
因为晚上有一个cf的比赛,而自己从来没有在cf上做过题,就找了道题熟悉一下. 题目大意:给一个数,判断是否能由1,14,144三个数连接得到. 代码如下: #include <stdio.h> #include <stdbool.h> #include <string.h> bool is_magic(char num[]) { int len = strlen(num); ; ; while(i < len) { switch(level) { : ') { i…
题意:给出一个数n,问有多少组数满足是s1/ s2 =n,要求组成s1和s2的数字没有重复的. 分析:枚举,然后二进制判断各位数字是否相同. #include<iostream> #include<cstdio> #define INF 9876543210 using namespace std; bool judge(long long n) { ; int m; while(n) { m=<<(n%);//对每位数字进行扩展为2^n if(cnt&m)//…
原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因为\(7+1=8\) \(f(9)=1\),因为\(9+1=10→1\) \(f(10099)=101\),因为\(10099+1=10100→1010→101\) 我们可以多次进行函数\(f(x)\)的运算,从而让一个数\(x\)转换为另一个数,例如\(10098\)可以转换为\(102\),因为…
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数,问一个区间内所有的数是否能被其其中一个数所全部整除,求出满足条件的区间的长度最大值,并输出这样的区间的个数与它们的左端点. 换句话将,求区间GCD=区间MIN的最大长度区间. 明显st表解决. 对于最大区间长度,二分判断即可. (因为在poj做过类似的题所以思路能很快……就是题看不懂有点难,所以特…
传送门 题目大意 定义n-magic为从左往右,偶数位置均为n,奇数位置不为n的一类数.求出[a,b]内所有可被m整除的d-magic个数. 分析 显然是数位dp,我们用dp[i][j][k]表示考虑到第i位,小于还是等于范围,对m取模的余数为k的时候的个数,然后我们枚举所有满足情况的j(i为奇数则j不能为d,i为偶数则j只能为d)进行转移,转移为经典的数位dp转移.最后记得因为答案取模过所以可能在相减后变为负数因此要进行一下特殊处理. 代码 #include<iostream> #inclu…
把电话号码转换成为词典中能够记忆的的单词的组合,找到最短的组合. 我这道题应用到的知识点: 1 Trie数据结构 2 map的应用 3 动态规划法Word Break的知识 4 递归剪枝法 思路: 1 建立Trie字典树.方便查找, 可是字典树不是使用字符来建立的.而是把字符转换成数字.建立一个数字字典树. 然后叶子节点设置一个容器vector<string>装原单词. 2 动态规划建立一个表,记录能够在字典树中找到的字符串的前缀子串 3 假设找到整个串都在字典树中,那么就能够直接返回这个单词…
这题只需要会10转P进制就行了. PS:答案需要约分,可以直接用c++自带函数__gcd(x,y). 洛谷网址 Codeforces网址 Code(C++): #include<bits/stdc++.h> using namespace std; int jz(int x,int p) { ,a; ) {//10转P进制 a=x%p; s+=a;//直接将算出的哪一位加上 x/=p; } return s; } int main() { ; cin>>A; ; ;i<A;i…
题目大意: 求区间 \([x,y]\) 范围内有多少数的二进制表示中的'0'的个数 \(\ge\) '1'的个数. 解题思路: 使用 数位DP 解决这个问题. 我们设状态 f[pos][num0][num1][all0] 表示在: 当前所在数位为 pos : 当前选择的'0'的个数为 num0: 当前选择的'1'的个数为 num1: 到当前位位置是不是前面的数都是前导零(如果都是前导0则 all0==true,否则 all==false). 下的方案数. 我们开函数 dfs(int pos, i…
原题链接 简要题意: 构造一个长为 \(n\) 的数,使得每位均不为 \(0\),且 \(n\) 不被它的各位数字整除. 比方说, \(n = 239\) 是合法的.因为: \(2 \not | 239\),\(3 \not | 239\),\(9 \not | 239\). 再比方,\(n = 235\) 是不合法的.因为: \(5 | 235\). 因此,本题是个水构造. 首先 \(n = 1\),显然无解. 否则,考虑以下构造: \[233 \cdots 33 \] \[499 \cdot…