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 ...
随机推荐
- (转载)Unity 优化总结
Unity 优化总结 2017-03-10 | 发布 大海明月 zengfeng75@qq.com | 分类 Unity | 标签 Unity 优化 相关文档 UGUI 降低填充率技巧两则 U ...
- session是什么时候创建的
总结:session不是一打开网站就会立刻建立.它的建立需要基于下面两个条件中的任意一个: 1:在servlet中手动调用 HttpSession session = request.getSessi ...
- javaScript中的严格模式 (译)
“use strict”状态指示浏览器使用严格模式,是javaScript中一个相对少且安全的特征集. 特征列表(非完全列举) 不允许定义全局变量.(捕获没有用var声明的变量和变量名的拼写错误) 在 ...
- JS核心
JS核心 1.实例化对象 objectName = new objectType (param1 [,param2] ...[,paramN]) 参数 objectName 新对象实例的名称. ob ...
- liunx下忘记root密码的解决方法
1.在Liunx 刚开始重启时.我们这里按“e”键进入系统启动前的Grub配置.(注:一般要安两次e键)(如果你的系统引导程序是LILO,和Grub大体类似,请自行参照LILO给出的提示操作) 如图: ...
- LookAround开元之旅(持续更新中...)
应用介绍随便瞧瞧是一款为android用户量身定做的免费图文资讯软件集美食,文学,语录等频道于一体界面简洁,操作流畅,图文分享,个性收藏是广大卓粉的必备神器APK下载 -->https://ra ...
- 爬虫基本原理及requests,response详解
一.爬虫基本原理 1.爬虫是什么 #1.什么是互联网? 互联网是由网络设备(网线,路由器,交换机,防火墙等等)和一台台计算机连接而成,像一张网一样. #2.互联网建立的目的? 互联网的核心价值在于数据 ...
- ScriptManager对象的属性
--<本文属于摘抄> 属性 说明 EnablePageMethods 指定在ASPX页面上定义的公共静态方法是否可以从客户端脚本中作为Web服务方法调用 EnablePartialRend ...
- COGS 1427. zwei
★☆ 输入文件:zwei.in 输出文件:zwei.out 简单对比时间限制:1 s 内存限制:256 MB [样例输入] 5 5 1 2 3 4 5 1 1 3 1 3 5 0 ...
- SQL Server2005的数据还原与备份具体步骤
一:备份数据库步骤 1. 第一步:在开始—>程序(P)—>MicrosoftSQLserver2005—>SQLServerManagementStudio(如下图) 2. 第二步: ...