基本思想:
难倒是不难,但是卡在了方法上;
自己的思想史正确的,通过规律枚举来进行枚举,但是卡在了后续的输出和反转上;
做每道题先三分钟思考为妙;
关键点:
1.一定要注意数学建模问题,对于边界计算一定要注意;
2.反转输出并不一定要靠字符串,可以直接在已知数据大小的情况下直接乘数达到反转的目的;
3.对于题目中的增序要求可以在枚举过程中实现,还是要注意建模问题;
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> using namespace std; using std::vector; void five_s(int n) { int a,b,c; for(a=1;a<=9;a++) { for(b=0;b<=9;b++) { if(2*(a+b)<=n&&(n-2*a-2*b)<10) cout<<a*10000+b*1000+(n-2*a-2*b)*100+b*10+a<<endl; } } return ; } void six_s(int n) { int a,b,c; for(a=1;a<10;a++) { for(b=0;b<10;b++) { if(2*(a+b)<=n&&(n-2*a-2*b)<20) cout<<a*100000+b*10000+(n-2*a-2*b)*550+b*10+a<<endl; } } return; } int main() { int n; while(cin>>n){ if(n<=45) five_s(n); if(n%2==0&&n<=54) six_s(n); if(n>54||(n>45&&n&1!=0)) cout<<-1<<endl; } return 0; }
蓝桥杯 1434: [蓝桥杯][历届试题]回文数字 Easy only once *一定要注意数学建模问题
原文:https://www.cnblogs.com/songlinxuan/p/12271744.html