• Codeforces Round #684 (Div. 1)


    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的改变方法,然后放在图上进行分类讨论即可

    1. # include
    2. using namespace std;
    3. char s[110][110];
    4. int main ()
    5. {
    6. int t;
    7. cin>>t;
    8. while(t--)
    9. {
    10. int n,m;
    11. cin>>n>>m;
    12. int ans=0;
    13. for(int i=1;i<=n;i++)
    14. {
    15. for(int j=1;j<=m;j++)
    16. {
    17. cin>>s[i][j];
    18. ans+=(s[i][j]=='1');
    19. }
    20. }
    21. cout<3<
    22. for(int i=1;i<=n-1;i++)
    23. {
    24. for(int j=1;j<=m-1;j++)
    25. {
    26. if(s[i][j]=='1')
    27. {
    28. cout<" "<" "<1<<" "<" "<1<<" "<1<
    29. cout<" "<" "<" "<1<<" "<1<<" "<
    30. cout<" "<" "<" "<1<<" "<1<<" "<1<
    31. }
    32. }
    33. }
    34. for(int i=1;i<=n-1;i++)
    35. {
    36. if(s[i][m]=='1')
    37. {
    38. int j=m;
    39. cout<" "<" "<1<<" "<1<<" "<1<<" "<
    40. cout<" "<1<<" "<" "<" "<1<<" "<1<
    41. cout<" "<" "<" "<1<<" "<1<<" "<
    42. }
    43. }
    44. if(s[n][1]=='1')
    45. {
    46. int i=n,j=1;
    47. cout<" "<" "<1<<" "<" "<1<<" "<1<
    48. cout<" "<" "<" "<1<<" "<1<<" "<
    49. cout<" "<" "<" "<1<<" "<1<<" "<1<
    50. }
    51. for(int j=2;j<=m;j++)
    52. {
    53. if(s[n][j]=='1')
    54. {
    55. int i=n;
    56. cout<" "<" "<1<<" "<1<<" "<" "<1<
    57. cout<" "<" "<1<<" "<" "<1<<" "<1<
    58. cout<" "<" "<1<<" "<" "<" "<1<
    59. }
    60. }
    61. }
    62. return 0;
    63. }

  • 相关阅读:
    数据结构学习系列之双向链表的三种插入方式
    微前端的初探索
    MyBatus-Plus保姆级快速上手教程
    使用Docker一键部署MongoDB
    Meta降本增效大招之:弃用产品
    【C++位图】1. 快速查找某个数据是否在一个集合中 2. 排序(全部插入,遍历一遍) 3. 求两个集合的交集、并集等
    【深度学习】《动手学深度学习》环境配置
    远程教育:低代码重塑教育技术
    Netty
    代码随想录二刷day45
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126213140