Codeforces Global Round 8-C. Even Picture

题目链接

题意:

输入一个n,输出怎样填充一个范围无限大的方格平面才能使得有n个方块周围(上下左右)的方块都被填充且其余方块周围的填充数是2。
有道翻译是真的6(微笑),莫名其妙翻译出一句k(总填充数)需要尽可能小。

思路:

构造一个可以无限延长的一十字形的斜着重叠且完全符合题意的区域,如果n变化,那么该区域长度也随着有规律的变化,具体形状构造看代码。

代码实现:

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=2e5+5;
const int mod=1e9+7;
const int inf=0x7fffffff;
const double pi=3.1415926535;
using namespace std;
signed main()
{
    int n;
    cin>>n;
    cout<<n*3+4<<endl;
    cout<<"0 0"<<endl;
    for(int i=1;i<=n+1;i++)
    {
        cout<<i<<" "<<i<<endl;
        cout<<i<<" "<<i-1<<endl;
        cout<<i-1<<" "<<i<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ACkingdom/article/details/106877632