博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Atcoder 1973:こだわり者いろはちゃん / Iroha's Obsession
阅读量:7111 次
发布时间:2019-06-28

本文共 2100 字,大约阅读时间需要 7 分钟。

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 KD1 D2 … DK

Output

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


Sample Input 1

1000 81 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 10

Sample Output 2

9999

题意

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

思路

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

AC代码

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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|1const 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
>x; vis[x]=1; } for(int i=n;;i++) { if(check(i)) { cout<
<

 

转载于:https://www.cnblogs.com/Friends-A/p/10324369.html

你可能感兴趣的文章
函数func_splitString:将字符串按指定方式分割,获取指定位置的数
查看>>
C++编程基础练习
查看>>
Python实现快速排序
查看>>
蓝牙4.0BLE抓包(二) – 广播包解析
查看>>
laravel创建新的提交数据
查看>>
FineBI学习系列之FineBI的ETL处理(图文详解)
查看>>
Java 8 新特性
查看>>
Windows启动配置数据(BCD)存储文件包含一些无效信息
查看>>
slim请求参数获取
查看>>
MySQL主从介绍 准备工作 配置主 配置从 测试主从同步
查看>>
hadoop2.4.1伪分布式环境搭建
查看>>
Java基础-字符串(String)常用方法
查看>>
CSS------当内容超出div宽度后自动换行和限制文字不超出div宽度和高度
查看>>
要恢复页面吗?Chrome未正确关闭
查看>>
iOS 性能优化总结
查看>>
hbs模板(zmaze ui用的)
查看>>
使用ASP.NET SignalR实现一个简单的聊天室
查看>>
8个试剂,其中一个有毒,最少多少只小白鼠能检测出有毒试剂——分而治之思想...
查看>>
Spring3.1 对Bean Validation规范的新支持(方法级别验证)
查看>>
fiddler script建议教程
查看>>