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

    A. Left-handers, Right-handers and Ambidexters
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and aambidexters, who can play with left or right hand.

    The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.

    Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.

    Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.

    Input

    The only line contains three integers lr and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.

    Output

    Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.

    Examples
    input
    Copy
    1 4 2
    output
    6
    input
    Copy
    5 5 5
    output
    14
    input
    Copy
    0 2 0
    output
    0
    Note

    In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.

    In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.

    有l个人支持偏左意见,r个人支持偏右意见,还有a个人是中立的,你要把他们组合成一个为偶数,势力均等的团体

    就有把中立的人加到一队然后平均,加到人少的那一队这两种情况

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int l,r,a;
        cin>>l>>r>>a;
        if(l<r)swap(l,r);
        int c=l-r;
        if(a>c)
            cout<<l+r+c+(a-c)/2*2;
        else
            cout<<min(l,r+a)*2;
        return 0;
    }
    B. Intercepted Message
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.

    Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive.

    Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.

    You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.

    Input

    The first line contains two integers nm (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages.

    The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message.

    The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message.

    It is guaranteed that x1 + ... + xn = y1 + ... + ymAlso, it is guaranteed that x1 + ... + xn ≤ 106.

    Output

    Print the maximum number of files the intercepted array could consist of.

    Examples
    input
    Copy
    7 6
    2 5 3 1 11 4 4
    7 8 2 4 1 8
    output
    3
    input
    Copy
    3 3
    1 10 100
    1 100 10
    output
    2
    input
    Copy
    1 4
    4
    1 1 1 1
    output
    1
    Note

    In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8.

    In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100.

    In the third example the only possibility is that the archive contains a single file of size 4.

     两个序列的和是相等的啊,所以放心往下加到相等,统计就好了

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=1e5+5;
    int x[N],y[N];
    int main()
    {
        ios::sync_with_stdio(false);
        int n,m;
        cin>>n>>m;
        for(int i=0; i<n; i++)
            cin>>x[i];
        for(int i=0; i<m; i++)
            cin>>y[i];
        int sum=0,pos=0;
        for(int i=0; i<n; i++)
        {
            ll suma=x[i],sumb=0;
            while(sumb!=suma)
            {
                if(sumb<suma)
                    sumb+=y[pos++];
                else
                    suma+=x[++i];
            }
            sum++;
        }
        cout<<sum;
        return 0;
    }
    C. Zebras
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.

    Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.

    Input

    In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.

    Output

    If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≤ k ≤ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≤ li ≤ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.

    Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.

    Examples
    input
    Copy
    0010100
    output
    3
    3 1 3 4
    3 2 5 6
    1 7
    input
    Copy
    111
    output
    -1

     C就是要大力模拟的,不太好写

    #include<bits/stdc++.h>
    using namespace std;
    const int N=2e5+5;
    string s;
    set<int> f[2];
    vector<int> ans[N];
    int main()
    {
        cin>>s;
        for(int i=0;s[i];i++)
            if(s[i]=='0')f[0].insert(i+1);
            else f[1].insert(i+1);
        int ZZ=0,F=0,cnt=0;
        set<int>::iterator it;
        while(f[0].size()||f[1].size())
        {
            it=f[ZZ].upper_bound(F);
            if(it==f[ZZ].end())
            {
                if(ZZ==1)
                    F=0,ZZ=0,cnt++;
                else
                {
                    cout<<-1<<endl;
                    return 0;
                }
            }
            else
            {
                F=*it,ans[cnt].push_back(F),f[ZZ].erase(it);
                ZZ=ZZ?0:1;
                if(ZZ==0&&f[0].size()==0)
                {
                    cout<<-1<<endl;
                    return 0;
                }
            }
        }
        cout<<cnt+1<<endl;
        for(int i=0;i<=cnt;i++)
        {
            cout<<ans[i].size()<<" ";
            for(int j=0;j<ans[i].size();j++)
                cout<<ans[i][j]<<" ";
            cout<<endl;
        }
        return 0;
    }
    D. A Leapfrog in the Array
    time limit per test
    2 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard output

    Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm.

    Let's consider that initially array contains n numbers from 1 to n and the number i is located in the cell with the index 2i - 1 (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number written in it to the nearest empty cell to the left of the selected one. The process continues until all n numbers will appear in the first n cells of the array. For example if n = 4, the array is changing as follows:

    You have to write a program that allows you to determine what number will be in the cell with index x (1 ≤ x ≤ n) after Dima's algorithm finishes.

    Input

    The first line contains two integers n and q (1 ≤ n ≤ 1018, 1 ≤ q ≤ 200 000), the number of elements in the array and the number of queries for which it is needed to find the answer.

    Next q lines contain integers xi (1 ≤ xi ≤ n), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes.

    Output

    For each of q queries output one integer number, the value that will appear in the corresponding array cell after Dima's algorithm finishes.

    Examples
    input
    Copy
    4 3
    2
    3
    4
    output
    3
    2
    4
    input
    Copy
    13 4
    10
    5
    4
    8
    output
    13
    3
    8
    9
    Note

    The first example is shown in the picture.

    In the second example the final array is [1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7].

     D找规律,超级水的

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=1e5+5;
    int a[N];
    int main()
    {
        int n;
        while(cin>>n)
        {
            for(int i=1; i<=n; i++)
                a[2*i-1]=i,a[2*i]=0;
            int f=n+n-1;
            for(int i=n+n-1; i>0; i--)
            {
                if(!a[i])
                {
    
                    cout<<i<<" "<<f<<"
    ";
                    swap(a[i],a[f]);
                    --f;
                }
            }
            for(int i=1; i<=n; i++)
                cout<<a[i]<<"
    ";
        }
        return 0;
    }

    很容易发现奇数位是确定的,而且每次加的也是确定的,所以qlogn稳过啊

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main()
    {
        ll n,q,x,t;
        cin>>n>>q;
        while(q--)
        {
            cin>>x;
            if(x&1)
                cout<<(x+1)/2<<"
    ";
            else
            {
                t=n-x/2;
                while(t%2==0)
                    x+=t,t/=2;
                cout<<(x+t+1)/2<<"
    ";
            }
        }
        return 0;
    }
  • 相关阅读:
    使用python-gitlab包在gitlab上自动创建分组
    navicat连接远程mysql失败
    Python shell介绍
    Python任务流taskflow
    Python导包问题
    demo27-数组去重
    demo26-通过循环输出数据到页面显示
    demo25-for循环
    Visual Studio 2005 快捷键汇总
    三维立体图片效果
  • 原文地址:https://www.cnblogs.com/BobHuang/p/8536931.html
Copyright © 2011-2022 走看看