hdu 5062 单峰数(12321)的个数

http://acm.hdu.edu.cn/showproblem.php?pid=5062

模拟筛出对称单峰数(12321)的个数,水题

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;

int n;
char s[10];
const double pi = acos ( -1.0 ) ;
bool ok(int x)
{
    int y = 0;
    while(x){
        s[y++] = x%10;
        x /= 10;
    }
    for(int i = 0,j = y - 1;i <= j;++i,--j)
        if(s[i] != s[j] || (i >= 1 && s[i] <= s[i-1]))
            return false;
    return true;
}
void work()
{
    int res = 0;
    n = (int)pow(10,n);
    //cout<<n;
    for(int i = 1;i <= n;++i){
        if(ok(i))
            res++;
    }
    printf("%d\n",res);
    return;
}
int main () {
    int T;
    RD(T);
    while(T--){
        RD(n);
        work();
    }
	return 0 ;
}


你可能感兴趣的:(hdu 5062 单峰数(12321)的个数)