The North American Invitational Programming Contest 2018 H. Recovery
Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4:
\displaystyle \begin{matrix} 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 1 & 1 & 0 \end{matrix}1000111111111110
We can compute even parity for each row, and each column. In this case, the row parities are [0, 1, 1, 0][0,1,1,0] and the column parities are [1, 0, 0, 1][1,0,0,1] (the parity is 11 if there is an odd number of 11s in the row or column, 00 if the number of 11s is even). Note that the top row is row 11, the bottom row is row nn, the leftmost column is column 11, and the rightmost column is column mm.
Suppose we lost the original matrix, and only have the row and column parities. Can we recover the original matrix? Unfortunately, we cannot uniquely recover the original matrix, but with some constraints, we can uniquely recover a matrix that fits the bill. Firstly, the recovered matrix must contain as many 11’s as possible. Secondly, of all possible recovered matrices with the most 11’s, use the one which has the smallest binary value when you start with row 11, concatenate row 22 to the end of row 11, then append row 33, row 44, and so on.
Input Format
Each input will consist of a single test case.
Note that your program may be run multiple times on different inputs.
Each test case will consist of exactly two lines.
The first line will contain a string R (1 \le |R| \le 50)R(1≤∣R∣≤50), consisting only of the characters 00 and 11. These are the row parities, in order.
The second line will contain a string C (1 \le |C| \le 50)C(1≤∣C∣≤50), consisting only of the characters 00 and 11. These are the column parities, in order.
Output Format
If it is possible to recover the original matrix with the given constraints, then output the matrix as |R|∣R∣ lines of exactly |C|∣C∣ characters, consisting only of 00’s and 11’s. If it is not possible to recover the original matrix, output -1−1.
样例输入1
0110
1001
样例输出1
1111
0111
1110
1111
样例输入2
0
1
样例输出2
-1
样例输入3
11
0110
样例输出3
1011
1101
题目来源
The North American Invitational Programming Contest 2018
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
using namespace std;
#define ll long long
#define N 60
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define gepp(i,a,b) for(int i=a;i>=b;i--)
#define gep1(i,a,b) for(ll i=a;i<=b;i++)
#define gepp1(i,a,b) for(ll i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof(a))
char s1[N],s2[N];
int a[N],b[N];
char s[N][N];
int main()
{
scanf("%s%s",s1,s2);
int l=strlen(s1);
int r=strlen(s2);
int x=l%,y=r%;
int cnt1=,cnt2=;
gep(i,,l-){
int ii=s1[i]-'';
if(ii%!=y){
a[cnt1++]=i;
}
}
gep(i,,r-){
int ii=s2[i]-'';
if(ii%!=x){
b[cnt2++]=i;
}
}
if((cnt1+cnt2)&){//必须为偶数
printf("-1\n");
return ;
}
while(cnt1<cnt2) a[cnt1++]=;
while(cnt2<cnt1) b[cnt2++]=;
sort(a,a+cnt1);sort(b,b+cnt2);//贪心
gep(i,,l-){
gep(j,,r-){
s[i][j]='';
}
}
gep(i,,cnt1-){
s[a[i]][b[i]]='';//这些点必须为0
}
gep(i,,l-){
printf("%s\n",s[i]);
}
return ;
}
The North American Invitational Programming Contest 2018 H. Recovery的更多相关文章
- The North American Invitational Programming Contest 2018 D. Missing Gnomes
A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by ...
- The North American Invitational Programming Contest 2018 E. Prefix Free Code
Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...
- North American Invitational Programming Contest 2018
A. Cut it Out! 枚举第一刀,那么之后每切一刀都会将原问题划分成两个子问题. 考虑DP,设$f[l][r]$表示$l$点顺时针一直到$r$点还未切割的最小代价,预处理出每条边的代价转移即可 ...
- The North American Invitational Programming Contest 2017 题目
NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K A mysterious circular arrangement of black st ...
- North American Invitational Programming Contest (NAIPC) 2017
(待补) A. Pieces of Parentheses 将括号处理完成后排序,方式参加下面的博客.然后做一遍背包即可. 2018 Multi-University Training Contest ...
- North American Invitational Programming Contest (NAIPC) 2016
(待补) A. Fancy Antiques 爆搜. B. Alternative Bracket Notation C. Greetings! D. Programming Team 0/1分数规划 ...
- AtCoder SoundHound Inc. Programming Contest 2018 E + Graph (soundhound2018_summer_qual_e)
原文链接https://www.cnblogs.com/zhouzhendong/p/AtCoder-SoundHound-Inc-Programming-Contest-2018-E.html 题目 ...
- ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018
ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syr ...
- 2014 ACM-ICPC Beijing Invitational Programming Contest
点击打开链接 Happy Reversal Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld J ...
随机推荐
- 牛客练习赛42B(异或的性质)
传送门 b^ c >= b - c,这个结论应该记住,我还在这里证过…… 这个题就用到了这个结论,假如当前答案集合为S,和为a,异或和为b,当前答案为a+b了.这时又读入个c,该不该加进来?a ...
- python之错题巩固
.#把班级学⽣数学考试成绩录⼊到⼀个列表中: 并求平均值. 要求: 录⼊的时候 # 要带着⼈名录⼊, 例如: 张三_44 li = [] : str_input = input('请输入你的姓名和分数 ...
- 关于childNodes和children
1.childNodes. 会把注释.空文本.非空文本.标签都当做节点. 2.children: 在IE8以后的版本只会找到标签元素.不包括文本.空文本.注释.在IE8以前的版本会找到标签元素和注释, ...
- 利用HttpClient4访问网页
一.HttpClient介绍 虽然在 JDK 的 java.net 包中已经提供了访问 HTTP 协议的基本功能,但是它没有提供足够的灵活性和其他应用程序需要的功能.HttpClient 是 Apac ...
- 记录一下filter
filter是什么,如它的字面意思,就是拦截器.它可以在request到达相关资源之前,比如servlet之前先处理requeset,也可以拦截或处理从某个资源比如servlet发出的response ...
- python学习之图形界面编程:
一 tkinter:tkinter是python自带的支持tk的库,python代码调用tkinter->tk->操作系统提供的本地GUI(TKL语言开发))完成界面开发,不需要安装任何第 ...
- Oracle 修改密码(忘记登录密码,用户System)
1.修改计算机环境变量,把oracle服务端路径放在最前面 2.输入cmd 3.输入命令:sysplus /nolog SQL>conn sys/syspwd as sysdba SQL> ...
- GIT本地pull远程失败,本地tag与远程仓库不匹配问题
2019-05-15 问题现象: 1.GIT本地目录无法pull下远程仓库已新增的内容,一直提示Already up to date 2.git log 命令显示没有远端的tag版本 $git lo ...
- vue样式操作与事件绑定
Vue笔记 1 Vue实例 (VM) var vm = new Vue({ el:'#app', //挂载元素 //数据 data: { title:'值', ...
- html5.0学习记录(一)——可拖动视频播放器
最近自己在重新学习html5新特性,了解到有视频标签和拖动标签,于是自己用这两个特性写了一个小demo,主要功能就是可以通过拖动视频来直接播放.效果图如下: 页面使用了<video>标签和 ...