题目链接: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 D2 … DK
Output
Print the amount of money that Iroha will hand to the cashier.
Sample Input 1
1000 8
1 3 4 5 6 7 8 9
Sample Output 1
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
9999 1
0
Sample Output 2
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 ;
}