zoukankan      html  css  js  c++  java
  • Codeforces Round #633 (Div. 2)

    You have integer nn. Calculate how many ways are there to fully cover belt-like area of 4n24n−2 triangles with diamond shapes.

    Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it.

    22 coverings are different if some 22 triangles are covered by the same diamond shape in one of them and by different diamond shapes in the other one.

    Please look at pictures below for better understanding.

    On the left you can see the diamond shape you will use, and on the right you can see the area you want to fill.

    These are the figures of the area you want to fill for n=1,2,3,4n=1,2,3,4.

    You have to answer tt independent test cases.

    Input

    The first line contains a single integer tt (1t1041≤t≤104) — the number of test cases.

    Each of the next tt lines contains a single integer nn (1n1091≤n≤109).

    Output

    For each test case, print the number of ways to fully cover belt-like area of 4n24n−2 triangles using diamond shape. It can be shown that under given constraints this number of ways doesn't exceed 10181018.

    Example
    input
    Copy
    2
    2
    1
    
    output
    Copy
    2
    1
    思路 胡乱猜一下就出来了直接输出n.
    #include<bits/stdc++.h>
    #include<map>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int n;
            cin>>n;
            cout<<n<<endl;
    
        }
    }
    View Code
    B. Sorted Adjacent Differences
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You have array of nn numbers a1,a2,,ana1,a2,…,an.

    Rearrange these numbers to satisfy |a1a2||a2a3||an1an||a1−a2|≤|a2−a3|≤…≤|an−1−an|, where |x||x| denotes absolute value of xx. It's always possible to find such rearrangement.

    Note that all numbers in aa are not necessarily different. In other words, some numbers of aa may be same.

    You have to answer independent tt test cases.

    Input

    The first line contains a single integer tt (1t1041≤t≤104) — the number of test cases.

    The first line of each test case contains single integer nn (3n1053≤n≤105) — the length of array aa. It is guaranteed that the sum of values of nn over all test cases in the input does not exceed 105105.

    The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (109ai109−109≤ai≤109).

    Output

    For each test case, print the rearranged version of array aa which satisfies given condition. If there are multiple valid rearrangements, print any of them.

    题意:给你n个数然后调整顺序,使得 |a1a2||a2a3||an1an||a1−a2|≤|a2−a3|≤…≤|an−1−an|;

    思路 先排序,然后把最大的压入栈中,然后最小的,然后第二大,第二小...............。最后输出,就满足题意了。

    #include<bits/stdc++.h>
    #include<stack>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int n;
            cin>>n;
            stack<int>q;
            int a[100005];
            for(int i=0; i<n; i++)
            {
                cin>>a[i];
            }
            sort(a,a+n);
            int l=0,r=n-1;
            if(n%2==0)
            {
                while(l<r)
                {
    
                    q.push(a[r]);
                    q.push(a[l]);
                    l++;
                    r--;
                }
            }
            else
            {
                while(l<=r)
                {
    
                    q.push(a[r]);
                    q.push(a[l]);
                    l++;
                    r--;
                }
                q.pop();
            }
            while(!q.empty())
            {
                cout<<q.top()<<" ";
                q.pop();
            }
    
        }
    }
    View Code
    C. Powered Addition
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You have an array aa of length nn. For every positive integer xx you are going to perform the following operation during the xx-th second:

    • Select some distinct indices i1,i2,,iki1,i2,…,ik which are between 11 and nn inclusive, and add 2x12x−1 to each corresponding position of aa. Formally, aij:=aij+2x1aij:=aij+2x−1 for j=1,2,,kj=1,2,…,k. Note that you are allowed to not select any indices at all.

    You have to make aa nondecreasing as fast as possible. Find the smallest number TT such that you can make the array nondecreasing after at most TT seconds.

    Array aa is nondecreasing if and only if a1a2ana1≤a2≤…≤an.

    You have to answer tt independent test cases.

    Input

    The first line contains a single integer tt (1t1041≤t≤104) — the number of test cases.

    The first line of each test case contains single integer nn (1n1051≤n≤105) — the length of array aa. It is guaranteed that the sum of values of nn over all test cases in the input does not exceed 105105.

    The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (109ai109−109≤ai≤109).

    Output

    For each test case, print the minimum number of seconds in which you can make aa nondecreasing.

    Example
    input
    3
    4
    1 7 6 5
    5
    1 2 3 4 5
    2
    0 -4
    
    output
    2
    0
    3
    题意 给你一个数组,你可以在第x秒选一些元素让它们都加上 2^(x-1),问至少需要多少秒可以使数组变成非递减的数组。
    思路:既然找最少用的时间,肯定找到当在某处出现递减的时候和前面最大值得差的最大值(也就是所有逆序对差值中最大的那个),看这个差值需要加多少次2^(x-1)才能的到。(这里就要想到这道题和2进制相关了)
    比如 最大的差值是12 则需要2^3+2^2.可以发现就是转换成2进制 12的二进制是1100 ->1*2^3+1*2^2+0*2^1+0*2^1。
    那么所需要的时间也就是这个数二进制总共有多少位。
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long  ll;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            int n;
            cin>>n;
            int a[100005];
            for(int i=0; i<n; i++)
            {
                cin>>a[i];
            }
            int Max=a[0];
            int Mad=0;
            for(int i=1; i<n; i++)
            {
                if(a[i]<Max)
                {
                 Mad=max(Mad,(Max-a[i]));
                }
                else if(a[i]>=Max)
                {
                    Max=a[i];
                }
            }
            if(Mad==0)
            {
                cout<<"0"<<endl;
                continue;
            }
            else
            {
                int ans=0;
                while(Mad)
                {
                   Mad/=2;
                   ans++;
    
                }
                cout<<ans<<endl;
    
            }
    
        }
    }
    View Code


  • 相关阅读:
    多种 网页文本编辑器 分析
    struts2 令牌 实现源代码 JSP
    ibatis 数据库时间 插入数据
    Eclipse/Myeclipse生成serialVersionUID方法
    SSM框架整合遇到的问题
    搭建Elasticsearch5.6.8 分布式集群
    使用SuperWebSocket 构建实时 Web 应用
    HAPROXY
    .NET面试题系列(二)GC
    MongoDB-3.4集群搭建:分片
  • 原文地址:https://www.cnblogs.com/sszywq/p/12692601.html
Copyright © 2011-2022 走看看