Problem A. Alter Board


题目描述:

Problem A. Alter Board
Input file: alter.in
Output file: alter.out
Little Dima gave his little brother Petya interactive chess board of size n × m as a present. There are
many awesome features of this board but one is Petya’s favorite. He can choose any rectangle formed by
board squares and perform an inversion. Every white cell in the inverted rectangle becomes black and
every black one becomes white.
In the initial state the board is colored in chess style, namely every cell is either black or white and
every two cells that share a side have different colors. Little Petya wants to perform several inversions
described above to turn all cells into the same color. He is impatient, so he asks you to provide him with
instructions to do it with the minimal number of inversions.
Input
The input file contains two integers, n and m (1 ≤ n, m ≤ 50) — the number of rows and columns on
the board, respectively.
Output
The first line of the output file must contain k — the number of inversions required to transform the
board.
The following k lines must describe inversions, one per line. Each line must contains 4 integers — row
and column of one of the corners of the corresponding rectangle and row and column of the opposite
corner. Any two opposite corners can be used to specify a rectangle.
Rows of the board are numbered from 1 to n. Columns of the board are numbered from 1 to m.
Sample input and output
alter.in alter.out
2 2 2
1 1 1 1
2 2 2 2

题解:

签到第一题.但是思想很好. 我们只考虑第一列,每次选中翻转,只会使得首尾的两个合他们相邻的颜色一样,就是说每次只会最多能两个(对于一列来说).
而猜出来的思路就是:先翻转偶数列,再翻转偶数行.

重点:

翻转内部的是不会改变的,只有相邻的.猜一下改变的东西.

代码:
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int n, m;

void solve()
{
    int ans = n/2+m/2;
    printf("%d\n", ans);
    for(int i = 2;i<=m;i+=2)
    {
        printf("%d %d %d %d\n", 1, i, n, i);
    }
    for(int i = 2;i<=n;i+=2)
    {
        printf("%d %d %d %d\n", i, 1, i, m);
    }
}

int main()
{
    freopen("alter.in", "r", stdin);
    freopen("alter.out", "w", stdout);
    while(scanf("%d%d", &n, &m)!=EOF)
    {
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值