zoukankan      html  css  js  c++  java
  • hduacm 5255

    http://acm.hdu.edu.cn/showproblem.php?pid=5255

    枚举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
    " , top ) ;
        sort ( S , S + top ) ;
        for ( int i = 0 ; i < top ; ++ i ) {
            printf ( "%I64d%c" , S[i] , i < top - 1 ? ' ' : '
    ' ) ;
        }
    }
    
    
    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:
    " , i ) ;
            solve () ;
        }
        return 0 ;
    }
    爱程序 不爱bug 爱生活 不爱黑眼圈 我和你们一样 我和你们不一样 我不是凡客 我要做geek
  • 相关阅读:
    linux下程序运行时间的获取方法,
    网络通信过程(转&自己完善)
    关于找工作&毕设
    linux进程间通信(IPC)几种方式
    asp.net2.0新特性概述 之二
    vs2005新特性
    C#高级特性
    Asp.net2.0新特性 之三
    当前流行的网站设计风格(转贴)
    ASP.NET 2.0 新特性 之一
  • 原文地址:https://www.cnblogs.com/yifi/p/4548096.html
Copyright © 2011-2022 走看看