链接:https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40669755

来源:牛客网

题目描述

    As an acmer, Devil Aguin particularly loves numbers. This time, with a sequence consisting of n elements 1∼n initially, Devil Aguin asks you to process the sequence until all the elements in it turn to zero. What you can do in one operation are as following :

    1. Select some elements from the sequence arbitrarily.

    2. Select a positive integer x arbitrarily.

    3. Subtract x from the elements you select.

    It is obvious that there are various methods to make elements of the sequence turn to zero. But Devil Aguin demands of you to use the minimum operations. Please tell him how many operations you will use.


输入描述:
The first line contains an integer number T, the number of test cases.

    ithith of each next T lines contains one integer n(1≤n≤1001≤n≤100), the number of sequence.

输出描述:
For each test case print a number, the minimum number of operations required.

示例1

输入

2

1

2

输出

1

2

思路

这道题的大概意思是输入t组数据,每组数据有一个数n,代表1~n的数,每次操作可以对任意数减去其中的某个数,直到所有数为0;这道题我们可以简化成将其最大的数n变为0当然我们不能直接减n,通过找规律发现每次减去中间值数是最划算的

代码:

#include<bits/stdc++.h>

using namespace std;

int main()

{

       int t;

       cin>>t;

       while(t--)//对于t组数据

       {

              int n;

              cin>>n;

              int s=0;

              while(n)//当最大值n为0时跳出来

              {

                     s++;

                     if(n%2==0)//每次减去中间值

                     n=n/2;

                     else

                     n=(n-1)/2;

              }

              cout<<s<<endl;

       }

 }