F. Binary String Reconstruction
For some binary string ss (i.e. each character sisi is either '0' or '1'), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length 22 were written. For each pair (substring of length 22), the number of '1' (ones) in it was calculated.
You are given three numbers:
- n0n0 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 00;
- n1n1 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 11;
- n2n2 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 22.
For example, for the string s=s="1110011110", the following substrings would be written: "11", "11", "10", "00", "01", "11", "11", "11", "10". Thus, n0=1n0=1, n1=3n1=3, n2=5n2=5.
Your task is to restore any suitable binary string ss from the given values n0,n1,n2n0,n1,n2. It is guaranteed that at least one of the numbers n0,n1,n2n0,n1,n2 is greater than 00. Also, it is guaranteed that a solution exists.
The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases in the input. Then test cases follow.
Each test case consists of one line which contains three integers n0,n1,n2n0,n1,n2 (0≤n0,n1,n2≤1000≤n0,n1,n2≤100; n0+n1+n2>0n0+n1+n2>0). It is guaranteed that the answer for given n0,n1,n2n0,n1,n2 exists.
Print tt lines. Each of the lines should contain a binary string corresponding to a test case. If there are several possible solutions, print any of them.
7 1 3 5 1 1 1 3 9 3 0 1 0 3 1 2 0 0 3 2 0 0
1110011110 0011 0110001100101011 10 0000111 1111 000
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <queue> #include <map> #include <sstream> #include <cstdio> #include <cstring> #include <numeric> #include <cmath> #include <iomanip> #include <deque> #include <bitset> //#include <unordered_set> //#include <unordered_map> //#include <bits/stdc++.h> //#include <xfunctional> #define ll long long #define PII pair<int, int> #define rep(i,a,b) for(int i=a;i<=b;i++) #define dec(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define mk make_pair using namespace std; int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } }; const long long INF = 0x7f7f7f7f7f7f7f7f; const int inf = 0x3f3f3f3f; const double pi = 3.14159265358979; const int mod = 998244353; const int N = 2e5+5; //if(x<0 || x>=r || y<0 || y>=c) inline ll read() { ll x = 0; bool f = true; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? x : -x; } ll gcd(ll m, ll n) { return n == 0 ? m : gcd(n, m%n); } ll lcm(ll m, ll n) { return m*n / gcd(m, n); } int main() { int T; cin >> T; while (T--) { string s=""; int a, b, c; cin >> a >> b >> c; if (a > 0) { rep(i, 0, a) { s += '0'; } } if (c > 0) { rep(i, 0, c) { s += '1'; } } int fg; if (a==0 && c==0) { b++; fg = 1; } if(a>0 && c>0) b--,fg = 1; if (a == 0 && c > 0) fg = 1; if (a > 0 && c == 0) fg = 0; rep(i, 1, b) { if (fg) { s += '0'; fg = 0; } else { s += '1'; fg = 1; } } cout << s << endl; } return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· 语音处理 开源项目 EchoSharp
· 《HelloGitHub》第 106 期
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 使用 Dify + LLM 构建精确任务处理应用