题解:P13655 [CERC 2020] Tobacco Growing
P13655 [CERC 2020] Tobacco Growing
思路
先看烟草生长的本质。假设某个点
初始时,种烟草的格子满足
我们要构造
现在假设有一片被割掉鲜花的区域,最开始只在原点种一棵烟草,其余格子初始烟草量均为
的三角形区域。
经过
从
那么整条斜线上的路径总数就是:
于是,只需要收割第
但是题目要求所有烟草都在同一个
可以在原点之前构造一条 延迟链。我们统一取
只需要构造
对于需要构造的
因此,种子到第
我们又恰好在第
最后将
对所有二进制位为
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int D = 59;
const int GAP = 200;
struct Cell{
int x, y, type;
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
ll n; cin >> n;
if(n == 0){
cout << 0 << "\n";
cout << 0 << " " << 0 << "\n";
return 0;
}
vector <Cell> cut;
vector < pair <int, int> > harvest;
for(int bit = 0; bit <= 59; bit++){
if(((n >> bit) & 1LL) == 0) continue;
int bx = 0;
int by = bit * GAP;
int len = D - bit;
int sx = bx - len;
int sy = by;
for(int t = 0; t <= len; t++){
int x = sx + t;
int y = sy;
if(t == 0)
cut.push_back({x, y, 1});
else
cut.push_back({x, y, 0});
}
for(int x = 0; x <= bit; x++){
for(int y = 0; x + y <= bit; y++){
if(x == 0 && y == 0) continue;
cut.push_back({bx + x, by + y, 0});
}
}
for(int x = 0; x <= bit; x++){
int y = bit - x;
harvest.push_back({bx + x, by + y});
}
}
cout << cut.size() << "\n";
for(int i = 0; i < (int)cut.size(); i++){
cout << cut[i].x << " " << cut[i].y << " " << cut[i].type << "\n";
}
cout << harvest.size() << " " << D << "\n";
for(int i = 0; i < (int)harvest.size(); i++){
cout << harvest[i].first << " " << harvest[i].second << "\n";
}
return 0;
}
复杂度
最多只会构造
所有三角形区域的格子总数为:
再加上所有延迟链,割掉的花坛数量仍远小于
收割点最多为:
同时
本文解法与代码由作者完成,AI 用于文字润色、排版检查、证明完整性检查。