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

    A. Holiday Of Equality
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.

    Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).

    You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.

    Input

    The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom.

    The second line contains n integers a1, a2, ..., an, where ai (0 ≤ ai ≤ 106) — the welfare of the i-th citizen.

    Output

    In the only line print the integer S — the minimum number of burles which are had to spend.

    Examples
    Input
    5
    0 1 2 3 4
    Output
    10
    Input
    5
    1 1 0 1 1
    Output
    1
    Input
    3
    1 3 1
    Output
    4
    Input
    1
    12
    Output
    0
    Note

    In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.

    In the second example it is enough to give one burle to the third citizen.

    In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3.

    In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.

    找到最大的数,把其他的数都加上一个数使所有的数都一样大。

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 using namespace std;
     6 #define N 105
     7 #define ll long long int
     8 int k[N];
     9 int main(){
    10   int n;
    11   cin>>n;
    12   int cnt=0;
    13   for(int i=0;i<n;i++){
    14     cin>>k[i];
    15     cnt=max(cnt,k[i]);
    16   }
    17   ll ans=0;
    18   for(int i=0;i<n;i++){
    19     ans+=cnt-k[i];
    20   }
    21   cout<<ans<<endl;
    22   return 0;
    23 }

     

    B. Blown Garland
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.

    Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.

    It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.

    Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

    Input

    The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:

    • 'R' — the light bulb is red,
    • 'B' — the light bulb is blue,
    • 'Y' — the light bulb is yellow,
    • 'G' — the light bulb is green,
    • '!' — the light bulb is dead.

    The string s can not contain other symbols except those five which were described.

    It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.

    It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

    Output

    In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

    Examples
    Input
    RYBGRYBGR
    Output
    0 0 0 0
    Input
    !RGYB
    Output
    0 1 0 0
    Input
    !!!!YGRB
    Output
    1 1 1 1
    Input
    !GB!RG!Y!
    Output
    2 1 1 0
    Note

    In the first example there are no dead light bulbs.

    In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.

    循环找规律。

    水题。

    #include <bits/stdc++.h>
    
    using namespace std;
    string s;
    int r,y,g,b;
    int main(){
        cin>>s;
        int len=s.length();
        for(int i=0;i<4&&i<len;i++){
          int cnt=0;
          char st;
          for(int j=i;j<len;j+=4){
            if(s[j]=='!')
              cnt++;
            else
              st=s[j];
          }
          if(st=='R')
            r=cnt;
          else if(st=='Y')
            y=cnt;
          else if(st=='G')
            g=cnt;
          else
            b=cnt;
        }
        cout<<r<<" "<<b<<" "<<y<<" "<<g<<endl;
      return 0;
    }
    C. Unfair Poll
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

    Seating in the class looks like a rectangle, where n rows with m pupils in each.

    The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

    The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.

    During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

    1. the maximum number of questions a particular pupil is asked,
    2. the minimum number of questions a particular pupil is asked,
    3. how many times the teacher asked Sergei.

    If there is only one row in the class, then the teacher always asks children from this row.

    Input

    The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

    Output

    Print three integers:

    1. the maximum number of questions a particular pupil is asked,
    2. the minimum number of questions a particular pupil is asked,
    3. how many times the teacher asked Sergei.
    Examples
    Input
    1 3 8 1 1
    Output
    3 2 3
    Input
    4 2 9 4 2
    Output
    2 1 1
    Input
    5 5 25 4 3
    Output
    1 1 1
    Input
    100 100 1000000000000000000 100 100
    Output
    101010101010101 50505050505051 50505050505051
    Note

    The order of asking pupils in the first test:

    1. the pupil from the first row who seats at the first table, it means it is Sergei;
    2. the pupil from the first row who seats at the second table;
    3. the pupil from the first row who seats at the third table;
    4. the pupil from the first row who seats at the first table, it means it is Sergei;
    5. the pupil from the first row who seats at the second table;
    6. the pupil from the first row who seats at the third table;
    7. the pupil from the first row who seats at the first table, it means it is Sergei;
    8. the pupil from the first row who seats at the second table;

    The order of asking pupils in the second test:

    1. the pupil from the first row who seats at the first table;
    2. the pupil from the first row who seats at the second table;
    3. the pupil from the second row who seats at the first table;
    4. the pupil from the second row who seats at the second table;
    5. the pupil from the third row who seats at the first table;
    6. the pupil from the third row who seats at the second table;
    7. the pupil from the fourth row who seats at the first table;
    8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
    9. the pupil from the third row who seats at the first table;

     模拟进行,不出错的话就可以过。

    注意数据挺大的,long long int

    题意:有n行m列学生,有一位老师在课上会问k个问题,在行上,是按照1,2。。。。n-1,n,n-1.。。。1这样的顺序提问,求学生当中回答问题个数最多和最少的个数,以及在第x行第y位的同学回答的问题数。


    解题思路:不难发现,当n>1时,1,2,……,n-1,n,n-1,……3,2为一个循环节,即有2*n-2行,其中每个循环节第1行以及第n行都只回答一次,其他都回答了两次,然后直接用二维数组进行模拟即可。注意细节的地方。

    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    ll kp[105][105];
    #define inf 1e18
    int main(){
      ll n,m,x,y;
      ll k,ma=0,mn=inf;
      ios::sync_with_stdio(0);
      cin.tie(0);
      cin>>n>>m>>k>>x>>y;
      if(n==1){
        if(k%m==0)
          cout<<k/m<<" "<<k/m<<" "<<k/m<<endl;
        else{
          cout<<k/m+1<<" "<<k/m<<" "<<k/m+(k%m<y?0:1)<<endl;
        }
        return 0;
      }else{
        ll cnt=0,ans=0;
        cnt=k/(m*(n-1));
        ans=k%(m*(n-1));
        if(cnt%2==0){
          for(int i=1;i<=m;i++){
            kp[1][i]+=cnt/2;
            kp[n][i]+=cnt/2;
          }
          for(int i=1;i<n&&ans;i++){
            for(int j=1;j<=m&&ans;j++){
              kp[i][j]++;
              ans--;
            }
          }
        }else{
          for(int i=1;i<=m;i++){
            kp[1][i]+=cnt/2+1;
            kp[n][i]+=cnt/2;
          }
          for(int i=n;i>1&&ans;i--){
            for(int j=1;j<=m&&ans;j++){
              kp[i][j]++;
              ans--;
            }
          }
        }
        for(int i=2;i<n;i++){
          for(int j=1;j<=m;j++)
            kp[i][j]+=cnt;
        }
      }
      for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
          if(kp[i][j]>ma)
            ma=kp[i][j];
          if(kp[i][j]<mn)
            mn=kp[i][j];
        }
      }
      cout<<ma<<" "<<mn<<" "<<kp[x][y]<<endl;
      return 0;
    }
  • 相关阅读:
    北风设计模式课程---22、责任链模式
    bootstarp modal自己主动调整宽度的JS代码
    谷歌技术面试要点(Google面试)(14年5月20日交大专场)
    ASCII与Unicode编码消息写文件浅析
    程序编写中的细节问题
    Oracle使用并行建索引须要注意的问题
    PHP读取Excel里的文件
    Oracle db中 CONNECT role的含义
    集团信息化之路—电子採购软件与现有库存及財务软件数据对接的探讨
    NTP方式保证以时间戳同步可靠性
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7615237.html
Copyright © 2011-2022 走看看