Codeforces Round #166 (Div. 2)暴力A. Beautiful Year

Posted SSL_ZZL

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #166 (Div. 2)暴力A. Beautiful Year相关的知识,希望对你有一定的参考价值。

Beautiful Year

Codeforces Round #166 (Div. 2) A. Beautiful Year
Codeforces Round #166 (Div. 2) B. Prime Matrix 题解
Codeforces Round #166 (Div. 2) D. Good Substrings 题解


题目

It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.

Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.

Input
The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.

Output
Print a single integer — the minimum year number that is strictly larger than y and all it’s digits are distinct. It is guaranteed that the answer exists.

Examples
input

1987

output

2013

input

2013

output

2014

题目大意

明显数的年份:没有出现重复的数字
找出一个严格大于给出年份的最小明显数年份
比如2022不是明显数年份,2031是2022后的第一个明显数年份


解题思路

开心开心开心开心,学长选的一套比赛好简单(哈哈虽然还是不会做)

因为年份4位数可以先提前预处理出答案
从后(9000)往前(1000),把当前最小的明显年份赋值给当前年份,如果当前年份是明显年份,那就更新最小明显年份
9000 * 4真的很小🙂

其实直接从 y+1 开始找明显年份也是可以的,但是我要写高级的程序(bushi,预处理在多组数据时比较吃香


Code

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int n, now, ans[11000], v[100];

int check(int i) 
	memset(v, 0, sizeof(v));
	while(i) 
		v[i % 10] ++;
		if(v[i % 10] > 1) return 0;
		i /= 10;
	
	return 1;


int main() 
	for(int i = 10000; i >= 1000; i --)   //比赛时天真的以为9000的答案是9123,然后被罚时了,暴躁开成10000
		ans[i] = now;
		if(check(i)) now = i;
	
	scanf("%d", &n);
	printf("%d", ans[n]);

以上是关于Codeforces Round #166 (Div. 2)暴力A. Beautiful Year的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #166 (Div. 2) BPrime Matrix

Codeforces Round #166 (Div. 2) DhashGood Substrings

Codeforces Round #166 (Div. 2)暴力A. Beautiful Year

Codeforces Round #166 (Div. 2)暴力A. Beautiful Year

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)