Codeforces Global Round 8 C. Even Picture(构造)

题目链接:https://codeforces.com/contest/1368/problem/C

题意

构造一个只含有灰、白块的网格,要求:

  • 所有灰块为一个连通块
  • 每个灰块与偶数个灰块相邻
  • 恰有 $n$ 个灰块四周都有灰块

题解

即在 $n = 1$ 网格的基础上更新右上角三个点的坐标即可。

代码一

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    cout << 7 + (n - 1) * 3 << "\n";
    vector<pair<int, int>> v(
        {
            {0, 0}, 
            {0, 1}, 
            {1, 0}, 
            {1, 1}, 
            {1, 2}, 
            {2, 1}, 
            {2, 2}
        }
    );
    for (int i = 0; i < 7; i++) {
        cout << v[i].first << ' ' << v[i].second << "\n";
    }
    for (int i = 1; i < n; i++) {
        for (int j = 4; j < 7; j++) {
            cout << v[j].first + i << ' ' << v[j].second + i << "\n";
        }
    }
}

代码二

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    cout << 3 * n + 4 << "\n";
    cout << 0 << ' ' << 0 << "\n";
    for (int i = 0; i <= n; i++) {
        cout << i << ' ' << i + 1 << "\n";
        cout << i + 1 << ' ' << i << "\n";
        cout << i + 1 << ' ' << i + 1 << "\n";
    }
}

 

posted @ 2020-06-19 10:25  Kanoon  阅读(327)  评论(0编辑  收藏  举报