首页 > 代码库 > HDU-5551 Huatuo's Medicine
HDU-5551 Huatuo's Medicine
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 663 Accepted Submission(s): 480
Problem DescriptionHuatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these bottles together.
However, there was a critical problem. When Huatuo arrived the patient‘s home, he took the chain out of his bag, and he could not recognize which bottle contains which type of medicine, but he remembers the order of the bottles on the chain.
Huatuo has his own solution to resolve this problem. When he need to bring 2 types of medicines, E.g. A and B, he will put A into one bottle and put B into two bottles. Then he will chain the bottles in the order of ′−B−A−B−′. In this way, when he arrived the patient‘s home, he knew that the bottle in the middle is medicine A and the bottle on two sides are medicine B.
Now you need to help Huatuo to work out what‘s the minimal number of bottles needed if he want to bring N types of medicine.
InputThe first line of the input gives the number of test cases, T(1≤T≤100). T lines follow. Each line consist of one integer N(1≤N≤100), the number of types of the medicine.
OutputFor each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimal number of bottles Huatuo needed.
Sample Input12Sample OutputCase #1: 3
题意:华佗分不清绳子的左右,要有n种药时最少要多少瓶子才能分得出。
除了第一种每增加一种就在两边各加一瓶。
昨晚临走前十分钟写了一发2*n-1结果wa了,还以为是我想的太简单,结果发现是输出格式问题...
附AC代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main(){ 5 int t,n; 6 cin>>t; 7 int ans=1; 8 while(t--){ 9 cin>>n;10 cout<<"Case #"<<ans++<<": "<<2*n-1<<endl;11 }12 return 0;13 }
HDU-5551 Huatuo's Medicine
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。