当前位置: 代码迷 >> 综合 >> Codeforces C. Even Picture (构造 / 模拟)(Global Round 8)
  详细解决方案

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

热度:9   发布时间:2023-12-22 13:46:20.0

传送门

题意: 在一张无限的方格图上,怎样在图中涂色k个点才会使得有n个灰色方格的四周都是灰色,其他k - n个灰色方格四周有两个灰色。
在这里插入图片描述
思路:

  • 以(0,0)为左顶点,x + y = 0上的点取n个,这n个点四周的点就是那k - n个灰点;因此k = n * 3 + 4.

在这里插入图片描述

代码实现:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {
    {
    1, 0}, {
    -1, 0}, {
    0, 1}, {
    0, -1}};
using namespace std;
const int  inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll   mod = 1e9 + 7;
const int  N = 2e5 + 5;int n;
signed main()
{
    IOS;cin >> n;cout << n * 3 + 4 << endl;cout << "0 0" << endl;for(int i = 0; i <= n; i ++){
    cout << i + 1 << " " << i << endl;cout << i << " " << i + 1 << endl;cout << i + 1 << " " << i + 1 << endl;}return 0;
}
  相关解决方案