#Codeforces Round #733_B. Putting Plates

B. Putting Plates

题目传送门;

题目传送门

题面:

在这里插入图片描述

题目大意:

意思是说一个矩阵长宽为 h , w h,w h,w,内部先全部变成0,只能在最外围那一圈把0变成1,规则是这个1九宫格里其他的几个不能为1。

代码:

#include<bits/stdc++.h>

using namespace std;
int a[22][22];
int n, m;
int check(int x, int y) {
	if (a[x + 1][y + 1] == 1 && x + 1 < n && y + 1 < m)return 0;
    if (a[x + 1][y - 1] == 1 && y - 1 >= 0 && x + 1 < n)return 0;
    if (a[x - 1][y + 1] == 1 && y + 1 < m && x - 1 >= 0)return 0;
    if (a[x - 1][y - 1] == 1 && x - 1 >= 0 && y - 1 >= 0)return 0;
    if (a[x + 1][y] == 1 && x + 1 < n)return 0;
    if (a[x - 1][y] == 1 && x - 1 >= 0)return 0;
    if (a[x][y + 1] == 1 && y + 1 < m)return 0;
    if (a[x][y - 1] == 1 && y - 1 >= 0)return 0;
    return 1;
}

int main() {
    int T;
    cin >> T;
    while(T--) {
        memset(a, 0, sizeof a);
        cin >> n >> m;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
                    if (check(i, j) == 1) {
                        a[i][j] = 1;
                    }
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << a[i][j];
            }
            cout << endl;
        }
        cout << endl;
    }
}

在Educational Codeforces Round 146 (Rated for Div. 2)比赛中,有关于一个节点数量为n的问题。根据引用的结论,无论节点数量是多少,都可以将其分成若干个大小为2或3的区间使其错排,从而减少花费。根据引用的推导,我们可以通过组合数和差量来表示剩余的花费。而引用进一步推广了这个结论,可以使得任意长度的一段错排花费代价为边权和的两倍,并且通过贪心算法使得更多的边不被使用。以此来解决与节点数量相关的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Educational Codeforces Round 146 (Rated for Div. 2)(B,E详解)](https://blog.csdn.net/TT6899911/article/details/130044099)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Educational Codeforces Round 83 (Rated for Div. 2) D](https://download.csdn.net/download/weixin_38562130/14878888)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值