ZCMU—1374
来源:互联网 发布:股市数据下载 编辑:程序博客网 时间:2024/06/08 17:40
1374: Greatest Naruto Army
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 23
[Submit][Status][Web Board]
Description
ccc is a VERY VERY BIG fans of Naruto(漩涡鸣人). Naruto's perseverance and passion attract him a lot, so does Naruto's skill "Kagebunsin no jyutu"(影分身术). Actually, ccc knows more details about "Kagebunsin no jyutu" than most of us. When Naruto makes an new illusion(幻象), his Chakra will divide into two parts A and B, and increase Naruto's weariness value by absolutely value of (A - B).
For example, at first Naruto have 5 Chakra, then he makes an illusion who has 2 Chakra. So he left 3 Chakra, and increase his weariness value by 1 (3 - 2). If he make a new illusion again and give him 2 Chakra, then he only left 1 Chakra and his weariness value changes to 2. Naruto cannot make a new illusion unless his Chakra is bigger than 1. What's more, Naruto's illusion can also use "Kagebunsin no jyutu" and the weariness they gains will also return to Naruto himself.
Now Naruto wants to make as many illusions as he can because Kakashi Sensei wants to teach him a new Ninjyutsu(忍术) and minimum his weariness value.
Input
The first line of input contains an integer T, indicating the number of test cases, then T lines follow , each line contains a positive integer N, indicating the number of Naruto's Chakra.
0 < N < 10000000;
Output
For each case ,output the minimum weariness value of Naruto when he makes the most illusions.
Sample Input
Sample Output
【分析】
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath> using namespace std;long long f[1001000];long long find(int x){if (x<=1000000) return f[x];if (x%2==0) return 2*find(x/2);else return find(x/2)+find(x/2+1)+1;}int main(){memset(f,-1,sizeof(f));f[0]=f[1]=f[2]=0;for (int i=3;i<=1000000;i++)if (i%2==0)f[i]=f[i/2]+f[i/2];else f[i]=f[i/2]+f[i/2+1]+1; int T_T;scanf("%d",&T_T);while (T_T--){int n;scanf("%d",&n);printf("%lld\n",find(n));}return 0;}
- ZCMU—1374
- ZCMU—1678
- ZCMU—1605
- ZCMU—1067
- ZCMU—1607
- ZCMU—1069
- ZCMU—1611
- ZCMU—1606
- ZCMU—1774
- ZCMU—1766
- ZCMU—1752
- ZCMU—1724
- ZCMU—1623
- ZCMU—1689
- ZCMU—1667
- ZCMU—1639
- ZCMU—1668
- ZCMU—1540
- [E10]展BOM
- JavaScript DOM编程艺术 第2版pdf
- 深入探讨Java中的异常与错误处理
- 51nod 1293 球与切换器
- 从Outlook导出联系人到VCF文件
- ZCMU—1374
- 高级加密标准AES的工作模式(ECB、CBC、CFB、OFB)
- jquery 判断获取单选值为空
- JVM-栈帧
- 比较好的Android开发帖子
- 有关ViewPager使用及解决ViewPager的item需要展示多个控件
- C#获取鼠标位置,模拟鼠标,模拟键盘(多方转载)
- memcached--统计命令
- scp命令