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

    A :

    题目:

    A. Vanya and Cards
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.

    Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?

    You can assume that initially Vanya had infinitely many cards with each integer number from  - x to x.

    Input

    The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.

    Output

    Print a single number — the answer to the problem.

    Sample test(s)
    input
    3 2
    -1 1 2
    output
    1
    input
    2 3
    -2 -2
    output
    2
    Note

    In the first sample, Vanya needs to find a single card with number -2.

    In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.

    大意:

    最少需要多少个绝对值小于 x(输入)  的数   
    使得总和(输入和需要计算的数的总和)为0

    水题一枚,直接求和 绝对值之后除以x即可  ,直接上代码:

    代码:

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     //freopen("aa.txt","r",stdin);
     9     int n,x,num,sum,ans=0;
    10     while(cin>>n>>x)
    11     {
    12         sum=0;
    13         for(int i=0;i<n;i++)
    14         {
    15             cin>>num;
    16             sum+=num;
    17         }
    18         if(sum<0)
    19         sum=-sum;
    20         if(sum%x==0)
    21         {
    22             ans=sum/x;
    23         }
    24         else
    25         ans=sum/x+1;
    26         cout<<ans<<endl;
    27     }
    28     return 0;
    29 }
    View Code

    B:

    题目:

    B. Sereja and Contests
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.

    Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.

    Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.

    Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.

    Input

    The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.

    Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1round). It is guaranteed that num1 - num2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.

    Output

    Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.

    Sample test(s)
    input
    3 2
    2 1
    2 2
    output
    0 0
    input
    9 3
    1 2 3
    2 8
    1 4 5
    output
    2 3
    input
    10 0
    output
    5 9
    Note

    In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1round.

    The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.

    大意:

    形象的形容一下:一些人和一些木头排成一个1-n的序列 max:总共多少人?  min:有多少孤独的人(左右为木头)两个相邻的人  额……说麻烦了,用图吧:(M代表木头,R代表人)MMRMM中min:1       MRRRRRRM中min:3        MRRR中min:2   MRMRR中min:2

    直接上代码了:

     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 #include<map>
     5 #include<math.h>
     6 #include<set>
     7 #include<algorithm>
     8 using namespace std;
     9 
    10 const int maxn=4005;
    11 
    12 int a[maxn];
    13 
    14 int main()
    15 {
    16     int x,k;
    17     int num,aa,bb;
    18     //freopen("aa.txt","r",stdin);
    19     while(cin>>x>>k)
    20     {
    21         memset(a,0,sizeof(a));
    22         while(k--)
    23         {
    24             cin>>num;
    25             if(num==1)
    26             {
    27                 cin>>aa>>bb;
    28                 a[aa]=1;
    29                 a[bb]=1;
    30             }
    31             else
    32             {
    33                 cin>>aa;
    34                 a[aa]=1;
    35             }
    36         }
    37         a[0]=1;
    38         a[x]=1;
    39         int minn=0;
    40         int maxx=0;
    41         int xx=0;
    42         for(int i=1;i<=x;i++)
    43         {
    44             if(a[i]==0)
    45             {
    46                 xx++;
    47                 maxx++;
    48             }
    49             else if(a[i]!=0)
    50             {
    51                 if(xx%2==0)
    52                 minn+=xx/2;
    53                 else
    54                 minn+=(xx/2+1);
    55                 xx=0;
    56             }
    57         }
    58         cout<<minn<<" "<<maxx<<endl;
    59     }
    60     return 0;
    61 }
    View Code

    C:

    题目:

    C. Team
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.

    For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that:

    • there wouldn't be a pair of any side-adjacent cards with zeroes in a row;
    • there wouldn't be a group of three consecutive cards containing numbers one.

    Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.

    Input

    The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.

    Output

    In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.

    Sample test(s)
    input
    1 2
    output
    101
    input
    4 8
    output
    110110110101
    input
    4 10
    output
    11011011011011
    input
    1 5
    output
    -1

     大意:

    输出一个m个0和n个1组成的序列,其中两个0不能连续,三个1不能连续

    思路:

    解方程,即 鸡兔同笼的变形:

    有  a个0    b个110   c个10  d个1  

      a指的是最开始0的个数  d代表最后1的个数
    a<=1   d<=2
    b c >=0
     1的个数等于m   0的个数等于n 
     然后列方程解出abcd
     
    这个题是鸡兔同笼那个题给我的思路。
     
    代码:
     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 #include<map>
     5 #include<math.h>
     6 #include<set>
     7 #include<algorithm>
     8 using namespace std;
     9 
    10 int main()
    11 {
    12     long long int n,m,i;
    13 
    14     //freopen("aa.txt","r",stdin);
    15     while(cin>>n>>m)
    16     {
    17         long long int x=0,y=0,z=0,q=0;
    18         int flag=0;
    19         for(q=0;q<=1;q++)
    20         {
    21             for(z=0;z<=2;z++)
    22             {
    23                 x=m-n+q-z;
    24                 y=n-q-x;
    25                 if(x>=0&&y>=0)
    26                 {
    27                     flag=1;
    28                     break;
    29                 }
    30             }
    31             if(flag==1)
    32             break;
    33         }
    34         if(flag==1){
    35         for(i=0;i<q;i++)
    36         cout<<"0";
    37         for(i=0;i<x;i++)
    38         cout<<"110";
    39         for(i=0;i<y;i++)
    40         cout<<"10";
    41         for(i=0;i<z;i++)
    42         cout<<"1";
    43         cout<<endl;
    44         }
    45         else
    46         cout<<"-1"<<endl;
    47     }
    48     return 0;
    49 }
    View Code

     

  • 相关阅读:
    校园路的伤感
    IBM决赛的相片
    IBM一面blue面筋(D组)
    解读校园路
    learn english
    DoNews.COM确实不错
    ARC使用
    Mac 终端 加tab键索引功能
    制作越狱ios设备ipa包
    objc>JS通信及JS>objc通信
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/3593103.html
Copyright © 2011-2022 走看看