hduacm 5255
2015-06-03 00:08
267 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5255
枚举a和c 求解b
枚举a和c 求解b
#include <cstdio> #include <cstring> #include <map> #include <string> #include <algorithm> using namespace std ; typedef long long LL ; #define clr( a , x ) memset ( a , x , sizeof a ) #define ls ( o << 1 ) #define rs ( o << 1 | 1 ) #define lson ls , l , m #define rson rs , m + 1 , r #define mid ( ( l + r ) >> 1 ) #define root 1 , 1 , n const int L = 1000000 ; LL p[15] ; LL S[L] , top ; LL gcd ( LL a , LL b ) { return b ? gcd ( b , a % b ) : a ; } LL f ( LL pp , LL a , LL c , LL x1 , LL y1 ) { LL x = a * pp * x1 - c * pp * y1 + c * x1 - a * y1 ; LL y = ( y1 - x1 ) * 10 ; if ( x == 0 ) return 0 ; else if ( x > 0 && y < 0 || x < 0 && y > 0 ) return -1 ; else { if ( x % y ) return - 1 ; else return x / y ; } } char s[100] ; void solve () { int x = 0 , y = 1 , loc = 0 ; top = 0 ; scanf ( "%s" , s ) ; int n = strlen ( s ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( s[i] >= '0' ) { x = x * 10 + s[i] - '0' ; if ( loc ) y *= 10 ; } else loc = 1 ; } int g = gcd ( x , y ) ; int x1 = x / g ; int y1 = y / g ; for ( int i = 1 ; i <= 9 ; ++ i ) { for ( int a = 1 ; a <= 9 ; ++ a ) { for ( int c = 0 ; c <= 9 ; ++ c ) { LL b = f ( p[i] , a , c , x1 , y1 ) ; if ( b < 0 || b * 10 >= p[i] ) continue ; LL t = a * p[i] + b * 10 + c ; S[top ++] = t ; } } } printf ( "%d\n" , top ) ; sort ( S , S + top ) ; for ( int i = 0 ; i < top ; ++ i ) { printf ( "%I64d%c" , S[i] , i < top - 1 ? ' ' : '\n' ) ; } } int main () { int T ; p[0] = 1 ; for ( int i = 1 ; i <= 12 ; ++ i ) { p[i] = p[i - 1] * 10 ; } scanf ( "%d" , &T ) ; for ( int i = 1 ; i <= T ; ++ i ) { printf ( "Case #%d:\n" , i ) ; solve () ; } return 0 ; }
相关文章推荐
- URAL 1152 Faise Mirrors 状压DP 简单题
- 2.Android整理清单
- Android 水波纹点击效果(Ripple Effect)
- Aurora协议调研
- LeetCode——Add Two Numbers
- Container With Most Water
- ftps
- Activity类
- HDOJ 1465 不容易系列之一(错排公式)
- C语言的角落(二)——你不一定知道的C语言特性
- 输出Bag中的所有记录为一个只有值的json数组---精通android、IOS App应用服务程序开发
- Linux Shell脚本查看NUMA信息
- python实用代码片段收集贴
- 解密Python中的描述符(descriptor)
- Python实现建立SSH连接的方法
- python操作ssh实现服务器日志下载的方法
- Python读写配置文件的方法
- python处理二进制数据的方法
- python下paramiko模块实现ssh连接登录Linux服务器
- Python中的深拷贝和浅拷贝详解