Codeforces Round #644 (Div. 3) G.A/B Matrix
Codeforces Round #644 (Div. 3) G.A/B Matrix
题目链接
You are given four positive integers n, m, a, b (1≤b≤n≤50; 1≤a≤m≤50). Find any such rectangular matrix of size n×m that satisfies all of the following conditions:
- each row of the matrix contains exactly a ones;
- each column of the matrix contains exactly b ones;
- all other elements are zeros.
If the desired matrix does not exist, indicate this.
For example, for n=3, m=6, a=2, b=1, there exists a matrix satisfying the conditions above:
[010001100100001010]\left[ \begin{matrix} 0 &1&0&0&0&1\\ 1 &0&0&1&0&0\\ 0 &0&1&0&1&0\\ \end{matrix} \right] ⎣⎡010100001010001100⎦⎤
Input
The first line contains an integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.
Each test case is described by four positive integers n, m, a, b (1≤b≤n≤50; 1≤a≤m≤50), where n and m are the sizes of the matrix, and a and b are the number of ones for rows and columns, respectively.
Output
For each test case print:
- “YES” (without quotes) and the required matrix (if there are several answers, print any) if it exists, or
- “NO” (without quotes) if it does not exist.
To print the matrix n×m, print n rows, each of which consists of m numbers 0 or 1 describing a row of the matrix. Numbers must be printed without spaces.
Example
input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
简单构造~
首先判断 NONONO 的情况,a∗n!=b∗ma*n!=b*ma∗n!=b∗m 即可
下面开始构造矩阵,我们按行来,一行连续 aaa 个 111,然后每行都错开 aaa 个即可,AC代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,t,a,b,cnt=0,g[55][55];
main(){cin>>t;while(t--){memset(g,0,sizeof(g));cin>>n>>m>>a>>b;if(n*a!=m*b) {puts("NO");continue;}for(int i=0;i<n;i++){for(int j=0;j<a;j++)g[i][cnt++]=1,cnt%=m;}puts("YES");for(int i=0;i<n;i++){for(int j=0;j<m;j++) cout<<g[i][j];puts("");}}
}
Codeforces Round #644 (Div. 3) G.A/B Matrix相关推荐
- Codeforces Round #644 (Div. 3) E.Polygon
Codeforces Round #644 (Div. 3) E.Polygon 题目链接 Polygon is not only the best platform for developing p ...
- Codeforces Round #644 (Div. 3) D.Buying Shovels
Codeforces Round #644 (Div. 3) D.Buying Shovels 题目链接 Polycarp wants to buy exactly n shovels. The sh ...
- Codeforces Round #644 (Div. 3) F.Spy-string
Codeforces Round #644 (Div. 3) F.Spy-string 题目链接 You are given n strings a1,a2,-,an: all of them hav ...
- Codeforces Round #731 (Div. 3) G. How Many Paths? dfs + 拓扑 + 思维
传送门 题意: 给你一张nnn个点mmm条边的图,让你对每个点确定一个编号,规则如下: (1)(1)(1) 对于不能到的点编号为000. (2)(2)(2) 对于只有一条路径能到这个点的点编号为111 ...
- Codeforces Round #592 (Div. 2) G. Running in Pairs 构造(水)
传送门 文章目录 题意: 思路: 题意: 思路: 史上最水GGG题,没有之一. 考虑最小的情况如何构造,显然就是让a,ba,ba,b都1−n1-n1−n依次排列即可,这样的最小值为n∗(n+1)2\f ...
- Codeforces Round #725 (Div. 3) G. Gift Set 二分
传送门 文章目录 题意: 思路: 题意: 有两种物品分别有x,yx,yx,y个,每次可以从一个拿出aaa个,另一个拿出bbb个分成一组,问最多能分成多少组. 思路: 这个题有一个显然的单调性,所以二分 ...
- Codeforces Round #644(Div. 3) A-H
A - Minimal Square 题意 给两个完全一样的矩形(平行且不重叠) 求能覆盖两个矩形的最小正方形的面积 思路 只有两种摆放方式 将两个矩形上下并列或者左右并列 得到的新图形 长或者宽是之 ...
- Codeforces Round #827 (Div. 4) G. Orray
Problem - G - Codeforces 题意: 给定一个数列,让你重新排列这个数列,使得其前缀或最大 思路: 贪心策略就是找一个与pre或起来最大的值 重点是怎么写呢 感觉div4的题思路都 ...
- Codeforces Round #827 (Div. 4) G. Orray 解题报告
原题链接: Problem - G - Codeforces 题目描述: You are given an array aa consisting of nn nonnegative integers ...
最新文章
- Target host is not specified错误
- php开发的程序怎么用加密狗加密,C# 简单的程序绑定、加密(类似加密狗)
- setContentView( )方法
- gorm配置logger显示执行的sql
- php 网页截屏,怎么用PHP实现网页截图
- javaone_JavaOne和OOW 2015总结
- 更为简单的Ctrl+S自动刷新浏览器工具-LinrF5
- 移动站适配rel=alternate PC页和H5页适配标注
- MySQL | MySQL 数据库系统(四)- 数据库的备份与恢复
- 【转】几款移动跨平台App开发框架比较
- SpringMVC框架学习上篇
- 2021-10-24
- FMEA软件功能失效矩阵-交叉表 vs 树形矩阵
- 软件研发成本构成中的间接成本包括哪些?
- 洛谷T30768 动感超人520
- ap计算机知识点总结,AP统计学考试知识点汇总
- POI 处理word 文档中 文本框模板
- Modularity Based Community Detection with Deep Learning 阅读笔记
- 假证假章猖狂不止 公章伪造的沉疴爱签电子印章来治愈
- 深度学习框架智能时代的操作系统是什么?
热门文章
- Mathorcup数学建模竞赛第六届-【妈妈杯】B题:小区车位分布的优化设计与评价(附一等奖获奖论文、C++和matlab代码)
- java空间(Java堆空间)
- CMI的C语言实现方法,C语言——Cmidiv0.6自主和弦模块(测试版)
- 【论文笔记】基于点云柱面投影图的平面特征提取SLAM: Fast planar surface 3D SLAM using LIDAR 2017
- 21.Mysql数据库连接配置
- layui使用tips_layer 的提示层 tips的一般使用
- 索尼手机c6802的Android,索尼C6802 (Xperia UL)图文刷机教程,最新教程,简单明了
- 课堂练习 最大联通数组
- 理解SQL语句中 Exists()
- 【CV】第 1 章:人工神经网络基础