zoukankan      html  css  js  c++  java
  • POJ 2402 Palindrome Numbers

    题目链接

    水题,LA我居然没找到在那里。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <string>
     4 #include <cmath>
     5 #include <ctime>
     6 #include <cstdlib>
     7 #include <iostream>
     8 using namespace std;
     9 #define LL long long
    10 LL dp[50],bin[50];
    11 int que[31],s;
    12 void judge(int x)
    13 {
    14     s = 0;
    15     while(x)
    16     {
    17         que[s++] = x%10;
    18         x /= 10;
    19     }
    20 }
    21 int main()
    22 {
    23     int i;
    24     LL temp,n,x;
    25     temp = 1;
    26     bin[0] = 1;
    27     for(i = 1;i <= 10;i ++)
    28     bin[i] = 10*bin[i-1];
    29     for(i = 1;i <= 20;i ++)
    30     {
    31         if(i%2 == 1)
    32         {
    33             dp[i] = temp*9;
    34             temp *= 10;
    35         }
    36         else
    37         {
    38             dp[i] = dp[i-1];
    39         }
    40     }
    41     while(cin>>n&&n)
    42     {
    43         for(i = 1;i <= 20;i ++)
    44         {
    45             if(n > dp[i])
    46             n -= dp[i];
    47             else
    48             {
    49                 if(i == 1)
    50                 cout<<n<<endl;
    51                 else if(i == 2)
    52                 cout<<n<<n<<endl;
    53                 else if(i%2 == 1)
    54                 {
    55                     x = bin[i/2] + n - 1;
    56                     cout<<x;
    57                     judge(x);
    58                     for(i = 1;i < s;i ++)
    59                     cout<<que[i];
    60                     cout<<endl;
    61                 }
    62                 else
    63                 {
    64                     x = bin[i/2-1] + n - 1;
    65                     cout<<x;
    66                     judge(x);
    67                     for(i = 0;i < s;i ++)
    68                     cout<<que[i];
    69                     cout<<endl;
    70                 }
    71                 break;
    72             }
    73         }
    74     }
    75     return 0;
    76 }

  • 相关阅读:
    bzoj 4911: [Sdoi2017]切树游戏
    bzoj 2654: tree
    bzoj 3240: [Noi2013]矩阵游戏
    有标号的DAG计数 III
    有标号的DAG计数 II
    bzoj 3512: DZY Loves Math IV
    bzoj 4480: [Jsoi2013]快乐的jyy
    bzoj 5323: [Jxoi2018]游戏
    codeforces412A
    7.6 T1 深度优先搜索(dfs)
  • 原文地址:https://www.cnblogs.com/naix-x/p/3381868.html
Copyright © 2011-2022 走看看