Codeforces Round #375 (Div. 2)

(只A了4题,所以就写四题)

[Task]


A. The New Year: Meeting Friends

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?

It’s guaranteed that the optimal answer is always integer.

Input

The first line of the input contains three distinct integers x1, x2 and x3 (1 ≤ x1, x2, x3 ≤ 100) — the coordinates of the houses of the first, the second and the third friends respectively.

Output

Print one integer — the minimum total distance the friends need to travel in order to meet together.


B. Text Document Analysis

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.

In this problem you should implement the similar functionality.

You are given a string which only consists of:

uppercase and lowercase English letters,
underscore symbols (they are used as separators),
parentheses (both opening and closing).
It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching “opening-closing” pair, and such pairs can’t be nested.

For example, the following string is valid: “Hello_Vasya(and_Petya)__bye(and_OK)”.

Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: “Hello”, “Vasya”, “and”, “Petya”, “bye”, “and” and “OK”. Write a program that finds:

  • the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),
  • the number of words inside the parentheses (print 0, if there is no word inside the parentheses).

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols.

Output

Print two space-separated integers:

the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),
the number of words inside the parentheses (print 0, if there is no word inside the parentheses).


C. Polycarp at the Radio

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence a1, a2, …, an, where ai is a band, which performs the i-th song. Polycarp likes bands with the numbers from 1 to m, but he doesn’t really like others.

We define as bj the number of songs the group j is going to perform tomorrow. Polycarp wants to change the playlist in such a way that the minimum among the numbers b1, b2, …, bm will be as large as possible.

Find this maximum possible value of the minimum among the bj (1 ≤ j ≤ m), and the minimum number of changes in the playlist Polycarp needs to make to achieve it. One change in the playlist is a replacement of the performer of the i-th song with any other group.

Input

The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 2000).

The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 109), where ai is the performer of the i-th song.

Output

In the first line print two integers: the maximum possible value of the minimum among the bj (1 ≤ j ≤ m), where bj is the number of songs in the changed playlist performed by the j-th band, and the minimum number of changes in the playlist Polycarp needs to make.

In the second line print the changed playlist.

If there are multiple answers, print any of them.


D. Lakes in Berland

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean.

Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that it’s possible to get from any cell of the set to any other without leaving the set and moving only to cells adjacent by the side, none of them is located on the border of the rectangle, and it’s impossible to add one more water cell to the set such that it will be connected with any other cell.

You task is to fill up with the earth the minimum number of water cells so that there will be exactly k lakes in Berland. Note that the initial number of lakes on the map is not less than k.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map.

The next n lines contain m characters each — the description of the map. Each of the characters is either ‘.’ (it means that the corresponding cell is water) or ‘*’ (it means that the corresponding cell is land).

It is guaranteed that the map contain at least k lakes.

Output

In the first line print the minimum number of cells which should be transformed from water to land.

In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, print any of them.

It is guaranteed that the answer exists on the given data.



[Solution]


A:

最大值减最小值就好了.


B:

第二题还是很水,但是有很多坑.

int main() {
    int n;
    cin>>n;
    char s[500];
    scanf("%s",s);
    int len=0;
    int mxl=0,cnt=0;
    for (int i=0;i<n;++i) {
        if (s[i]=='_') mxl=max(mxl,len),len=0;
        else if (s[i]=='(') {
            mxl=max(mxl,len);
            len=0;
            i++;
            while (s[i]!=')') {
                if (s[i]=='_') {
                    if (len) cnt++;
                    len=0;
                } else len++;
                i++;
            }
            if (len) cnt++;
            len=0;
        } else len++;
    }
    mxl=max(mxl,len);
    cout<<mxl<<" "<<cnt<<endl;
    return 0;
}

C:

C题还是恶心人的题目,很容易写错.

每个数至少要达到的数目是可以直接算出来的.
所以我觉得应该先把需要的位置腾出来.
再把数都填进去,然后就好了.

#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int M=2005;   
int num[M];
int cnt[M]; 
int main() {
    int n,m;
    cin>>n>>m;
    int hav=n/m;
    int c1,c2;
    c1=c2=0;
    for (int i=1;i<=n;++i) {
        scanf("%d",&num[i]);
        if (num[i]<=m) cnt[num[i]]++;
        else c2++;
    }
    for (int i=1;i<=m;++i) {
        if (cnt[i]<hav) c1+=hav-cnt[i];
    }
    if (c1>c2) {
        int x=c1-c2;
        for (int i=1;i<=m;++i) {
            if (cnt[i]>hav) {
                int y=min(x,cnt[i]-hav);
                x-=y;
                for (int j=1;j<=n;++j) {
                    if (num[j]==i&&y) num[j]=0,y--;
                }
            }
        }
    }
    int use=0;
    for (int i=1;i<=m;++i) {
        if (cnt[i]<hav) {
            int x=hav-cnt[i];
            use+=x;
            for (int j=1;j<=n;++j) {
                if ((num[j]>m||num[j]==0)&&x) num[j]=i,x--;
            }
        }
    }
    cout<<hav<<" "<<use<<endl;
    printf("%d",num[1]);
    for (int i=2;i<=n;++i) printf(" %d",num[i]);
    puts("");
    return 0;
}

D:

D题又是巨水.
沿着边dfs把海都填上,
再算出每一片湖的大小


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值