UVA 725 - Division
2015-07-29 08:58
495 查看
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666
题 意:给你一个数n,找出有1----9组成的两个五位数满足x/y==n。
思 路:直接暴力即可。即直接在(1000,100000)内枚举y。
代码如下:
题 意:给你一个数n,找出有1----9组成的两个五位数满足x/y==n。
思 路:直接暴力即可。即直接在(1000,100000)内枚举y。
代码如下:
#include <iostream> using namespace std; #include <string.h> #include <stdio.h> #include <queue> #include <algorithm> int a[10]; int sum( int x, int y ) { if( y > 98765 ) return 0; memset(a,0,sizeof(a)); if(x<10000) a[0]=1; while( x ) { a[x%10]++; x/=10; } while(y) { a[y%10]++; y/=10; } for( int i = 0; i < 10; i ++ ) { if(a[i]>1) return 0; if(a[i]==0) return 0; } return 1; } int main() { int n,ans=0; while( scanf ( "%d", &n ) != EOF ) { if( n == 0 ) break; if(ans++) printf("\n"); int f = 1; for( int i = 1234; i < 100000; i ++ ) if( sum( i, i*n ) ) { f=0; printf("%05d / %05d = %d\n",i*n,i,n); } if( f ) printf("There are no solutions for %d.\n",n); } return 0; }
相关文章推荐
- 用fail2ban阻止SSH和VSFTP暴力破解密码
- 2015BJOI day1第三题 糖果candy
- 4495: Least Prime factor 找到最小质因子P的第N小正整数
- POJ 2965.The Pilots Brothers' refrigerator
- POJ 1753.Flip Game
- POJ 3295.Tautology
- 没参加的2015百度之星——数矩形
- Birthday Cake——直线分割
- Spiral——找规律暴力
- POJ 1166&IOI 1994 The blocks 暴力枚举 解题报告
- hdu 1248
- LCM Challenge(暴力)
- 小晴天老师系列——竖式乘法(暴力)
- URAL 1786 Sandro's Biography
- URAL 1788 On the Benefits of Umbrellas
- URAL 1792 Hamming Code
- URAL 1794 Masterpieces of World Architecture
- URAL 1796 Amusement Park
- HDU 5207 Greatest Greatest Common Divisor
- HDU3183 A 4000 Magic Lamp