| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这就是数学题啊In Reply To:注意了,这题不是数学题,是一个较好的递归题,0ms不轻松解决! Posted by:1272406003 at 2009-08-04 13:09:09 将数分三段,高位H,低位L,中间被strike掉的位S,则
X=(10H+S)*10^i+L (i = 0, 1, 2 ... 最多log10(N))
Y=H*10^i+L
N=X+Y=(11H+S)*10^i + 2L
将N/(10^i)得(11H+S) + 2L/(10^i),其中2L/(10^i)只可能为0和1,再加上i的不到10种取值,共20种不到的组合
每种组合都验证一下,答案就出来了
#include <iostream>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
long N, H, S, I, L, X, i = 0;
map<long, long> result, ri;
cin >> N;
for (I = 1; I <= N; I *= 10, i++) {
if (N % I % 2) continue;
H = N / I / 11;
L = N % I / 2;
S = N / I % 11;
if (S < 10) {
X = (10 * H + S) * I + L;
if (H + S) result[X] = H * I + L;
ri[X] = i;
}
L = (N % I + I) / 2;
S = N / I % 11 - 1;
if (S >= 0 && L) {
X = (10 * H + S) * I + L;
if (H + S) result[X] = H * I + L;
ri[X] = i;
}
}
cout << result.size() << endl;
for (map<long, long>::iterator it = result.begin(); it != result.end(); ++it)
cout << it->first << " + " << setw(ri[it->first]) << setfill('0') << it->second << " = " << N << endl;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator