前四题对应这套题的 C C C~ F F F
E
传送门
考虑用扫描线的思想将原图分成若干小矩形,然后就可以利用行列二分图匹配+差分的思想建图,最后用 d i n i c dinic dinic跑最小割即可。
代码:
#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
const int rlen=1<<18|1;
inline char gc(){
static char buf[rlen],*ib,*ob;
(ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin));
return ib==ob?-1:*ib++;
}
inline int read(){
int ans=0;
char ch=gc();
while(!isdigit(ch))ch=gc();
while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
return ans;
}
typedef pair<int,int> pii;
const int N=505,inf=1e9;
int sx,sy,vx[N],vy[N],trans[N][N],n;
pii a[N];
struct edge{
int v,c,next;};
namespace dinic{
edge e[1000005];
int first[N],cur[N],d[N],cnt,s,t;
inline void init(){
memset(first,-1,sizeof(first)),cnt=-1;}
inline void add(int u,int v,int c){
e[++cnt]=(edge){
v,c,first[u]},first[u]=cnt;}
inline void addedge(int u,int v,int c){
add(u,v,c