zoukankan      html  css  js  c++  java
  • HDU1329 Hanoi Tower Troubles Again!——S.B.S.

    Hanoi Tower Troubles Again!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 602    Accepted Submission(s): 418


    Problem Description
    People stopped moving discs from peg to peg after they know the number of steps needed to complete the entire task. But on the other hand, they didn't not stopped thinking about similar puzzles with the Hanoi Tower. Mr.S invented a little game on it. The game consists of N pegs and a LOT of balls. The balls are numbered 1,2,3... The balls look ordinary, but they are actually magic. If the sum of the numbers on two balls is NOT a square number, they will push each other with a great force when they're too closed, so they can NEVER be put together touching each other.



    The player should place one ball on the top of a peg at a time. He should first try ball 1, then ball 2, then ball 3... If he fails to do so, the game ends. Help the player to place as many balls as possible. You may take a look at the picture above, since it shows us a best result for 4 pegs.
     
    Input
    The first line of the input contains a single integer T, indicating the number of test cases. (1<=T<=50) Each test case contains a single integer N(1<=N<=50), indicating the number of pegs available.
     
    Output
    For each test case in the input print a line containing an integer indicating the maximal number of balls that can be placed. Print -1 if an infinite number of balls can be placed.
     
    Sample Input
    2 4 25
     
    Sample Output
    11 337
     
    Source
     
    Recommend
    Ignatius.L   |   We have carefully selected several similar problems for you:  1308 1313 1317 1330 1297 
    ————————————————我是分割线————————————————————————————————
    一道水题。
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<queue>
     7 #include<cstdlib>
     8 #include<iomanip>
     9 using namespace std;
    10 int read(){
    11     int x=0,f=1;char ch=getchar();
    12     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    13     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    14     return x*f;
    15 }
    16 int main()
    17 {
    18     std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
    19      int t,n,i,f[55];
    20      f[1]=1;f[2]=3;
    21      for(i=3;i<=50;i++)
    22      {
    23          if(i%2)
    24                f[i]=f[i-1]+i+1;//当最小路径覆盖为奇数时,就=f[i-1]+i+1;
    25           else
    26                f[i]=f[i-1]+i;//否则就是上一个数+i;
    27      }
    28      cin>>t;
    29      while(t--)
    30      {
    31           cin>>n;
    32           cout<<f[n]<<endl;
    33      }
    34      return 0;
    35 }
    View Code
  • 相关阅读:
    BAT脚本批量调用Sql执行文件 (SqlServer 数据库)
    树莓派系统刻录到首次登陆等问题
    数据库视图的使用
    MQ配置安装
    PLSQL集合类型
    PLSQL-包函数存储过程
    Oracle 字段拆分替换在合并成一条
    ORACLE-EXP和IMP方法介绍
    javascript几个月前的时间
    返回顶部实现方式
  • 原文地址:https://www.cnblogs.com/AwesomeOrion/p/5492068.html
Copyright © 2011-2022 走看看