日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Binary String Reconstruction CodeForces - 1352F(思维+构造)

發布時間:2023/12/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Binary String Reconstruction CodeForces - 1352F(思维+构造) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

For some binary string s (i.e. each character si is either ‘0’ or ‘1’), all pairs of consecutive (adjacent) characters were written. In other words, all substrings of length 2 were written. For each pair (substring of length 2), the number of ‘1’ (ones) in it was calculated.

You are given three numbers:

n0 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 0;
n1 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 1;
n2 — the number of such pairs of consecutive characters (substrings) where the number of ones equals 2.
For example, for the string s=“1110011110”, the following substrings would be written: “11”, “11”, “10”, “00”, “01”, “11”, “11”, “11”, “10”. Thus, n0=1, n1=3, n2=5.

Your task is to restore any suitable binary string s from the given values n0,n1,n2. It is guaranteed that at least one of the numbers n0,n1,n2 is greater than 0. Also, it is guaranteed that a solution exists.

Input
The first line contains an integer t (1≤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,n2 (0≤n0,n1,n2≤100; n0+n1+n2>0). It is guaranteed that the answer for given n0,n1,n2 exists.

Output
Print t 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.

Example
Input
7
1 3 5
1 1 1
3 9 3
0 1 0
3 1 2
0 0 3
2 0 0
Output
1110011110
0011
0110001100101011
10
0000111
1111
000
思路:0和2的情況我們可以直接構造出來,但是1的情況,就需要多考慮一下了。
①0和2都存在的情況。
②只有0存在的情況。
③只有2存在的情況。
④0和2都不存在的情況。
找規律分下奇偶,就可以了。具體看代碼:

#include<bits/stdc++.h> #define ll long long using namespace std;int n0,n1,n2;int main() {int t;scanf("%d",&t);while(t--){scanf("%d%d%d",&n0,&n1,&n2);string s0="",s1="",s2="";if(n0) s0+='0';if(n2) s2+='1';while(n0>0) s0+='0',n0--;while(n2>0) s2+='1',n2--;if(s0.size()&&s2.size()){if(n1&1) for(int i=1;i<=n1/2;i++) s1+="10";else{for(int i=1;i<n1/2;i++) s1+="10";s2+='0';}}else if(s0.size()){for(int i=1;i<=n1/2;i++) s1+="10";if(n1&1) s0='1'+s0;}else if(s2.size()){for(int i=1;i<=n1/2;i++) s1+="10";if(n1&1) s2=s2+'0';}else{for(int i=1;i<=(n1+1)/2;i++) s1+="10";if(n1%2==0) s1+='1';}cout<<s0<<s1<<s2<<endl;}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Binary String Reconstruction CodeForces - 1352F(思维+构造)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。