CodeForces - 950C Zebras 模拟变脑洞的天秀代码
题意:给你一个01串,问其是否能拆成若干形如0101010的子串,若能,输出所有子串的0,1 的位置。
题解:一开是暴力,然后瞎找规律,
最后找到一种神奇的线性构造法:扫一遍字符串,若为0就一直竖着往下写0,碰到1就回头往上写,再碰到0 就回头往下写······判断无法构造的依据:如果写1写得超过了上界就跳出,如果最后写的0不在最下面也跳出//codeforces上看到的一段代码秀的脑壳疼
坑:之前随便找规律,写了个巨丑的代码,逻辑混乱,直接wa掉。
无脑写的直接T了
ac
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include<string>
#include<vector>
#include<queue>
#define pb push_back
#define _for(i, a, b) for (int i = (a); i<(b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i
using namespace std;
const int maxn = + ;
string s; vector<int>ans[maxn];
int main() {
cin >> s; int j = , x=;
_for(i, , s.size()) {
if (s[i] - ) { if (!j)return cout << "-1", ; ans[--j].pb(i + ); }else { ans[j++].pb(i + ); }x = max(x, j);}
if (x != j)return cout << "-1", ;
cout <<x << endl;_for(i,,x){cout << ans[i].size() ; _for(j,,ans[i].size())cout << ' ' << ans[i][j]; cout << endl;} }
附上天秀代码:
#include <bits/stdc++.h>
#define pb push_back
#define fi(x,n) for(int i=0;i<n;i++)
#define fj(x,n) for(int j=0;j<n;j++)
using namespace std;
vector <int> a[];
string s; int z, o, j, x, t, c;
int main() {
cin >> s; fi(, s.size()) { s[i] -= ; if (s[i]) { if (!j)return cout << "-1", ; a[--j].pb(i + ); } else a[j++].pb(i + ); x = max(x, j); }
if (x != j)return cout << "-1", ;
cout << x << endl; fi(, x) { cout << a[i].size() << " "; fj(, a[i].size())cout << a[i][j] << " "; cout << endl; };
}
CodeForces - 950C Zebras 模拟变脑洞的天秀代码的更多相关文章
- Codeforces 950C Zebras ( 贪心 && 模拟 )
题意 : 给出一个 01 串,要求你将其分隔出若干个子序列 ( 每个数字只能属于某一个子序列 ) ,子序列必须满足由 0 开头和结尾,且中间需 01 交替构成.若无法做到,则输出 -1. 分析 : ...
- Divisibility by 25 CodeForces - 988E(模拟)
遇见模拟题 有两种做法 例如这题: 1.直接去算次数(统计哪个数在第几位,然后去运算) 2.模拟操作 贴一个别人的代码...https://blog.csdn.net/weixin_39453270/ ...
- 音频算法之小黄人变声 附完整C代码
前面提及到<大话音频变声原理 附简单示例代码>与<声音变调算法PitchShift(模拟汤姆猫) 附完整C++算法实现代码> 都稍微讲过变声的原理和具体实现. 大家都知道,算法 ...
- spring-mvc实现模拟数据到网页展示过程代码
spring-mvc实现模拟数据到网页展示过程代码 先看看我们的3种模拟数据到网页展示的思路图: 1.当mybatis的环境配置完成.一个动态Web项目建立好.开始导入jar包. -spring的ao ...
- Zebras CodeForces - 950C(思维)
借鉴自: https://www.cnblogs.com/SuuT/p/8619227.html https://blog.csdn.net/my_sunshine26/article/details ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
随机推荐
- openssl & openssh
什么是OpenSSL众多的密码算法.公钥基础设施标准以及SSL协议,或许这些有趣的功能会让你产生实现所有这些算法和标准的想法.果真如此,在对你表示敬佩的同时,还是忍不住提醒你:这是一个令人望而生畏的过 ...
- iOS开发--UIButton 设置圆角 边框颜色 点击回调方法
UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom]; signBtn.frame = CGRectMake(, , , ) ...
- 全屏加载loading显示的解决方法
step1:可以在网页里加一个div用来现实loading. <div id="loading"> <!--这里放你的loading时显示的动画或者文字--> ...
- 《C++标准程序库》笔记之四
本篇博客笔记顺序大体按照<C++标准程序库(第1版)>各章节顺序编排. ---------------------------------------------------------- ...
- PyQt4简单的窗口程序
下面的程序显示了一个简单的小窗口. #!/usr/bin/python # -*- coding:utf-8 -*- import sys from PyQt4 import QtGui app = ...
- 执行Batch批处理遇到的问题
1.务必关掉自动提交 增强执行效率 conn.setAutoCommit(false); 2.executeBatch失效问题 <1>务必将语句pstmt = conn.prepareSt ...
- c# MVC Take的使用
Take的使用 myPicture = dbContext.MyPictures.Where(u => u.Width == request.Width && u.Height ...
- chattr lsattr
chattr命令的用法:chattr [ -RVf ] [ -v version ] [ mode ] files…最关键的是在[mode]部分,[mode]部分是由+-=和[ASacDdIijsTt ...
- document.visibilityState 监听浏览器最小化
document.hidden:表示页面是否隐藏的布尔值.页面隐藏包括 页面在后台标签页中 或者 浏览器最小化 (注意,页面被其他软件遮盖并不算隐藏,比如打开的 sublime 遮住了浏览器). do ...
- Visual Studio for Mac离线安装教程
Visual Studio for Mac离线安装教程 可以在线安装,也可以离线安装(本次安装博主使用离线,在线安装失败了) 据说翻个墙就可以,有条件的就翻吧 没条件的我于是选择离线安装………… 离线 ...