C - こだわり者いろはちゃん / Iroha's Obsession


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

题意

第一行是数n和k,第二行有k个数(这k个数均在1~9之间),要求找出各位都不包含这k个数的大于n的最小的数

思路

将出现过的数字标记一下,然后for循环从n开始,写一个check函数,查找当前数字的每一位的数字是否在k个数里面,一直找到符合要求的数为止。

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int a[maxn];
int vis[maxn];
bool check(int n)
{
while(n)
{
if(vis[n%10])
return false;
n/=10;
}
return true;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n,k;
int x;
cin>>n>>k;
for(int i=0;i<k;i++)
{
cin>>x;
vis[x]=1;
}
for(int i=n;;i++)
{
if(check(i))
{
cout<<i<<endl;
return 0;
}
}
return 0;
}

Atcoder 1973:こだわり者いろはちゃん / Iroha's Obsession的更多相关文章

  1. こだわり者いろはちゃん / Iroha's Obsession (暴力枚举)

    题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_a Time limit : 2sec / Memory limit : 256MB Score ...

  2. AtCoder Regular Contest 058

    这个应该是第一场有英文的atcoder吧??不过题解却没有英文的... 从前往后慢慢做... C こだわり者いろはちゃん / Iroha's Obsession 数据范围这么小,直接暴力 #inclu ...

  3. 【AtCoder】ARC058

    ARC058 C - こだわり者いろはちゃん / Iroha's Obsession 暴力一个个枚举是最简单的方式 #include <bits/stdc++.h> #define fi ...

  4. AtCoder-arc058(题解)

    A - こだわり者いろはちゃん / Iroha's Obsession(暴力) 题目链接 题目大意: 给你 \(k\) 个个位数字和一个数字 \(n\) ,要求找到一个大于等于n的数字,使得不出现 \ ...

  5. AtCoder ABC 042D いろはちゃんとマス目 / Iroha and a Grid

    题目链接:https://abc042.contest.atcoder.jp/tasks/arc058_b 题目大意: 给定一个 H * W 的矩阵,其中左下角 A * B 区域是禁区,要求在不踏入禁 ...

  6. Atcoder Regular Contest 058 D - 文字列大好きいろはちゃん / Iroha Loves Strings(单调栈+Z 函数)

    洛谷题面传送门 & Atcoder 题面传送门 神仙题. mol 一发现场(bushi)独立切掉此题的 ycx %%%%%%% 首先咱们可以想到一个非常 naive 的 DP,\(dp_{i, ...

  7. Iroha and a Grid AtCoder - 1974(思维水题)

    就是一个组合数水题 偷个图 去掉阴影部分  把整个图看成上下两个矩形 对于上面的矩形求出起点到每个绿点的方案 对于下面的矩形 求出每个绿点到终点的方案 上下两个绿点的方案相乘后相加 就是了 想想为什么 ...

  8. 2018.12.19 atcoder Iroha and a Grid(组合数学)

    传送门 组合数学好题. 给你一个hhh行www列的网格,其中左下角aaa行bbb列不能走,问从左上角走到右下角有多少种走法(每次只能向右或者向下) 我们考虑分步计数. 我们一共能走的区域是总网格区域去 ...

  9. いろはちゃんとマス目 / Iroha and a Grid (组合数学)

    题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_b Time limit : 2sec / Memory limit : 256MB Score ...

随机推荐

  1. laravel自定义公共函数的引入

    原文地址:http://blog.csdn.net/u011415782/article/details/78925048 步骤指导 1. 创建 functions.php 在 app/Helpers ...

  2. Java中的标签

    @SuppressWarnings 简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量 ...

  3. window有哪些属性?

    self:self代表自己,相当于window. parent:返回父窗口. top:返回顶层窗口,和parent作用一样. opener:窗口开启者. status:设置窗口状态栏的文本.

  4. OOP⑻

    1.接口: 类 和 对象 对象 is a 类 例子: 小鸟 is a 动物 飞机 is a 交通工具 子弹 is a 武器 卫星 is a 通讯工具 问题? 01. 小鸟 飞机 子弹 卫星 虽然不是一 ...

  5. AttributeError: 'cx_Oracle.Cursor' object has no attribute 'numbersAsStrings'

    转载自:https://www.wengbi.com/thread_77579_1.html 最近在本地搭建Django开发环境,Django 1.11,python 2.7.11,数据库Oracle ...

  6. Delphi I/O error 103 错误

    http://stackoverflow.com/questions/634587/delphi-why-do-i-sometimes-get-an-i-o-error-103-with-this-c ...

  7. urllib 获取页面或发送信息

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- #urllib提供了一系列用于操作URL的功能. #urllib的request模块可以非常方便地抓取UR ...

  8. asp.net mvc 获取ajax的 request payload 参数

    注意事项: 传输的格式要设置城:"contentType": "application/x-www-form-urlencoded"

  9. 传统应用迁移到kubernetes(Hadoop YARN)

    spark-on-yarn-with-kubernetes 该例子仅用来说明具体的步骤划分和复杂性,在生产环境应用还有待验证,请谨慎使用. 过程中可能用到的概念和术语初步整理如下: 整个迁移过程分为如 ...

  10. centos7配置mysql

    一:mysql安装方法一:yum安装 下载并安装MySQL官方的 Yum Repository https://dev.mysql.com/ cd ~ wget -i -c https://dev.m ...