Section 1.2.5 Dual Palindromes 水
http://www.wzoi.org/usaco/11%5C302.asp
pat
没太水了没什么好说的。
然而感觉如果不计代价的话,先把string reverse再比较是否相同来判断回文,好方便pat
#include <bits/stdc++.h> using namespace std; bool gao(int base, int n){ int i, j; string ans = ""; while(n){ ans += n % base + '0'; n /= base; } string rev(ans); reverse(rev.begin(), rev.end()); return rev == ans; } int main() { freopen("dualpal.in","r",stdin); #ifndef poi freopen("dualpal.out","w",stdout); #endif int i, j, n, beg, cnt = 0; scanf("%d%d", &n, &beg); for(i = beg + 1;cnt < n; i++){ int get = 0; for(j = 2;get < 2&& j <= 10; j++){ if(gao(j, i)) get ++; } if(get == 2) { printf("%d\n", i); cnt ++; } } return 0; }