在开始之前,致敬越南选手的勇气首杀T1,同时为最后没有写出T3正解默哀。
sol
考虑对构造不合法最具威胁的情况:只有一个白色块。
这时候我们有一个初步的贪心想法,尽量让白色块发挥作用,即:
- 左上角白色,向右下角放置。
- 右上角白色,往左下角放置。
- 左下角白色,往右上角放置。
- 右下角白色,往左上角放置。
为什么合法?考虑不合法的情况:
对于两个大方块而言,若白色块分别同时位于上方/下方的左侧和右侧。这时候显然是不会出现的。举白色位于左上,右上的例子。因为一个左上角为白色的块右侧一定是一个左上角为白色的块,显然不存在这种情况。
若白色块分别位于左上,右下。白色左上在左侧,白色右下在右侧。这时候我们发现,白色位于右下的方块的左上方(包括正左和正上)应该都是白色在右下的方块才对,所以完全不会说出现我的左边有白色块在左上的情况。
其余方向同理可得。
于是优先队列维护 和 的最大最小就行了,每次取出如果重复直接跳过再取。
ac code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
#define node pair<int,pair<int,int>>
priority_queue<node> mx[2];
priority_queue<node,vector<node>,greater<node>> mn[2];
map<pair<int,int>,bool> mp;
void init(int N,int M){
n=N; m=M;
for(int i(0);i<n;++i){
for(int j(0);j<m;++j){
mx[0].push({i+j,{i,j}});
mx[1].push({i-j,{i,j}});
mn[0].push({i+j,{i,j}});
mn[1].push({i-j,{i,j}});
}
}
}
std::pair<int,int> receive_block(int TL,int TR,int BL,int BR){
pair<int,int> res;
if(!TL){
res=mx[0].top().second;
while(mp[res]){
mx[0].pop();
res=mx[0].top().second;
}
}
if(!TR){
res=mx[1].top().second;
while(mp[res]){
mx[1].pop();
res=mx[1].top().second;
}
}
if(!BL){
res=mn[1].top().second;
while(mp[res]){
mn[1].pop();
res=mn[1].top().second;
}
}
if(!BR){
res=mn[0].top().second;
while(mp[res]){
mn[0].pop();
res=mn[0].top().second;
}
}mp[res]=1;
res.first=(res.first<<1);
res.second=(res.second<<1);
return res;
}再次为越南大哥表示崇高敬意!