題目描述 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年浙江大學復試機試模擬題 [cpp] /********************************* * 日期: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; } /********************************* * 日期: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; }