SDNU 1474.特殊回文数(水题)
生活随笔
收集整理的這篇文章主要介紹了
SDNU 1474.特殊回文数(水题)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
123321是一個非常特殊的數,它從左邊讀和從右邊讀是一樣的。
???????輸入一個正整數n,? 編程求所有這樣的五位和六位十進制數,滿足各位數字之和等于n? 。(1< =n< =54)
Input
輸入一行,包含一個正整數n。Output
按從小到大的順序輸出滿足條件的整數,每個整數占一行。Sample Input
52Sample Output
899998 989989 998899思路:一開始我想的是用暴力來解決,就是6個for循環(從0~9)來計算,時間復雜度也不過是10^6,沒想到居然計算不出來,就只能優化成這樣的了。
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int maxn = 5100;int n, id, a[58][100][100], num[100], number[100];int main() {scanf("%d", &n);id = 0;for(int i = 10000; i<999999; i++){int ge = i%10;int shi = (i/10)%10;int bai = (i/100)%10;int qian = (i/1000)%10;int wan = (i/10000)%10;int shiwan = i/100000;if(i <= 100000 && ge+shi+bai+qian+wan == n && ge == wan && shi == qian){num[id] = i;id++;}else if(i>100000 && ge+shi+bai+qian+wan+shiwan == n && ge == shiwan && shi == wan && bai == qian){num[id] = i;id++;}}for(int i = 0; i<id; i++)printf("%d\n", num[i]);return 0; }
?
轉載于:https://www.cnblogs.com/RootVount/p/11249090.html
總結
以上是生活随笔為你收集整理的SDNU 1474.特殊回文数(水题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SDNU 1481.纪念品分组(水题)
- 下一篇: SDNU 1469.校门外的树(水题)