题解:P13185 [GCJ 2016 Qualification] Counting Sheep
BlackHoles · · 题解
正解(附证明)
当
当
考虑证明:首先,每连续
我们尝试构造,设
于是简单模拟即可,用
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int T, N;
bool flag[10];
int main(void) {
cin.tie(0), cout.tie(0);
cin >> T;
for (int t = 1; t <= T; ++t) {
cin >> N;
if (!N) {
cout << "Case #" << t << ": INSOMNIA\n";
continue;
}
memset(flag, false, sizeof flag);
int num = 0, now = 0, tmp = 0;
while (num < 10) {
now += N;
tmp = now;
while (tmp) {
int tot = tmp % 10;
if (!flag[tot]) {
flag[tot] = true;
++num;
if (num == 10) break;
}
tmp /= 10;
}
}
cout << "Case #" << t << ": " << now << '\n';
}
return 0;
}
谢谢大家!(点个赞吧