zoukankan      html  css  js  c++  java
  • USACO Section1.2 Dual Palindromes 解题报告

        dualpal解题报告 —— icedream61 博客园(转载请注明出处)
    ------------------------------------------------------------------------------------------------------------------------------------------------
    【题目】
      给出N和S,找出大于S的前N个双回文数。
      双回文数定义:在二进制至十进制中的两种(或两种以上)进制下是回文数。
    【数据范围】
      1<=N<=15
      0<S<10000
      本题不需要使用大于4字节的整型变量
    【输入样例】
      3 25
    【输出样例】
      26
      27
      28
    ------------------------------------------------------------------------------------------------------------------------------------------------
    【分析】
      没难度。
    ------------------------------------------------------------------------------------------------------------------------------------------------
    【总结】
      很可惜,又不是一遍AC。(在main中,“--N”一句忘了写了。)

    ------------------------------------------------------------------------------------------------------------------------------------------------

    【代码】

     1 /*
     2 ID: icedrea1
     3 PROB: dualpal
     4 LANG: C++
     5 */
     6 
     7 #include <iostream>
     8 #include <fstream>
     9 using namespace std;
    10 
    11 int N,S;
    12 
    13 char to(int x) { return x-1+'1'; }
    14 string change(int x,int B)
    15 {
    16     string num;
    17     while(x) { num=to(x%B)+num; x/=B; }
    18     return num;
    19 }
    20 bool isPal(string num)
    21 {
    22     for(int i=0;i!=num.size();++i)
    23         if(num[i]!=num[num.size()-1-i]) return false;
    24     return true;
    25 }
    26 
    27 int main()
    28 {
    29     ifstream in("dualpal.in");
    30     ofstream out("dualpal.out");
    31 
    32     int cnt;
    33     in>>N>>S;
    34     while(N)
    35     {
    36         cout<<"N="<<N<<endl;
    37         ++S; cnt=0;
    38         for(int B=2;B<=10;++B) cnt+=isPal(change(S,B));
    39         if(cnt>=2) { out<<S<<endl; --N; }
    40     }
    41 
    42     in.close();
    43     out.close();
    44     return 0;
    45 }
  • 相关阅读:
    apache安全—用户访问控制
    hdu 3232 Crossing Rivers 过河(数学期望)
    HDU 5418 Victor and World (可重复走的TSP问题,状压dp)
    UVA 11020 Efficient Solutions (BST,Splay树)
    UVA 11922 Permutation Transformer (Splay树)
    HYSBZ 1208 宠物收养所 (Splay树)
    HYSBZ 1503 郁闷的出纳员 (Splay树)
    HDU 5416 CRB and Tree (技巧)
    HDU 5414 CRB and String (字符串,模拟)
    HDU 5410 CRB and His Birthday (01背包,完全背包,混合)
  • 原文地址:https://www.cnblogs.com/icedream61/p/4321427.html
Copyright © 2011-2022 走看看