Dualpal Problem Solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
Give N and S to find the first n double palindrome numbers greater than S.
Double palindrome number definition: two (or more) binaries in binary to decimal are palindrome numbers.
"Data Range"
1<=n<=15
0<s<10000
Integer variables greater than 4 bytes are not required
"Input Sample"
3 25
"Output Example"
26
27
28
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
No difficulty.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
It's a pity that it's not AC again. (in Main, the word "--n" forgot to write.) )
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Code
1 /*2 id:icedrea13 Prob:dualpal4 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten One intn,s; A - Charto (intx) {returnX-1+'1'; } - stringChangeintXintB) the { - stringnum; - while(x) {num=to (x%b) +num; x/=B;} - returnnum; + } - BOOLIspal (stringnum) + { A for(intI=0; I!=num.size (); + +i) at if(Num[i]!=num[num.size ()-1-I.])return false; - return true; - } - - intMain () - { inIfstreaminch("dualpal.in"); -Ofstream out("Dualpal.out"); to + intCNT; - inch>>N>>S; the while(N) * { $cout<<"n="<<N<<Endl;Panax Notoginseng++s; Cnt=0; - for(intb=2; b<=Ten; ++b) cnt+=Ispal (Change (s,b)); the if(cnt>=2) { out<<S<<endl; --N;} + } A the inch. Close (); + out. Close (); - return 0; $}
Usaco Section1.2 Dual palindromes Problem Solving report