第2-10错了,哪里出了问题啊?

P1207 [USACO1.2] 双重回文数 Dual Palindromes

```cpp #include<bits/stdc++.h> using namespace std; int const N = 100000 + 5; int n, m, p;//大于m的n个双重回文数 bool pd2(int x, int y){//x待判断数;y进制 int s[N], d, z1, z2, h; d = 1; h = 1; while(x > 0){ s[d] = x % y; x /= y; d++; } while(1){ if(h = d / 2) break; else if(s[h] != s[d + 1 - h]) return false; else h++; } return true; } bool pd1(int x){ for(int i = 2; i <= 10; ++i) if(pd2(x, i))p++; if(p >= 2)return true; else return false; } int main(){ cin >> n >> m; for(int i = m + 1; n > 0;++i) if(pd1(i)){ cout << i << endl; n--; } return 0; } ``` 改一下仍然错6个点
by 洋葱头www @ 2022-04-23 17:02:04


```cpp #include<bits/stdc++.h> using namespace std; int pd(int n,int k) { int p[1005]; int t=0; while(n!=0) { p[++t]=n%k; n/=k; } for(int i=1,j=t;i<=t/2;i++,j--) if(p[i]!=p[j]) return 0; return 1; } int main(){ int n,s,ans=0; cin>>n>>s; for(int i=s+1;ans<n;i++) { int count=0; for(int j=2;j<=10;j++) if(pd(i,j)==1) ++count; if(count>=2) { ++ans; cout<<i<<endl; } } return 0; } 这样能AC(求关注)
by lienze2012 @ 2023-04-25 22:23:26


|