当前位置:网站首页>Codeforces Round #684 (Div. 1)
Codeforces Round #684 (Div. 1)
2022-08-08 04:10:00 【秦小咩】
A1. Binary Table (Easy Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.
You are given a binary table of size n×mn×m. This table consists of symbols 00 and 11.
You can make such operation: select 33 different cells that belong to one 2×22×2 square and change the symbols in these cells (change 00 to 11 and 11 to 00).
Your task is to make all symbols in the table equal to 00. You are allowed to make at most 3nm3nm operations. You don't need to minimize the number of operations.
It can be proved that it is always possible.
Input
The first line contains a single integer tt (1≤t≤50001≤t≤5000) — the number of test cases. The next lines contain descriptions of test cases.
The first line of the description of each test case contains two integers nn, mm (2≤n,m≤1002≤n,m≤100).
Each of the next nn lines contains a binary string of length mm, describing the symbols of the next row of the table.
It is guaranteed that the sum of nmnm for all test cases does not exceed 2000020000.
Output
For each test case print the integer kk (0≤k≤3nm0≤k≤3nm) — the number of operations.
In the each of the next kk lines print 66 integers x1,y1,x2,y2,x3,y3x1,y1,x2,y2,x3,y3 (1≤x1,x2,x3≤n,1≤y1,y2,y3≤m1≤x1,x2,x3≤n,1≤y1,y2,y3≤m) describing the next operation. This operation will be made with three cells (x1,y1)(x1,y1), (x2,y2)(x2,y2), (x3,y3)(x3,y3). These three cells should be different. These three cells should belong into some 2×22×2 square.
Example
input
Copy
5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101
output
Copy
1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2
Note
In the first test case, it is possible to make only one operation with cells (1,1)(1,1), (2,1)(2,1), (2,2)(2,2). After that, all symbols will be equal to 00.
In the second test case:
- operation with cells (2,1)(2,1), (3,1)(3,1), (3,2)(3,2). After it the table will be:
011 001 000
- operation with cells (1,2)(1,2), (1,3)(1,3), (2,3)(2,3). After it the table will be:
000 000 000
In the fifth test case:
- operation with cells (1,3)(1,3), (2,2)(2,2), (2,3)(2,3). After it the table will be:
010 110
- operation with cells (1,2)(1,2), (2,1)(2,1), (2,2)(2,2). After it the table will be:
000 000
- ============================================================================================================================================
之前出过类似的题目,这类题除了针对一个一个进行填补或归位没有任何好方法,突破点就在限制的次数上,3*n*m 就意味着一个点构成的2*2方阵,要想单独改变一个而不去改变其余三个,需要进行三次操作。演草可以退出四个位置的1的改变方法,然后放在图上进行分类讨论即可
# include<iostream>
using namespace std;
char s[110][110];
int main ()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>s[i][j];
ans+=(s[i][j]=='1');
}
}
cout<<ans*3<<endl;
for(int i=1;i<=n-1;i++)
{
for(int j=1;j<=m-1;j++)
{
if(s[i][j]=='1')
{
cout<<i<<" "<<j<<" "<<i+1<<" "<<j<<" "<<i+1<<" "<<j+1<<endl;
cout<<i<<" "<<j<<" "<<i<<" "<<j+1<<" "<<i+1<<" "<<j<<endl;
cout<<i<<" "<<j<<" "<<i<<" "<<j+1<<" "<<i+1<<" "<<j+1<<endl;
}
}
}
for(int i=1;i<=n-1;i++)
{
if(s[i][m]=='1')
{
int j=m;
cout<<i<<" "<<j<<" "<<i+1<<" "<<j-1<<" "<<i+1<<" "<<j<<endl;
cout<<i<<" "<<j-1<<" "<<i<<" "<<j<<" "<<i+1<<" "<<j-1<<endl;
cout<<i<<" "<<j<<" "<<i<<" "<<j-1<<" "<<i+1<<" "<<j<<endl;
}
}
if(s[n][1]=='1')
{
int i=n,j=1;
cout<<i<<" "<<j<<" "<<i-1<<" "<<j<<" "<<i-1<<" "<<j+1<<endl;
cout<<i<<" "<<j<<" "<<i<<" "<<j+1<<" "<<i-1<<" "<<j<<endl;
cout<<i<<" "<<j<<" "<<i<<" "<<j+1<<" "<<i-1<<" "<<j+1<<endl;
}
for(int j=2;j<=m;j++)
{
if(s[n][j]=='1')
{
int i=n;
cout<<i<<" "<<j<<" "<<i-1<<" "<<j-1<<" "<<i<<" "<<j-1<<endl;
cout<<i<<" "<<j<<" "<<i-1<<" "<<j<<" "<<i-1<<" "<<j-1<<endl;
cout<<i<<" "<<j<<" "<<i-1<<" "<<j<<" "<<i<<" "<<j-1<<endl;
}
}
}
return 0;
}
边栏推荐
猜你喜欢

小程序优化实践

Week 4 Step by step building multi-layer neural network and application (1 & 2)

项目分析(嵌入式产品Web化)

NetCore uses Dapper to query data

Awk syntax-03-awk expressions (if statements, while loops, for loops), execute shell commands in awk

监控工具Prometheus及项目总结,220805,,

leetcode 112. Path sum recursion

Nanny level tutorial!Golang microservices simple architecture in practice

高效记忆法

ToDesk企业版上新 | 十大新功能,让企业远控更安全、更便捷、更流畅
随机推荐
拒绝“内卷”跃迁软件测试最大门槛,我是如何从月薪8K到15K的?
Video Signal Loss Detection Based on Image 2D Entropy (Signal Loss Detection)
Awk syntax-03-awk expressions (if statements, while loops, for loops), execute shell commands in awk
leetcode 70.爬楼梯 动态规划
topk()/eq( ) / gt( ) / lt( ) / t( )的用法
【图基础】如何定义异质图上的小样本学习:Heterogeneous Graph Few-Shot Learning
Implementing Express middleware principles
vulfocus靶场情景模式-内网死角
剑指 Offer 17. 打印从1到最大的n位数
The difference between orElse and orElseGet in Optional
Flume (三) --------- Flume 进阶
NLP之基本介绍
Strong Net Cup 2019 - Casual Bet (Stacked Injection)
The research project of the Institute of Metal Research of the Chinese Academy of Sciences has been certified by Huawei, helping to develop a new paradigm in materials science!
Amazon Cloud Technology Build On Learning Experience
语音鉴定软件
C语言 扫雷
L3-007 天梯地图(测试点2卡住了可以看下)
Shell 脚本 — 多行注释、开启子/不开启子进程执行、转义带颜色输出、读取键盘输入、输入输出重定向、单双引号、命令替换、读取变量、系统变量、正则过滤、算术运算、一行多条命令、字符串比较
使用 Presto 和 Alluxio 在 AWS 上搭建高性能平台来支持实时游戏服务