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 ...
随机推荐
- matlab plot line settings
- LY.JAVA面向对象编程.包的概述、导包
2018-07-18 08:46:57 导包:
- Win10系列:VC++媒体播放控制3
(5)添加视频进度条 视频进度条可以用来显示当前视频的播放进度,并可以通过拖动视频进度条来改变视频的播放进度.接下来介绍如何实现视频进度条,首先打开MainPage.xaml文件,并在Grid元素中添 ...
- Mysql InnoDB三大特性-- 自适应hash index
Mysql InnoDB三大特性-- 自适应hash index
- SpringMVC:后台将List转为Json,传值到页面
一.JSP页面 <body> <form name="test" action="getAllStudent" method="po ...
- Neo4J 教程
好文转载: W3C: https://www.w3cschool.cn/neo4j/neo4j_cypher_api_example.html neo4j图数据库入门: http://blog.csd ...
- Map中根据条件删除元素
今天在写程序过程中,需要根据判断条件删除一个Map中的相应数据,我自然而然想到可以通过调用Map中的remove(Object key)函数进行删除:代码如下: public Map<Doubl ...
- pymongo 对mongoDB的操作
#文档地址 http://api.mongodb.com/python/current/api/pymongo/collection.html collection级别的操作: find_and _m ...
- 不管你是否已经准备面试, 这45道Python面试题都对你非常有帮助!(mark!)
1)什么是Python?使用Python有什么好处? Python是一种编程语言,包含对象,模块,线程,异常和自动内存管理.蟒蛇的好处在于它简单易用,可移植,可扩展,内置数据结构,并且它是一个开源的. ...
- Cracking The Coding Interview 9.1
//原文: // // You are given two sorted arrays, A and B, and A has a large enough buffer at the end to ...