zoukankan      html  css  js  c++  java
  • hdu 1271 整数对

    看了别人的解题报告a了,

    大致思路就是

    A=a+b*10^k+c*10^(k+1)

    B=a+c*10^k (在A中取出一位数后)

    N=A+B=2*a+b*10^k+11*c*10^k

    这样就好做了,再就是注意进位可能影响b的值……

    链接http://acm.hdu.edu.cn/showproblem.php?pid=1271

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<iomanip>
    #include<cmath>
    #include<string>
    using namespace std;
    int
    main()
    {

        int
    n,i,j,a,b,ans[1000],m,c;
        while
    (cin>>n&&n)
        {

            m=0;
            for
    (i=1;i<=n;i*=10)
            {

                c=n/i/11;
                b=n/i%11;
                if
    (b+c!=0&&b<10)
                {

                    a=(n-b*i-11*c*i)/2;
                    if
    (2*a+b*i+11*c*i==n)
                        ans[m++]=a+b*i+10*c*i;
                }

                b--;
                if
    (b+c!=0&&b>=0)
                {

                    a=(n-b*i-11*c*i)/2;
                    if
    (2*a+b*i+11*c*i==n)
                        ans[m++]=a+b*i+10*c*i;
                }
            }

                if
    (m==0)
                    cout<<"No solution."<<endl;
                else

                {

                    sort(ans,ans+m);
                    cout<<ans[0];
                    for
    (i=1;i<m;i++)
                        if
    (ans[i]!=ans[i-1])
                            cout<<' '<<ans[i];
                    cout<<endl;
                }
        }

        return
    0;
    }

  • 相关阅读:
    【程序员的自我修养】读书笔记
    Notepad++ 正则表达式
    【BI】商务智能
    【BI】OLTP与OLAP的区别
    【Linux】条件判断eq、ne、gt、lt、ge、le
    【shell】shell基础脚本合集
    capture同focus
    c++101rule
    老生常谈,正确使用memset
    C语言的数组名和对数组名取地址
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3193564.html
Copyright © 2011-2022 走看看