A - Zebras
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.
Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.
Input
In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.
Output
If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≤ k ≤ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≤ li ≤ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.
Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.
Examples
0010100
3
3 1 3 4
3 2 5 6
1 7
111
-1 蛇皮走位 构造一个方阵,对行来说 0就前进,1就后退
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N = ;
// name*******************************
vector<int>vec[N];
char s[N];
// function****************************** //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
scanf("%s",s+);
int len=strlen(s+);
int r=,k=;
For(i,,len)
{
if(s[i]=='')
vec[++r].pb(i);
else
{
if(r<=)
{
cout<<-;
return ;
}
vec[r--].pb(i);
}
k=max(k,r);
}
if(k!=r)
{
cout<<-;
return ;
}
cout<<k<<endl;
For(i,,k)
{
cout<<vec[i].size()<<" ";
For(j,,vec[i].size()-)
{
cout<<vec[i][j]<<" ";
}
cout<<endl;
} return ;
}
A - Zebras的更多相关文章
- Codeforces Round #469 (Div. 2)C. Zebras(思维+模拟)
C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...
- Codeforces 950 C. Zebras
http://codeforces.com/contest/950/problem/C 题意: 给出一个01序列,问能否将这个序列分为若干个0开头0结尾的序列 输出方案 如果有解,几个1能在一个序列就 ...
- CodeForces - 950C Zebras 模拟变脑洞的天秀代码
题意:给你一个01串,问其是否能拆成若干形如0101010的子串,若能,输出所有子串的0,1 的位置. 题解:一开是暴力,然后瞎找规律, 最后找到一种神奇的线性构造法:扫一遍字符串,若为0就一直竖着往 ...
- Zebras CodeForces - 950C(思维)
借鉴自: https://www.cnblogs.com/SuuT/p/8619227.html https://blog.csdn.net/my_sunshine26/article/details ...
- codeforce469DIV2——C. Zebras
题意 0, 010, 01010 这一类的01交替且开头和结尾都为0的序列被称为zebra序列.给出一段01序列,尝试能否把他分为k个子序列使得每个子序列都是zebra序列. 分析 这个题应该算是水题 ...
- [CodeForces950C]Zebras
Description 题目地址: Codeforces 题意:给你一串只含01的字符串,判断能否将字符串分为k个子序列,使得子序列满足以下条件: 开头和结尾都是0 相邻的2个数是01或者10 如0, ...
- CF949A/950C Zebras
思路: 贪心乱搞. 实现: #include <bits/stdc++.h> using namespace std; vector<vector<int>> v; ...
- CF949A Zebras 构造
是一道不错的构造题. 我们观察,一个 111 的前后必须都有 000. 那么,我们开一个二维数组 (vector)(vector)(vector),这样每遇到一个 000 就将 000 加入到当前的 ...
- Codeforces 950C Zebras ( 贪心 && 模拟 )
题意 : 给出一个 01 串,要求你将其分隔出若干个子序列 ( 每个数字只能属于某一个子序列 ) ,子序列必须满足由 0 开头和结尾,且中间需 01 交替构成.若无法做到,则输出 -1. 分析 : ...
随机推荐
- nodejs 通过nginx后出现响应慢的解决方法
最近用了nodejs搭建服务器,然后用了nginx做了反向代理,项目开发需求,没办法.但是发现了经过代理之后发现网页请求变慢了,而且是不能忍的一分钟以上. 一开始,怀疑是在nodejs那边的问题,结果 ...
- js-ES6学习笔记-字符串的扩展
1.codePointAt方法是测试一个字符由两个字节还是由四个字节组成的最简单方法.codePointAt方法会正确返回32位的UTF-16字符的码点. function is32Bit(c) { ...
- element-ui Pagination组件源码分析整理笔记(七)
element-ui源码的版本是2.4.9 pagination.js import Pager from './pager.vue'; import ElSelect from 'element-u ...
- event.stopPropagation与event.preventDefault的区别
1.event.stopPropagation 停止事件的传播,阻止它被分配到其它Dom节点.但是不能阻止同一Dom节点上的其它事件句柄被调用. 注:不同Dom节点的事件必须是一致的.如父节点和子节点 ...
- sql 获取批处理信息的脚本(优化器在处理批处理时所发生的优化器事件)
--获取批处理信息的脚本(优化器在处理批处理时所发生的优化器事件) SET NOCOUNT ON; DBCC FREEPROCCACHE; --清空过程缓存 GO --使用tempdb..Optsta ...
- OSGI企业应用开发(一)OSGI简介
一.OSGI简介 OSGI全称为Open Service Gateway Initiative(开放服务网关规范),有两个层面的含义,一方面它指OSGi Alliance组织:另一方面指该组织制定的一 ...
- Vue + Spring Boot从零开始搭建个人网站(一) 之 项目前端Vue.js环境搭建
前言: 最近在考虑搭建个人网站,想了想决定采用前后端分离模式 前端使用Vue,负责接收数据 后端使用Spring Boot,负责提供前端需要的API 就这样开启了我边学习边实践之旅 Vue环境搭建步骤 ...
- openCV 扩图
1.扩图 import cv2 import numpy as np img=cv2.imread('Test2.jpg',1) width=img.shape[0] height=img.shape ...
- JavaScript动画:offset和匀速动画详解(含轮播图的实现)
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. offset简介 我们知道,三大家族包括:offset/scroll/c ...
- JS中的“==”符号及布尔值转换规则
what are the rules for how == converts types? 关于"=="的比较规则: 1. Comparing numbers and string ...