Codeforces Round #777 (Div. 2) C. Madoka and Childish Pranks

 

【题意】

  给你一个n*m的白色桌面。将其变成一个黑白相间的图案(1代表黑色,0代表白色)。每次操作可以选定一个大小的矩形,按照左上角是白色,黑白间隔的染色。

  如果可以是,输出操作次数(不用最小),并输出路径。如果不可以输出-1。

【思路】:
  数据范围为100*100 不用担心时间复杂度。

  我们从右下角开始遍历。选择每一个黑色块,修改与他的左边或者上边某一块变成白的,这样可以不影响其他的状态。

【代码】:

#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>

#define ms(a, b) memset(a,b,sizeof(a))
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define rep(i, a, b)  for(ll i=a;i<=b;i++)
#define lep(i, a, b)  for(ll i=a;i>=b;i--)
#define endl '\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi  vector<ll>
#define vpi vector<pii>
#define vpl vector<pll>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define ff first
#define ss second
#define test4(x, y, z, a) cout<<"x is "<<x<<"        y is "<<y<<"        z is "<<z<<"        a is "<<a<<endl;
#define test3(x, y, z) cout<<"x is "<<x<<"        y is "<<y<<"        z is "<<z<<endl;
#define test2(x, y) cout<<"x is "<<x<<"        y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
using namespace std;
const int N = 110;
const int maxx = 0x3f3f3f;
const int mod = 1e9 + 7;
const int minn = -0x3f3f3f;
const int M = N;
ll T, n, m;
struct node {
    ll a,b,x,y; // 记录路径
};
char s[N][M];
int a[N][M];
void solve() {
    cin>>n>>m;
    int flag=0;
    rep(i,1,n){
        rep(j,1,m){
            cin>>s[i][j];
            a[i][j] = s[i][j] -'0';
            if ( a[i][j]==1 )   flag=1;
        }
    }
    if ( flag==0 )  {cout<<0<<endl;return ; }
    if ( a[1][1]==1 )   {cout<<-1<<endl;return ; }
    vector<node> v;
    lep(i,n,1){
        lep(j,m,1){
            if ( a[i][j]==1 ){
                if ( j==1 ){
                    v.push_back({i-1,j,i,j});
                }else{
                    v.push_back({i,j-1,i,j}); // 将路径放在vector中、
                }
            }
        }
    }
    cout<<v.size()<<endl;
    for ( auto p: v){
        cout<<p.a<<' '<<p.b<<' '<<p.x<<' '<<p.y<<endl;
    }
}
int main() {
    fast;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
View Code

 

posted @ 2022-03-16 00:24  Pan_c  阅读(79)  评论(0)    收藏  举报