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;
}

你可能感兴趣的:(HDU)