版权声明:_ https://blog.csdn.net/lunch__/article/details/82912768
题意
- 给你一个 串,请你构造出一颗大小和 串长度相等的树,如果 串第 位为 代表这棵树断开一条边后可以形成大小为 的联通块,为 代表不会形成,如果无解输出 .
首先来看无解的情况
显然断开一条边后不可能存在大小为 的联通块,也一定会存在大小为 的联通块,所以 ,然后如果 也不会有解,这些情况判掉后就可以构造了
扫把图有一个很棒的性质,那就是把它分离出来除了大小为 ,就只有它子树大小的联通块了,那么每次从小到大构造扫把,遇到大的把原来的小的接在这上面,再把多出来的大小直接接在根上,然后就做完了
Codes
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define min(a, b) (a < b ? a : b)
#define max(a, b) (b < a ? a : b)
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef long double ldb;
typedef double db;
namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
#define putc(x) *nowps ++ = (x)
const uint Buffsize = 1 << 15, Output = 1 << 23;
static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
static char Out[Output], *nowps = Out;
inline void flush(){fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
template<class T>inline void read(T &_) {
_ = 0; static char __; T ___ = 1;
for(__ = getc(); !isdigit(__); __ = getc()) if(__ == '-') ___ = -1;
for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
_ *= ___;
}
template<class T>inline void write(T _, char __ = '\n') {
if(!_) putc('0');
if(_ < 0) putc('-'), _ = -_;
static uint sta[111], tp;
for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
for(; tp; putc(sta[tp --] ^ 48)); putc(__);
}
template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}
}
using namespace std;
using namespace IO;
const int N = 1e5 + 10;
char S[N]; int n;
int main() {
#ifdef ylsakioi
file("e");
#endif
scanf("%s", S + 1), n = strlen(S + 1);
if(S[1] == '0' || S[n] == '1') return puts("-1"), 0;
For(i, 1, n - 1) if(S[i] ^ S[n - i]) return puts("-1"), 0;
int now = 1;
For(i, 2, n) if(S[i] == '1') {
For(k, now, i - 1) cout << k << ' ' << i << endl; now = i;
}
For(i, now, n - 1) cout << now << ' ' << n << endl;
return flush(), 0;
}