当前位置:网站首页>【AtCoder2387】+/- Rectangle
【AtCoder2387】+/- Rectangle
2022-06-11 07:37:00 【CaptainHarryChen】
The question
Construct a H × W H \times W H×W Matrix , Meet the following conditions
- All elements are integers , And belongs to [ − 1 0 9 , 1 0 9 ] [-10^9,10^9] [−109,109]
- The sum of all elements is positive
- For each h × w h \times w h×w The submatrix of , Its element sum is negative
Answer key
According to the example , The simplest idea is , Give satisfaction x m o d h = 0 x\ mod\ h=0 x mod h=0 And y m o d w = 0 y\ mod\ w=0 y mod w=0 The location of ( x , y ) (x,y) (x,y) Marked as − h w -hw −hw, All the rest are marked as 1 1 1
But there are counter examples
about 1 × 4 1\times 4 1×4 Matrix , 1 × 3 1\times 3 1×3 The submatrix of , Will be marked as
1 1 − 3 1 \begin{matrix} 1&1&-3&1 \end{matrix} 11−31 illegal , Can be marked as
2 2 − 5 2 \begin{matrix} 2&2&-5&2 \end{matrix} 22−52
Consider improving this method , Mark the normal position as k k k, x m o d h = 0 x\ mod\ h=0 x mod h=0 And y m o d w = 0 y\ mod\ w=0 y mod w=0 The location of ( x , y ) (x,y) (x,y) Marked as − k ( h w − 1 ) − 1 -k(hw-1)-1 −k(hw−1)−1, The sum of the submatrix is -1, If you can find k, Then there is a solution .
It can be proved that H m o d h = 0 H\ mod\ h=0 H mod h=0 And W m o d w = 0 W\ mod\ w=0 W mod w=0 when , unsolvable , At this time, you can H × W H\times W H×W The matrix of is exactly divided into integer numbers h × w h\times w h×w Submatrix , And each submatrix is negative , Then the entire primitive matrix cannot sum to a positive number .
If the above conditions are not met , Then the original matrix is cut into several submatrixes , There are still some leftovers , The value of each cell of leftover materials is k k k, Just make k k k Large enough , It must be able to offset a lot of the previous submatrix -1, therefore k The bigger the better .
When it is implemented, directly put k Card to the maximum .
Code
#include<cstdio> const int MAXN=505; int H,W,h,w; int arr[MAXN][MAXN]; int main() {
scanf("%d%d%d%d",&H,&W,&h,&w); if(h==1&&w==1) {
puts("No"); return 0; } long long sum=0; int k=999999999/(h*w-1); {
sum=0; for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) {
if(i%h==0&&j%w==0) arr[i][j]=-k*(h*w-1)-1; else arr[i][j]=k; sum+=arr[i][j]; } if(sum>0) {
puts("Yes"); for(int i=1;i<=H;i++) {
for(int j=1;j<=W;j++) printf("%d ",arr[i][j]); puts(""); } return 0; } } puts("No"); return 0; } 边栏推荐
- 20200810 T2 dispatch money
- 2022年熔化焊接与热切割考试练习题及答案
- 零基础自学SQL课程 | UNION 联合查询
- [STL source code analysis] summary notes (10): hashtable exploration
- [IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products
- 【AtCoder2376】Black and White Tree(博弈)
- C language to write a calculator calculation logic
- [atcoder1998] stamp Rally
- Euler's theorem and its extension (with proof)
- Implementation of stack (C language)
猜你喜欢
![Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]](/img/f0/9d4609a53f398636b8062c625f7d3c.jpg)
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]

Implementation of stack (C language)
![[atcoder1980] mystious light (mathematical simulation)](/img/c0/7de31b36e11ff71328d927c1d1c2d3.png)
[atcoder1980] mystious light (mathematical simulation)
![[Oracle database] mammy tutorial day03 Sorting Query](/img/ea/24c9495a2ef4f1786f7b7852bde321.png)
[Oracle database] mammy tutorial day03 Sorting Query

2022 melting welding and thermal cutting exam exercises and answers

3年功能测试拿8K,被新来的反超,其实你在假装努力

【AtCoder1980】Mysterious Light(数学模拟)

QT table display data

【IoT】项目管理:如何打造更好的跨职能团队?

C language function stack frame
随机推荐
20200803 T3 my friends [divide and conquer NTT optimization recursion]
【Oracle 数据库】奶妈式教程day04 排序查询
Find the longest common substring of N arrays (strings)
C language judging big end and small end [consortium or pointer] big end and small end conversion
C language function stack frame
Rabin Miller prime test
Seata的几种事务模式
10 advanced concepts that must be understood in learning SQL
MFC custom string linked list
[atcoder1998] stamp Rally
I/o multiplexing - select/poll/epoll
[IOT] project management: how to build a better cross functional team?
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]
Djikstra solves the shortest circuit with negative weight
JVM tuning
Import on CSDN MD file
Classes and objects (medium)
【AtCoder2387】+/- Rectangle
Classification of MNIST datasets with keras
【CodeForces908H】New Year and Boolean Bridges (FWT)