Zebras CodeForces - 950C(思维)
借鉴自:
https://www.cnblogs.com/SuuT/p/8619227.html
https://blog.csdn.net/my_sunshine26/article/details/79502152
题意:
给定一个01字符串,需要你把它分为k个子序列,其中k可以为任意正整数。
对子序列的要求为
以0开始,以0结束
0,1相间
输出满足条件的一种结果即可。 输出的结果还要从低到高的顺序
扫一遍字符串,若为0就一直竖着往下写0,碰到1就回头往上写,再碰到0 就回头往下写······
判断无法构造的依据:如果写1写得超过了上界就跳出,如果最后写的0不在最下面也跳出
#include <cstdio> #include <iostream> #include <cmath> #include <queue> #include <cstring> #include <algorithm> using namespace std; #define mst(a,b) memset((a),(b),sizeof(a)) #define rush() int T;scanf("%d",&T);while(T--)typedef long long ll; const int maxn = 200005; const ll mod = 1e9+7; const int INF = 1e9; const double eps = 1e-9;int n,m; char s[maxn]; vector<int>vec[maxn];int main() {scanf("%s",s+1);int len=strlen(s+1);int Max=0;int zero=0;for(int i=1;i<=len;i++){if(s[i]=='0') vec[++zero].push_back(i); //zero前面都是以0结尾的else{if(zero==0) return puts("-1"),0; //确保每个子序列以0开始vec[zero--].push_back(i); //这个位置放了1之后下一次又可以放0了 }Max=max(Max,zero); //Max为当前已经用了几个容器,即分成了几个子序列 }if(Max!=zero) return puts("-1"),0; //确保每个子序列以0结尾printf("%d\n",Max);for(int i=1;i<=Max;i++){printf("%d",vec[i].size());for(int j=0;j<vec[i].size();j++){printf(" %d",vec[i][j]);}puts("");} }
转载于:https://www.cnblogs.com/WTSRUVF/p/9404646.html
Zebras CodeForces - 950C(思维)相关推荐
- CodeForces 798D 思维,贪心
CodeForces 798D 题意:长度为 n的两个数组 a[]和 b[],要找出 k ( k<=n/2+1 )个下标,使得在两个数组中这 k个数的和乘上 2 要大于所有数的和. tags: ...
- codeforces - 1315C - 思维题
原题链接:https://codeforces.com/problemset/problem/1315/C 翻译: 这是一个猜谜游戏,你需要猜中一个序列,谜题是一个序列,我们设为b,长度为n.你需要根 ...
- Balanced Substring CodeForces - 873B (思维+前缀和)
Balanced Substring CodeForces - 873B You are given a string s consisting only of characters 0 and 1. ...
- Codeforces 1093C (思维+贪心)
题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤⋯≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+ ...
- B. Bogosort codeforces(思维)
outputstandard output You are given an array a1,a2,-,an. Array is good if for each pair of indexes i ...
- Count Subrectangles CodeForces - 1323B(思维)
You are given an array a of length n and array b of length m both consisting of only integers 0 and ...
- Dead Pixel CodeForces - 1315A(思维)
Screen resolution of Polycarp's monitor is a×b pixels. Unfortunately, there is one dead pixel at his ...
- Three Integers CodeForces - 1311D(思维+暴力)
You are given three integers a≤b≤c. In one move, you can add +1 or −1 to any of these integers (i.e. ...
- Interesting Array CodeForces - 483D(思维+线段树)
We'll call an array of n non-negative integers a[1], a[2], -, a[n] interesting, if it meets m constr ...
- Hills And Valleys CodeForces - 1467B 思维
给你一个数组,最多可以修改一个数,问最少的山峰和山谷数量之和. 小菜鸡做了一年. 一上来想猜个结论,让每个数等于其相邻的两个数,看了题解之后也证明的正确性,当时直接写就没后面这么多事了. 但是命运让我 ...
最新文章
- ApacheBench(ab)使用详解
- Python 学习笔记 - socket(基本原理和流程)
- Java小结(一)——打印等腰三角形
- lua检测表中是否有某个值,如何检查表是否包含Lua中的元素?
- 树莓派3B+运行arm_computer_library
- java 复杂 sql_复杂的SQL条件
- Java加密与解密的艺术~SHA算法实现
- java对mysql查询_如何利用java对mysql数据库进行增删改查
- Dev的多语言简单实现
- HackerOne 公布十大漏洞奖励计划“豪门”
- 深入理解Python对象(源码深度解析)
- C语言测试:想成为嵌入式程序员应知道的0x10个基本问题
- AIDL简单使用(通过它跨应用传递对象(数据))
- Ubuntu16.04 安装Tensorflow-CPU
- Python—2022 |已有文章汇总 | 持续更新,直接看这篇就够了
- 整型数组——首尾相连
- SaaS运营实战:B端与C端的区别在哪?
- 21天学习之二(Android 10.0 SystemUI默认去掉底部导航栏的三种方法)
- OpenDaylight是什么?
- Codeup墓地-1123