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

    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.

     题意:一部分人喜欢用左手,一部分人喜欢用右手,一部分人两只手都可以用。

    现在要你分组,使得用左手的人和用右手的人一样多。尽量两边的人都最多。

    求人数。

     1 #include <iostream>
     2 
     3 using namespace std;
     4 
     5 int n,m,k;
     6 
     7 int main(){
     8     cin>>n>>m>>k;
     9     int sum =0;
    10     int a = min(n,m);
    11     int b = max(n,m);
    12     int c = k-(b-a);
    13     if(c>=0){
    14         sum = b*2;
    15         sum+=(c/2)*2;
    16     }else{
    17         sum= a*2;
    18         sum+=k*2;
    19     }
    20     cout<<sum<<endl;
    21     return 0;
    22 }
    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.

    题意: 这个就是要将第一组数据放到第二组里面去,求最多可以分成多少组,其实直接用前缀和做一个标记数组就行了。

    剩下的就只要吧第二组前缀也算出来。有重复的就算一次了。

     1 #include <iostream>
     2 #define ll long long int
     3 #define N 1000005
     4 using namespace std;
     5 int n,m;
     6 int an[N];
     7 int bn[N];
     8 ll ans[N];
     9 int main(){
    10     cin>>n>>m;
    11     for(int i=0;i<n;i++)
    12         cin>>an[i];
    13     for(int i=0;i<m;i++)
    14         cin>>bn[i];
    15     ll cnt=0;
    16     for(int i=0;i<n;i++){
    17         cnt+=an[i];
    18         ans[cnt]++;
    19     }
    20     cnt = 0;
    21     int sum = 0;
    22     for(int i=0;i<m;i++){
    23         cnt+=bn[i];
    24         if(ans[cnt])
    25             sum++;
    26     }
    27     cout<<sum<<endl;
    28     return 0;
    29 }
    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

    题意: 给定01串,需要把串中所有元素用上,且必须是"01"间隔或者"0"单独一个的形式。还有一个条件就是子串前后只能是零。

      否则就输出“-1”.

    思路:模拟即可,用二维vector存取,每遇到0就放到最后一个元素为1的容器集合内;

       若无,则创建一个新的容器集合;
       如样例"0010100"
       0 a[1][0]
       0 a[2][0]
       遇到1,则放a[2][1],接下来遇到0继续在a[2][2]补上,1 a[2][3]补上,0 a[2][4];
       再遇到最后一个0,原理同第二个0,新建一个a[3][0].

    一开始我也没看懂题意。之后才看懂。

    贴代码了,代码好理解。

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #define N 200005
     5 using namespace std;
     6 string s;
     7 vector<int> v[N];
     8 int main(){
     9     cin>>s;
    10     int len = s.length();
    11     int Max = -1,ans = 0;
    12     bool prime  =  true;
    13     for(int i=0;i<len&&true;i++){
    14         if(s[i]=='0')
    15             v[++ans].push_back(i+1);
    16         else{
    17             if(ans == 0){
    18                 prime = false;
    19                 break;
    20             }
    21             v[ans--].push_back(i+1);
    22         }
    23         Max = max(Max,ans);
    24     }
    25     if(Max!=ans)
    26         prime = false;
    27     if(!prime){
    28         cout<<"-1"<<endl;
    29         return 0;
    30     }else{
    31         cout<<Max<<endl;
    32         for(int i=1;i<=Max;i++){
    33             cout<<v[i].size();
    34             for(int j=0;j<v[i].size();j++){
    35                 cout<<" "<<v[i][j];
    36             }
    37             cout<<endl;
    38         }
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    解决方案 git@github.com出现Permission denied (publickey)
    github设置添加SSH
    base64是啥原理
    PHP面试题:HTTP中POST、GET、PUT、DELETE方式的区别
    PHP中put和post区别
    常用的微信编辑器
    局域网内一台电脑的ip地址自己会变,怎样让它不变
    Trendalyzer is an information visualization software
    FineReport报表和水晶报表的比较
    x
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/8543637.html
Copyright © 2011-2022 走看看