Codeforces Round #374 (Div. 2) A && B(两个水题)

来源:互联网 发布:手机vpn软件排名 编辑:程序博客网 时间:2024/05/29 17:39



A. One-dimensional Japanese Crossword
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).

Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword.

The example of encrypting of a single row of japanese crossword.

Help Adaltik find the numbers encrypting the row he drew.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).

Output

The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.

The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.

Examples
input
3BBW
output
12 
input
5BWBWB
output
31 1 1 
input
4WWWW
output
0
input
4BBBB
output
14 
input
13WBBBBWWBWBBBW
output
34 1 3 
Note

The last sample case correspond to the picture in the statement.


题意:给你一段字符串求有几段B,输出总共的个数,并且将每一段的个数输出。

思路:记录每一段B的个数,然后把它放入vector里,注意最后可能是B结尾,最后的时候判断下。

#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>using namespace std;char s[105];vector<int>res;int main(){    int n;    scanf("%d%s",&n,s);    int now=0;    for(int i=0;i<n;i++)    {        if(s[i]=='B')now++;        else        {            if(now)res.push_back(now);            now=0;        }    }    if(now)res.push_back(now);    printf("%d\n",(int)res.size());    for(int i=0;i<(int)res.size();i++)        printf("%d ",res[i]);    return 0;}

B. Passwords
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.

Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.

Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.

Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.

The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.

The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.

Output

Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.

Examples
input
5 2cbaabcbb1abCABCabc
output
1 15
input
4 10011221222
output
3 4
Note

Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.

注意是每隔k段+5s就行

#include<bits/stdc++.h>using namespace std;char str[105][105], ans[105];int main(void){    int n, k;    while(cin >> n >> k)    {        for(int i = 0; i < n; i++)            scanf(" %s", str[i]);        scanf(" %s", ans);        int len = strlen(ans);        int l = 0, d = 0, r;        for(int i = 0; i < n; i++)        {            if(strlen(str[i]) < len) l++;            if(strlen(str[i]) == len) d++;        }        int ansl = 0, ansr = 0;        ansl = l+(l/k)*5+1;        ansr = l+d+(l+d-1)/k*5;        printf("%d %d\n", ansl, ansr);    }    return 0;}




1 0
原创粉丝点击