zoukankan      html  css  js  c++  java
  • 南阳理工oj88--汉诺塔(一)

    题目链接。http://acm.nyist.net/JudgeOnline/problem.php?pid=88


    #include <stdio.h>
    
    /*
    //测试一下49999和50000,1000000,1000000000你会发现规律.
    //关键是9个0的那个超大数输出的必须要快,否则超时.
    */
    int nunu(int a)
    {
        int i;
        int m=1;
        //a = a%50000;
        if (a>50000)
            a = a%50000+50000;
        for(i=2;i<=a;i++)
        {
            m = m*2+1;
            m = m%1000000;
        }
        return m;
    }
    int main()
    {
        int a;
        int n;
        scanf("%d",&n);
        while (n--)
        {
            scanf("%d",&a);
            printf("%d
    ",nunu(a));
        }
        return 0;
    }
    
    
    /*
    1-->1
    2-->3
    3-->7
    4-->15
    5-->31
    6-->63
    7-->127
    .
    .
    .
    n-->2*(n-1)+1
    */
    
    /*#include <stdio.h>
    int i=1;//记录步数
    void move(int n,char from,char to) //将编号为n的盘子由from移动到to
    {printf("第%d步:将%d号盘子%c---->%c
    ",i++,n,from,to);
    }
    void hanoi(int n,char from,char denpend_on,char to)//将n个盘子由初始塔移动到目标塔(利用借用塔)
    {
        if (n==1)
        move(1,from,to);//只有一个盘子是直接将初塔上的盘子移动到目的地
    	else
    	{
          hanoi(n-1,from,to,denpend_on);//先将初始塔的前n-1个盘子借助目的塔移动到借用塔上
    	  move(n,from,to);              //将剩下的一个盘子移动到目的塔上
    	  hanoi(n-1,denpend_on,from,to);//最后将借用塔上的n-1个盘子移动到目的塔上
    	}
    }
    
    int main()
    {
    	 printf("请输入盘子的个数:
    ");
    	 int n;
    	 scanf("%d",&n);
    	 char x='A',y='B',z='C';
    	 printf("盘子移动情况如下:
    ");
    	 hanoi(n,x,y,z);
    	 return 0;
    }
    */
    



  • 相关阅读:
    SecureCRT 迁移到新环境,配置导出
    Git 常用操作
    Java 性能分析工具 Asyncprofiler
    冒号语法
    后台乱码转中文
    js讲解视频
    下载指定版本的loader.调整文件夹结构
    react大型数据渲染列表
    git拉取报错
    记录一个排序表格的插件
  • 原文地址:https://www.cnblogs.com/acmwangpeng/p/5524871.html
Copyright © 2011-2022 走看看