【Codeforces Round #166 (Div. 2)】【暴力】A. 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]);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值