Magical Sticks

    技术2022-07-12  71

    1.题目:

    A penguin Rocher has nn sticks. He has exactly one stick with length ii for all 1≤i≤n1≤i≤n.

    He can connect some sticks. If he connects two sticks that have lengths aa and bb, he gets one stick with length a+ba+b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his set and can be used for the next connections.

    He wants to create the maximum number of sticks that have the same length. It is not necessary to make all sticks have the same length, some sticks can have the other length. How many sticks with the equal length he can create?

    Input

    The input consists of multiple test cases. The first line contains a single integer t (1≤t≤10001≤t≤1000) — the number of test cases. Next tt lines contain descriptions of test cases.

    For each test case, the only line contains a single integer n (1≤n≤1091≤n≤109).

    Output

     

    For each test case, print a single integer  — the answer to the problem.

    Example

    Input

    Copy

    4 1 2 3 4

    Output

    Copy

    1 1 2 2

    Note

    In the third case, he can connect two sticks with lengths 11 and 22 and he will get one stick with length 33. So, he will have two sticks with lengths 33.

    In the fourth case, he can connect two sticks with lengths 11 and 33 and he will get one stick with length 44. After that, he will have three sticks with lengths {2,4,4}{2,4,4}, so two sticks have the same length, and one stick has the other length.

     

     

    2.题解:

    举例,进行分析:

     总而言之 ,当n为奇数时:y=(n+1)/2;

                        当n为偶数时:y=n/2=(n+1)/2;  //这样的话,无论n的奇偶性,y均可用y=(n+1)/2;表示,从而简化了代码。

    3:AC代码:

    #include<iostream> using namespace std; int main() { int n,t,y; cin>>t; for(int m=1;m<=t;m++){ cin>>n; y=(n+1)/2; cout<<y<<endl; } return 0; }

     

    Processed: 0.013, SQL: 9