HDU3181 Greatest Naruto Army

6 篇文章 0 订阅

Greatest Naruto Army

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 801    Accepted Submission(s): 522


Problem Description
Wyb 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, wyb 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
  
  
2 5 9
 

Sample Output
  
  
2 3
 


#include <stdio.h>
#include <string.h>
int dg(long n)
{/*
	if(n<10001&&a[n]!=-1)
	{
	   return a[n];
	}
	
    if(n<10001)
	{
	  if(n%2==0)
	      return a[n]=dg(n/2)*2;
	  else
		  return a[n]=dg(n/2)+dg(n-n/2)+1;
	}
	
	else
	{
	     if(n%2==0)
	      return dg(n/2)*2;
	  else
		  return dg(n/2)+dg(n-n/2)+1;
	}*/
    if(n==1||n==2||n==0)
	  return 0;
	if(n%2==0)
		return dg(n/2)*2;
	else
        return dg(n/2)+dg(n-n/2)+1;
}
int main(int argc, char* argv[])
{
	int n;
	int i;
	long num;
	scanf("%d", &n);	
	memset(a,-1, sizeof(a));
    a[0]=a[1]=a[2]= 0;
	for (i = 0; i < n; i++)
	{
		scanf("%ld", &num);
		printf("%ld\n", dg(num));
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值