阅读 69

题目1474: DotA

  • 题目1474: DotA

    题目描述

    DotA(Defence of the Ancients) is very popular in Zhejiang University.Now a new hero appears in DotA.This hero has a miraculous skill.If the target's HP n is an even number,then it will be cut in half after skill-using.Otherwise the targe's HP will plus one after skill-using.Given a target's HP,we want to decrease the target's HP from n to 1 only with this new skill.

     

    输入

    The input consists of multiple test cases.Each case contain one line with an integer n(1<n≤1000000000).

     

    输出

    For each test case,output the target's HP's changing process on a single line.The HP values connect with '-' character.

     

    样例输入

    5
    21

     

    样例输出

    5-6-3-4-2-1
    21-22-11-12-6-3-4-2-1

     

    提示 [+]

    *** 提示已隐藏,点击上方 [+] 可显示 ***

     

    来源

    2013年浙江大学复试机试模拟题

     

    /*********************************
    *   日期:2013-3-25
    *   作者:SJF0115
    *   题号: 题目1474: DotA
    *   来源:http://acmclub.com/problem.php?id=1474
    *   结果:AC
    *   来源:2013年浙江大学复试机试模拟题
    *   总结:
    **********************************/
    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
    	long long int N;
    	int first,i;
    	//freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin);
    	while(scanf("%lld",&N)!=EOF){
    		first = 1;
    		printf("%lld",N);
    		while(N > 1){
    			if(N % 2 == 0){
    				N = N / 2;
    			}
    			else{
    				N = N + 1;
    			}
    			printf("-");
    			printf("%lld",N);
    		}
    		printf("\n");
    	}
    	return 0;
    }



文章分类
代码人生
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐