Moving Bricks
Time limit:2000/1000 MS (java/others) Memory limit:65535/65535 K (java/others)
Total submission (s): 4646 Accepted Submission (s): 1060
Problem Description Xiao Ming is now a person to see people love, flowers see flowers open Gaofu, all day immersed in beauty around the singer wonderful dance. But people do not know, the triumphant Xiao Ming also has a hard history of struggle.
At that time, Xiaoming has not cut long hair, no credit card without her, no 24 hours of hot water home, but the original xiaoming is so happy, although not even a broken wood guitar ...
The reason is happy, because then Xiao Ming had a dream of a reverse attack. One day, Xiao Ming in order to give his idea of the Goddess to buy a birthday gift, came to a construction site to move bricks to earn money. At this time, the construction site also brought a truck of bricks, contractor Jean Xiaoming The truck unloaded the pile of bricks into a piece (require any 2 pieces to be separated). As a senior porter, Xiaoming always divides a pile of bricks into two piles, at this time, the energy consumed is divided after the two piles of bricks difference.
Now, the number of bricks known to the truck, please tell xiaoming at least how much physical strength to complete the contractor required tasks?
Input data The first line is a positive integer t (t<=100), which indicates that there is a T group of test data.
The next T line is a positive integer N (n<=10000000) per line, indicating the number of bricks shipped by the truck.
Output for each set of data, print the minimum amount of physical strength that xiaoming needs to complete the task.
Sample Input245
Sample Output02 Title: A number divided into two parts is odd plus an even numbers I didn't know I was going to use God's search to write me in the queue has been the MLE with recursive write can pass
#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#include<algorithm>#include<iostream>#include<queue>#include<vector>using namespacestd;#defineN 1005intDfnintN) { if(n<=1) return 0; if(n%2==0) return 2*DFN (n/2); Else if(n%2==1) returnDFN (n/2) +DFN ((n+1)/2)+1;}intMain () {intT,n; scanf ("%d",&T); while(t--) {scanf ("%d",&N); printf ("%d\n", DFN (n)); } return 0;}
Moving bricks--Hangzhou Electric School Race (DFS)