关于队里面最菜的在博客打卡第五十三天这件事

题目:https://codeforces.com/contest/1439/problem/A1

神奇大模拟

 ac代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>

using namespace std;
typedef pair<int,int> PII;
const int N = 110;
char a[N][N];
int n , m ;

vector<PII> ans;

void ooo()
{
    for(int i = 1; i <= n ; i ++)puts(a[i]+1);
    cout <<"ans:" <<ans.size()<<endl;
    cout <<endl;
}

void push3(int x ,int y)
{
    //puts("bug3");
    for(int i = x; i < x + 2 ; i ++)
    for(int j = y ; j < y + 2; j ++)
        {
            if(a[i][j] == '1')ans.push_back({i,j});
            a[i][j] = '0';
        }
        
}

void push2(int x , int y)
{
    PII temp[2] ;
    int cnt = 0 ;
    //puts("bug2");
    for(int i = x ; i < x + 2; i ++)
        for(int j = y ; j < y + 2; j ++)
        {
            if(a[i][j] == '1')temp[cnt++] = {i,j};
        }

    // for(int i = 0; i <= 1 ; i ++)
    // {
    //     cout << temp[i].first<<' '<<temp[i].second <<endl;
    // }
    
        for(int i = x ; i < x + 2 ; i ++)
            for(int j = y ; j < y + 2; j ++)
            {
                if(a[i][j] == '0')
                {
                    ans.push_back({i,j});
                    a[i][j] = '1';
                }
            }

        ans.push_back(temp[0]);
        a[temp[0].first][temp[0].second] = '0';
        push3(x,y);
    
}

void push1(int x , int y)
{
    // puts("push1");
    int potx , poty ;
    for(int i = x ; i < x + 2; i ++)
        for(int j = y ; j < y + 2 ; j ++)
        {
            if(a[i][j] == '1')
            {
                potx = i , poty = j ;
            }
        }
    
    ans.push_back({potx,poty});
    int num = 0 ;
    for(int i = x ; i < x + 2; i ++)
        for(int j = y ; j < y + 2; j ++)
        {
            if(a[i][j] == '0')
            {
                a[i][j] = '1';
                ans.push_back({i,j});
                num ++;
            }
            if(num == 2)
            {
                a[potx][poty] = '0';
                push2(x,y);
                return ;
            }
        }
}

void push4(int x, int y)
{
    int num = 0 ;
    for(int i = x ; i < x + 2; i ++)
        for(int j = y ; j < y + 2; j ++)
        {
            if(a[i][j] == '1')
            {
                num ++ ;
                a[i][j] = '0';
                ans.push_back({i,j});
            }
            if(num == 3)
            {
                push1(x,y);
                return ;
            }
        }
}



int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        ans.clear();
        cin >> n >> m ;
        for(int i = 1; i <= n ; i ++)
        cin >> a[i] + 1;
        for(int i = 1; i + 1 <= n ; i += 2)
        {
            for(int j = 1; j + 1 <= n ; j += 2)
            {
                // cout << i <<' '<< j << endl;
                int num = 0 ;
                for(int i1 = i ; i1 < i + 2; i1 ++)
                for(int j1 = j ; j1 < j + 2 ;j1 ++)
                {
                    if(a[i1][j1] == '1')num ++ ;
                }
                if(num == 0)continue;
                else if(num == 1)push1(i,j);
                else if(num == 2)push2(i,j);
                else if(num == 3)push3(i,j);
                else if(num == 4)push4(i,j);
                // ooo();
            }
        }
        // puts("status2");
        for(int i = 1; i + 1 <= n ; i ++)
        {
            for(int j = m - 1; j >= 2; j -= 2)
            {

                int num = 0 ;
                for(int i1 = i ; i1 < i + 2; i1 ++)
                for(int j1 = j ; j1 < j + 2 ;j1 ++)
                {
                    if(a[i1][j1] == '1')num ++ ;
                }
                if(num == 0)continue;
                else if(num == 1)push1(i,j);
                else if(num == 2)push2(i,j);
                else if(num == 3)push3(i,j);
                else if(num == 4)push4(i,j);
            }
        }

        for(int i = n - 1;  i >= 2 ; i -= 2)
        {
            for(int j = m - 1; j >= 2; j -= 2)
            {

                int num = 0 ;
                for(int i1 = i ; i1 < i + 2; i1 ++)
                for(int j1 = j ; j1 < j + 2 ;j1 ++)
                {
                    if(a[i1][j1] == '1')num ++ ;
                }
                if(num == 0)continue;
                else if(num == 1)push1(i,j);
                else if(num == 2)push2(i,j);
                else if(num == 3)push3(i,j);
                else if(num == 4)push4(i,j);
                // ooo();
            }
        }
        for(int i = n - 1;  i >= 2 ; i -= 2)
        {
            for(int j = 1; j + 1 <= m; j += 2)
            {

                int num = 0 ;
                for(int i1 = i ; i1 < i + 2; i1 ++)
                for(int j1 = j ; j1 < j + 2 ;j1 ++)
                {
                    if(a[i1][j1] == '1')num ++ ;
                }
                if(num == 0)continue;
                else if(num == 1)push1(i,j);
                else if(num == 2)push2(i,j);
                else if(num == 3)push3(i,j);
                else if(num == 4)push4(i,j);
                // ooo();
            }
        }
        cout << ans.size()/3<<endl;
        for(int i = 0 ; i < ans.size() ; i ++)
        {
            cout << ans[i].first<<' '<<ans[i].second<<' ';
            if((i+1) % 3 == 0)cout <<endl;
        }
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值