zoukankan      html  css  js  c++  java
  • Atcoder 1973:こだわり者いろはちゃん / Iroha's Obsession

    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;
    }
  • 相关阅读:
    redis之Scan
    redis之GeoHash
    redis之漏斗限流
    redis之布隆过滤器
    redis之HyperLogLog
    redis位图
    redis延迟队列
    redis分布式锁
    如何安装redis
    社区首款 OAM 可视化平台发布!关注点分离、用户友好、上手难度低
  • 原文地址:https://www.cnblogs.com/Friends-A/p/10324369.html
Copyright © 2011-2022 走看看