Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题
题目链接:http://codeforces.com/contest/721/problem/A
1 second
256 megabytes
standard input
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.
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).
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.
3
BBW
1
2
5
BWBWB
3
1 1 1
4
WWWW
0
4
BBBB
1
4
13
WBBBBWWBWBBBW
3
4 1 3
The last sample case correspond to the picture in the statement.
题解:
虽然是一道很基础的题目,但是却清晰了我对类似情况的写法, 值得记录一下。
关键代码:
if(a[i]=='B')
{
if(i==0 || a[i-1]=='W') k++;
s[k]++;
}
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 100+10; int n;
char a[maxn];
int k, s[maxn]; void init()
{
scanf("%d",&n);
scanf("%s",a);
ms(s,0);
k = 0;
} void solve()
{
int cnt = 1;
for(int i = 0; i<n; i++)
{
if(a[i]=='B')
{
if(i==0 || a[i-1]=='W') k++;
s[k]++;
}
} printf("%d\n",k);
for(int i = 1; i<=k; i++)
printf("%d ",s[i]);
putchar('\n');
} int main()
{
// int T;
// scanf("%d",&T);
// while(T--)
{
init();
solve();
}
return 0;
}
Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题的更多相关文章
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...
- 拓扑序+dp Codeforces Round #374 (Div. 2) C
http://codeforces.com/contest/721/problem/C 题目大意:给你有向路,每条路都有一个权值t,你从1走到n,最多花费不能超过T,问在T时间内最多能访问多少城市? ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...
- Codeforces Round #374 (Div. 2) C. Journey DP
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to o ...
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array —— 贪心
题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds ...
- Codeforces Round #374 (Div. 2) C. Journey —— DP
题目链接:http://codeforces.com/contest/721/problem/C C. Journey time limit per test 3 seconds memory lim ...
- Codeforces Round #374 (Div. 2) B. Passwords —— 基础题
题目链接:http://codeforces.com/contest/721/problem/B B. Passwords time limit per test 2 seconds memory l ...
随机推荐
- SSL剥离工具sslstrip
SSL剥离工具sslstrip 在日常上网过程中,用户只是在地址栏中输入网站域名,而不添加协议类型,如HTTP和HTTPS.这时,浏览器会默认在域名之前添加http://,然后请求网站.如果网站采 ...
- OAuth 2.0 in Web API #Reprinted
http://www.codebetter.com/howarddierking/2011/10/11/oauth-2-0-in-web-api/
- Laravel composer自定义命令空间,方便引用第三方库
第一步:自定义目录 在app文件夹下新建Library目录,做为第三方库的目录 第二步: 修改composer.json文件 autoload节点下的psr-4自定义命名空间 规则: key: 命名空 ...
- ArcGIS for Android地图控件的5大常见操作转
http://blog.csdn.net/arcgis_mobile/article/details/7801467 GIS的开发中,什么时候都少不了地图操作.ArcGIS for Android中, ...
- 记Weblogic采用RAC方式链接数据库遇到的问题
前几天,去客户现场部署系统,WEBLOGIC连接数据库使用RAC方式连接,好几个人弄了一下午愣是没搞定,总是报SID错误 开始一致认为是防火墙的原因,后来SSH登陆应用服务器后,再TELNET数据 ...
- 机器学习(十三)——机器学习中的矩阵方法(3)病态矩阵、协同过滤的ALS算法(1)
http://antkillerfarm.github.io/ 向量的范数(续) 范数可用符号∥x∥λ表示. 经常使用的有: ∥x∥1=|x1|+⋯+|xn| ∥x∥2=x21+⋯+x2n−−−−−− ...
- 判断浏览器是否支持flash
虽然flash已经过时了,如腾讯视频一样,有很多网站还来不及或者根本就改不了原来的架构,所以我们需要判断flash视频(默认chrome和Firefox)等浏览器会自动阻止flash加载 , 这与Sa ...
- JAVA Timer定时器使用方法
JAVA Timer 定时器测试 MyTask.java:package com.timer; import java.text.SimpleDateFormat;import java.util. ...
- vue2.0 + vux 项目搭建
1.快速搭建项目模板 因为项目使用vux,所以推荐使用vux官网的airyland/vux2 模板,vue-cli工具是vue项目的搭建脚手架 默认为 webpack2 模板,如果你需要使用webpa ...
- java要在命令行执行eclipse的项目的方法
在命令行运行eclipse的项目时须要把该项目生成一个能够运行的jar包,才干够在命令行下运行:分为两种情况,一种是项目中没有调用第三方的jar包,这样的比較简单.网上的资源也非常多,本文主要讲述第二 ...