题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_a

Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

Iroha is very particular about numbers. There are K digits that she dislikes: D1,D2,…,DK.

She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).

However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.

Find the amount of money that she will hand to the cashier.

Constraints

  • 1≦N<10000
  • 1≦K<10
  • 0≦D1<D2<…<DK≦9
  • {D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}

Input

The input is given from Standard Input in the following format:

N K
D1 D2DK

Output

Print the amount of money that Iroha will hand to the cashier.


Sample Input 1

Copy
1000 8
1 3 4 5 6 7 8 9

Sample Output 1

Copy
2000

She dislikes all digits except 0 and 2.

The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.


Sample Input 2

Copy
9999 1
0

Sample Output 2

Copy
9999

题解:大致意思就是不能用出现过的数字组合去付钱 数据很小那就尽情暴力枚举吧 每次判断一下是否存在不喜欢的数

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
int a[];
int prim(int n)
{
int b,flag=;
while(n){
b=n%;
if(a[b]){
flag=;
break;
}
n/=;
}
if(flag) return ;
return ;
}
int main()
{
std::ios::sync_with_stdio(false);
int n,k,s,t;
cin>>n>>k;
mem(a);
for(int i=;i<k;i++){
cin>>t;
a[t]=;
}
for(int i=n; ;i++){
if(prim(i)){
cout<<i<<endl;
break;
}
}
return ;
}

こだわり者いろはちゃん / Iroha's Obsession (暴力枚举)的更多相关文章

  1. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  2. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  3. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  4. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

  5. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  6. bzoj 1028 暴力枚举判断

    昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...

  7. POJ-3187 Backward Digit Sums (暴力枚举)

    http://poj.org/problem?id=3187 给定一个个数n和sum,让你求原始序列,如果有多个输出字典序最小的. 暴力枚举题,枚举生成的每一个全排列,符合即退出. dfs版: #in ...

  8. hihoCoder #1179 : 永恒游戏 (暴力枚举)

    题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...

  9. CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

随机推荐

  1. composer安装其实可以很简单 两行命令就解决了

    最近接了一个cakephp项目,就想着用composer安装实施,因为Composer 可以方便地帮你安装项目中声明所依赖的外部工具库(libraries).之前没有接触过,相对比较陌生,但是相信ph ...

  2. 20181211 Oracle Parallel

    如下用Select作为参考, Select 在sql server中如果直接查询大量的数据,方式为给列增加Index,可以提高效率.如果查询数据量非常大的时候其实效率依旧不高,而且index在增删改中 ...

  3. Python3学习之路~5.7 Json & pickle 模块

    用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换 pickle,用于python特有的类型 和 python的数据类型间进行转换 Json模块提供了四个功能:dumps. ...

  4. System.getProperty("user.dir")

    /**获得当前类的完整路径.最后一句*/package test;import java.net.MalformedURLException;import java.net.URI;import ja ...

  5. jquery 之ajax,get,post异步请求简单代码模版

    $.get(                        "../cart/cart_list.do", "productId="+productId, fu ...

  6. [CC]Mesh文件保存

    CC中有两个地方使用了文件保存,一个是MainWindow,另一个是ccCommandLineParser. MainWindow的保存按钮关联的槽是doActionSaveFile()方法,实现了点 ...

  7. typedef 详解

    一行很常用的代码: typedef int XX_Size_Check[(sizeof(XX)==64)? 1:-1]; 很容易猜到上面这行代码是要在编译时检查XX的size,但再深究点,我们就会发现 ...

  8. 深入解密.NET(Tuple元祖)

    元组(Tuple)数学概念上是指包含特定元素与数列的数据结构,n-Tuple称为一个n元祖.比如拿数据表来类比,数据表的每一行就是一个元祖,每一列是元祖的一个属性. 它可以视为由于你不想大动干戈创建一 ...

  9. ROSETTA使用技巧随笔--score.sc处理

    对score.sc的便利操作: $ sort -n -k2 example_score_file.sc 此命令会以score文件的第二列进行排序(sort -n -k2,-n表示对数值型数据排序,可用 ...

  10. linux du查看文件所占大小

    Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...