uva 471 - Magic Numbers】的更多相关文章

题意:给出一个数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)//…
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…
UVa 10006 - Carmichael Numbers An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without cryptography. Alvar…
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…
题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: #include <bits/stdc++.h> typedef long long ll; using namespace std; ; ll num[maxn]; int n,ans[maxn]…
[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.题里说个位数的偶数位…
UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且1为丑数,那么不妨从1开始算起.算完之后2,3,5均为丑数,然后再从2算起,4,5,10均为丑数--直到算到第1500个即可.那么有如下的问题: 如何从算出来的丑数中取出最小的? 如何保证没有计算重复的丑数? 对于第一个问题,可以采用优先队列的方法,即有序的队列,且为升序,每次只需要取出队首元素即可…
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…
UVA - 13022 Sheldon Numbers 二进制形式满足ABA,ABAB数的个数(A为一定长度的1,B为一定长度的0). 其实就是寻找在二进制中满足所有的1串具有相同的长度,所有的0串也具有相同的长度,并且在给定范围内的个数. 位运算.通过分析不难发现,所有解不会很大,因此我们可以暴力,用两个for分别枚举0串和1串的长度,然后交替放入一个值内(注意先放1),同时更新答案. 将值存入set,发现所有满足条件的个数为4809(4810). ps:因为这里的2^63大于long lon…
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[][][]…
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&…
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…
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included.Write a program to find and print the 1500'th ugly number. Input There…
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionallynumbers can of course be ordered in size. The first few…
  Carmichael Numbers  An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without cryptography. Alvaro is one…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题意 输入两个整数a和b,输出从a到b(包含a和b)的平方数的个数.直到输入0 0时程序结束 分析: 如果一个数n是平方数,(double)sqrt(n)-(int)sqrt(n)<1e-6. 下面给出AC代码: #include <bits/stdc++.h&…
 Pseudo-Random Numbers  Computers normally cannot generate really random numbers, but frequently are used to generate sequences of pseudo-random numbers. These are generated by some algorithm, but appear for all practical purposes to be really random…
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included. Write a program to find and print the 1500’th ugly number. Input Ther…
Smith Numbers Background While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Lehigh University , noticed that the telephone number of his brother-in-law H. Smith had the following peculiar property: The sum of the digits o…
题意: 求在[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]中的满足条件…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456 题目大意: 给出两个数a,b(a<=b<=100000),求在a和b之间有多少个完全平方数(包括a和b) 思路: 打表啊打表. #include<cstdio> #include<cstring> #include<cmath> cons…
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally numbers can of course be ordered in size. The first…
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…
数学太渣了,这道题反复参考了大神的博客,算是看懂了吧.博客原文  http://blog.csdn.net/crazysillynerd/article/details/43339157 算是个数学题吧,虽然在AOAPC上面给放到象征水题的第三章里面了. 这个题基本就是帮着你复习了一遍浮点数的存储方式了.浮点数在计算机里是分三部分表示的,最前面一位表示符号,后面一部分是尾数,最后一部分是阶码,表示方法类似于科学记数法,不过是二进制的,尾数是M阶码是E的话那么表示起来就是M × 2^E了.然后对于…
题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <ctime> #include <cstdlib> #include <iostream> using namespace std; #define LL long long #define MOD 1000000007 ]; int judge(in…
#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;…
题目:统计区间中的平方数个数. 分析: ... #include <stdio.h> #include <string.h> ]; int main() { int i, a, b, t; memset(on,,sizeof(on)); ;i<=;i++) on[i*i] = ; while(~scanf("%d%d", &a, &b)) { t=; &&b==) break; for(i=a;i<=b;i++) {…
题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i++) sum *= ; return sum; } int main() { ], c; while(~scanf("%d", &n)) { ) break; i=; *p((i-)/)) { n -= *p((i-)/); i++; } c = (i+)/; t=; while(…
题意:给出丑数的定义,不能被除2,3,5以外的素数整除的的数称为丑数. 和杭电的那一题丑数一样--这里学的紫书上的用优先队列来做. 用已知的丑数去生成新的丑数,利用优先队列的能够每次取出当前最小的丑数再去生成新的丑数==== 大概这儿的优先队列就充当了dp转移方程里面的那个min的意思@_@ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include&l…