UVa 10624 - Super Number】的更多相关文章

题目大意 给定两个数n和m,如果长度为m的数满足对于每个i(n<=i<=m),数字的前i位都能被i整除,那么这个数就是超级数,求出字典序最小的符合要求的超级数. 分析 直接暴力搜索 #include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;int str[50];int n,m,flag;int judge(int cur){…
题目链接 题意:给出n到m的范围,求出一个数在前i位数组成的数字能被i整除.假设存在输出这个数,假设不存在.输出-1. 思路:回溯,每次放第i位,然后推断是否符合题意.这题踩着时间过去的2.6s(看了下别人的题解.能够降低取模次数来节省时间). 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const…
UVA - 12298 Super Poker II NTT 链接 Vjudge 思路 暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数". 错误 我也不知道,改着改着自己就A了 思路 #include <bits/stdc++.h> #define ll long long using namespace std; const ll N=1e7+7,mod=39582418599937LL; char s; bool vi…
题目:UVA10624 - Super Number(dfs) 题目大意:给你n和m要求找出这种m位数,从第n位到第m位都满足前i位是能够被i整除,假设没有这种数,输出-1.有多个就输出字典序最小的那个. 解题思路:将每一个位置都用0..9枚举一下,注意第一个字符不能是0,然后dfs推断每一个位置是否都满足要求.注意这里是会爆long long的,所以要取模一下.本来以为这种做法会超时的,结果居然过了,预计是例子数少,并且找不到的情况也比較少. 代码: #include <cstdio> #i…
Super Rooks on Chessboard UVA - 12633 题意: 超级车可以攻击行.列.主对角线3 个方向. R * C 的棋盘上有N 个超级车,问不被攻击的格子总数. 行列好好做啊,就是不被攻击的行数*列数 减去主对角线的,就是不被攻击的行列中求\(r - c = d\)的三元组个数 考虑写出行和列生成函数 \(A(x)=\sum x^{r_i},B(x)=\sum x^{-c_i}\),乘起来就行了 可以乘上\(x^c\)来避免负指数 #include <iostream>…
Happy Number UVA - 10591 Let the sum of the square of the digits of a positive integer S0 be represented by S1. In a similar way, let the sum of the squares of the digits of S1 be represented by S2 and so on. If Si = 1 for some i ≥ 1, then the origin…
You have a maze with obstacles and non-zero digits in it: You can start from any square, walk in the maze, and finally stop at some square. Each step, you may only walk into one of the four neighbouring squares (up, down, left, right) and you cannot…
大水题,不解释啦! #include<cstdio> #include<cstring> #define maxn 50 using namespace std; char s[maxn],t[maxn]; int main() { ; scanf("%d",&tt); getchar(); while(tt--) { gets(s); gets(t); int l1=strlen(t); int l2=strlen(s); ; ; ;i<l2;i…
题目大意:给出一个方格矩阵,矩阵中有数字0~9,任选一个格子为起点,将走过的数字连起来构成一个数,找出最大的那个数,每个格子只能走一次. 题目分析:DFS.剪枝方案:在当前的处境下,找出所有还能到达的点的个数,若当前数字的长度加上个数仍小于目前最优答案的长度,则剪去:若长度相等,则将所有还能到达的数字按从大到小排序后连到当前数字上,如果还比目前最优解小,则减去.找出所有还能到达的点的过程用BFS实现. #pragma comment(linker, "/STACK:1024000000,1024…
题意: 给你一个R*C的棋盘,棋盘上的棋子会攻击,一个棋子会覆盖它所在的行,它所在的列,和它所在的从左上到右下的对角线,那么问这个棋盘上没有被覆盖的棋盘格子数.数据范围R,C,N<=50000 思路: 直接做肯定会超时,所以需要一种\(nlogn\)的算法.我们一步一步来. 首先,我们肯定需要给被覆盖的行被覆盖的列做上标记,visx标记被覆盖的行,visy标记被覆盖的列,visd标记被覆盖的对角线 那么就是 visx[r]=1,visy[c]=1,visd[r-c+C]=1,给对角线这么标号避免…