USACO Dual Palindromes
输出N个大于s的满足条件的数, 对于满足条件的数的定义是其2-10进制表示中,至少有两种表示为回文串。。还是暴力:
/* ID: m1500293 LANG: C++ PROG: dualpal */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[200], len_a; int is[100000+100]; int judge() { bool flog = true; for(int i=0; i<len_a/2; i++) if(a[i] != a[len_a-1-i]) { flog = false; break; } return flog; } int pan(int n) //判断n是否满足条件 { int num = 0; for(int base=2; base<=10; base++) { len_a = 0; int tp = n; while(tp > 0) { a[len_a++] = tp%base; tp /= base; } if(judge()) num++; } return num>=2; } int main() { freopen("dualpal.in", "r", stdin); freopen("dualpal.out", "w", stdout); memset(is, 0, sizeof(is)); for(int i=1; i<=100000; i++) { if(pan(i)) is[i] = 1; } int n, s; while(scanf("%d%d", &n, &s) == 2) { int tp = 0; for(int i=s+1; tp<n; i++) { if(is[i]) { printf("%d\n", i); tp++; } } } return 0; }