您的位置:首页 > 其它

UVa 471 - Magic Numbers

2016-07-19 11:06 274 查看
題目:已知一個數字N,構造出s1與s2使得s1 / s2 = N,其中s1和s2各自數位上的數字不同。

分析:搜索,枚舉。直接枚舉N的倍數判斷是否合法即可(數據中沒有1╮(╯▽╰)╭)。

說明:╮(╯▽╰)╭又是好久沒刷題了。

#include <cstdio>

int bits_count[11];
int check(long long value)
{
for (int i = 0; i <= 9; ++ i) {
bits_count[i] = 0;
}
while (value) {
if (bits_count[value%10LL]) {
return 0;
}
bits_count[value%10LL] ++;
value /= 10LL;
}
return 1;
}

int main()
{
int T, length;
long long base;
scanf("%d",&T);
while (T --) {
scanf("%lld",&base);
for (long long i = 1; i <= 9876543210; ++ i) {
if (base*i > 9876543210) {
break;
}
if (check(base*i) && check(i)) {
printf("%lld / %lld = %lld\n",base*i,i,base);
}
}

if (T) puts("");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: