题目大意

给定两个数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)
{
int sum=0;
for(int i=0; i<cur; i++)
sum=(sum*10+str[i])%cur;
return sum;
}
void dfs(int cur)
{
if(flag==1)
return ;
if(cur==m)
{
flag=1;
return ;
}
for(int i=0; i<=9; i++)
{
str[cur]=i;
if((cur<n-1)||!judge(cur+1))
{
dfs(cur+1);

}
if(flag==1)
return ;
}
}
int main()
{
int t;
scanf("%d",&t);
for(int ii=1; ii<=t; ii++)
{
scanf("%d %d",&n,&m);
flag=0;
for(int i=1; i<=9; i++)
{
str[0]=i;
dfs(1);
if(flag==1)
{
printf("Case %d: ",ii);
for(int i=0; i<m; i++)
printf("%d",str[i]);
printf("\n");
break;
}
}
if(flag==0)
printf("Case %d: -1\n",ii);
}
return 0;
}

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

  1. 10624 - Super Number

    题目链接 题意:给出n到m的范围,求出一个数在前i位数组成的数字能被i整除.假设存在输出这个数,假设不存在.输出-1. 思路:回溯,每次放第i位,然后推断是否符合题意.这题踩着时间过去的2.6s(看了 ...

  2. UVA - 12298 Super Poker II NTT

    UVA - 12298 Super Poker II NTT 链接 Vjudge 思路 暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数&q ...

  3. UVA10624 - Super Number(dfs)

    题目:UVA10624 - Super Number(dfs) 题目大意:给你n和m要求找出这种m位数,从第n位到第m位都满足前i位是能够被i整除,假设没有这种数,输出-1.有多个就输出字典序最小的那 ...

  4. UVA 12633 Super Rooks on Chessboard [fft 生成函数]

    Super Rooks on Chessboard UVA - 12633 题意: 超级车可以攻击行.列.主对角线3 个方向. R * C 的棋盘上有N 个超级车,问不被攻击的格子总数. 行列好好做啊 ...

  5. UVA - 10591 Happy Number

    Happy Number UVA - 10591 Let the sum of the square of the digits of a positive integer S0 be represe ...

  6. UVA 11882 Biggest Number(搜索+剪枝)

    You have a maze with obstacles and non-zero digits in it: You can start from any square, walk in the ...

  7. UVA 11734 Big Number of Teams will Solve This

    大水题,不解释啦! #include<cstdio> #include<cstring> #define maxn 50 using namespace std; char s ...

  8. UVA - 11882 Biggest Number(dfs+bfs+强剪枝)

    题目大意:给出一个方格矩阵,矩阵中有数字0~9,任选一个格子为起点,将走过的数字连起来构成一个数,找出最大的那个数,每个格子只能走一次. 题目分析:DFS.剪枝方案:在当前的处境下,找出所有还能到达的 ...

  9. UVA 12633 Super Rooks on Chessboard(FFT)

    题意: 给你一个R*C的棋盘,棋盘上的棋子会攻击,一个棋子会覆盖它所在的行,它所在的列,和它所在的从左上到右下的对角线,那么问这个棋盘上没有被覆盖的棋盘格子数.数据范围R,C,N<=50000 ...

随机推荐

  1. ArrayAdapter适配器的用法,模拟QQ发消息界面。

    import java.util.ArrayList; import android.app.Activity; import android.content.Context; import andr ...

  2. webApi跨域

    <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...

  3. mac 连接mysql提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory

    mac 连接mysql的时候提示 Warning: mysqli::real_connect(): (HY000/2002): No such file or directory [说明1]MAC下M ...

  4. validator

    http://rickharrison.github.io/validate.js/validate.js rules: 'required|callback_check_password' vali ...

  5. RM报表的选项 注册表位置

    HKCU\Software\WHF SoftWare\Report Machine\RMReport\Form\RMDesignerForm\ 设计器-工具-选项的设置 HKCU\Software\W ...

  6. 数据结构-AVL树的旋转

    http://blog.csdn.net/GabrieL1026/article/details/6311339 平衡二叉树在进行插入操作的时候可能出现不平衡的情况,AVL树即是一种自平衡的二叉树,它 ...

  7. 用Qt实现简单的视频播放器

    ui 在.pro文件中添加 QT +=phonon 头文件 #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> ...

  8. Codeforces Round #327 (Div. 2)-Wizards' Duel

    题意: 在一条长度为l的走廊,两个人站在走廊的左右两端分别以p,q的速度走来,问他们相遇时离左端的距离是多少? 思路: 非常简单的暴力题,不解释. 代码如下: #include <iostrea ...

  9. Spring学习笔记之Constructor-based or setter-based DI?

    如果是强制依赖,那么使用构造器注入,如果是可选依赖,那么使用set方法注入.Spring鼓励构造器注入,可以确保依赖项不为null, Since you can mix constructor-bas ...

  10. protected 和default的区别

    default:包内可见,包外不可见 protected:包内可见,包外不可见,但是包外继承之后可见.