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;
}
Atcoder 1973:こだわり者いろはちゃん / Iroha's Obsession的更多相关文章
- こだわり者いろはちゃん / Iroha's Obsession (暴力枚举)
题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_a Time limit : 2sec / Memory limit : 256MB Score ...
- AtCoder Regular Contest 058
这个应该是第一场有英文的atcoder吧??不过题解却没有英文的... 从前往后慢慢做... C こだわり者いろはちゃん / Iroha's Obsession 数据范围这么小,直接暴力 #inclu ...
- 【AtCoder】ARC058
ARC058 C - こだわり者いろはちゃん / Iroha's Obsession 暴力一个个枚举是最简单的方式 #include <bits/stdc++.h> #define fi ...
- AtCoder-arc058(题解)
A - こだわり者いろはちゃん / Iroha's Obsession(暴力) 题目链接 题目大意: 给你 \(k\) 个个位数字和一个数字 \(n\) ,要求找到一个大于等于n的数字,使得不出现 \ ...
- AtCoder ABC 042D いろはちゃんとマス目 / Iroha and a Grid
题目链接:https://abc042.contest.atcoder.jp/tasks/arc058_b 题目大意: 给定一个 H * W 的矩阵,其中左下角 A * B 区域是禁区,要求在不踏入禁 ...
- Atcoder Regular Contest 058 D - 文字列大好きいろはちゃん / Iroha Loves Strings(单调栈+Z 函数)
洛谷题面传送门 & Atcoder 题面传送门 神仙题. mol 一发现场(bushi)独立切掉此题的 ycx %%%%%%% 首先咱们可以想到一个非常 naive 的 DP,\(dp_{i, ...
- Iroha and a Grid AtCoder - 1974(思维水题)
就是一个组合数水题 偷个图 去掉阴影部分 把整个图看成上下两个矩形 对于上面的矩形求出起点到每个绿点的方案 对于下面的矩形 求出每个绿点到终点的方案 上下两个绿点的方案相乘后相加 就是了 想想为什么 ...
- 2018.12.19 atcoder Iroha and a Grid(组合数学)
传送门 组合数学好题. 给你一个hhh行www列的网格,其中左下角aaa行bbb列不能走,问从左上角走到右下角有多少种走法(每次只能向右或者向下) 我们考虑分步计数. 我们一共能走的区域是总网格区域去 ...
- いろはちゃんとマス目 / Iroha and a Grid (组合数学)
题目链接:http://abc042.contest.atcoder.jp/tasks/arc058_b Time limit : 2sec / Memory limit : 256MB Score ...
随机推荐
- SpringBoot 配置文件存放位置及读取顺序
SpringBoot配置文件可以使用yml格式和properties格式 分别的默认命名为:application.yml.application.properties 存放目录 SpringBoot ...
- 使用C#开发数据库应用程序
第一章 用Hello ACCP.NET快速热身(一) 1-1.进入C#世界 a.第一个C#程序 (1)新建项目[项目:project] (2)生成解决方案[生成:build,解决方案:solution ...
- vs2015如何使用附加进程调试发布在IIS上项目
1.如何使用附加进程调试IIS上的网站项目 1)在IIS部署一个网站项目 2)保证浏览器可访问(比如访问登陆页面) 3)在项目中LoginController断点,并在工具栏的调试找到附加到进程 4) ...
- 原 spring-boot工程中,jpa下hibernate的ddl-auto的各种属性
jpa: hibernate: ddl-auto: create ddl-auto:create----每次运行该程序,没有表格会新建表格,表内有数据会清空 ddl-auto:create-d ...
- LY.JAVA面向对象编程.final、多态、抽象类、接口
2018-07-08 13:47:26 final关键字 多态 从右向前念 多态的成员访问特点及转型的理解 多态的问题理解: class 孔子爹 { public int age = 40; p ...
- day04_python_1124
01 上周内容回顾 int bool str int < --- > str: i1 = 100 str(i1) s1 = '10' int(s1)字符串必须是数字组成. in ...
- 学习Linux系统的方法有很多,适合自己的才是最好
综观现在互联网+的发展以及应用,作为一个从事IT行业的人员,应该懂得Linux占比多大份量,所以说,去掌握Linux是一种相当重要的谋生途径,当然,如果你对它产生情感那更好.这篇文章主要是本人结合自身 ...
- 深度学习----Xavier初始化方法
“Xavier”初始化方法是一种很有效的神经网络初始化方法,方法来源于2010年的一篇论文<Understanding the difficulty of training deep feedf ...
- Cracking The Coding Interview 1.2
//原文: // // Write code to reverse a C-Style String. (C-String means that "abcd" is represe ...
- powershell玩转litedb数据库-第二版
powershell可以玩nosql数据库吗?答案是肯定的.只要这个数据库兼容.net,就可以很容易地被powershell使用. 发文初衷:世界上几乎没有讲powershell调用nosql的帖子, ...