当前位置:网站首页>F.金玉其外矩阵(构造)
F.金玉其外矩阵(构造)
2022-08-04 14:09:00 【Harris-H】
F.金玉其外矩阵(构造)
不可能的情况就是矩阵长度分别整除,显然与2矛盾。
否则有解,考虑每个子矩阵右上角放负数,然后和为-1。最后肯定有多的行,直接正数即可。
选定的基数 m x mx mx要大于 n h × m w \dfrac{n}{h}\times \dfrac{m}{w} hn×wm,保证最终和为正数。
#include<bits/stdc++.h>
using namespace std;
long long n,m,h,w;
int main()
{
cin>>n>>m>>h>>w;
if(n%h==0&&m%w==0)
{
puts("N");
return 0;
}
int mx = (n/h)*(m/w)+1;
puts("Y");
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i%h==0&&j%w==0)
{
printf("%d ",-mx*w*h+(mx-1));
}
else printf("%d ",mx);
}
printf("\n");
}
}
边栏推荐
猜你喜欢
随机推荐
小 P 周刊 Vol.13
TS - type
1375. 二进制字符串前缀一致的次数-前序遍历法
从理论到实践:MySQL性能优化和高可用架构,一次讲清
Niuke.com Brush Question Record || Linked List
odoo13 note point
职场漫谈:为什么越是内卷的行业越有人争着抢着往里冲?好奇怪的说...
oracle+RAC+linux5.1所需要安装的包
2546 饭卡(01背包,挺好的)
Chinese valentine's day, of course, to learn SQL optimization better leave work early to find objects
"C pitfalls and pitfalls" reading summary
PAT甲级:1038 Recover the Smallest Number
橄榄枝大课堂APP正式启动上线
数据库的基本概念
Crawler - action chain, xpath, coding platform use
人像分割技术解析与应用
State security organs conduct criminal arrest and summons review on Yang Zhiyuan, a suspect suspected of endangering national security
企业应当实施的5个云安全管理策略
idea永久激活教程(新版)
【毕设选题推荐】机器人工程专业毕设选题推荐