题解 P5542 【[USACO19FEB]Painting The Barn S】
VioletIsMyLove · · 题解
笨蛋的方法就是模拟呗,每次都涂上,最后扫一趟就好了,但是这效率最慢是
Code:
#include<bits/stdc++.h>
#define maxh 1005
using namespace std;
int N,K,Ans,F[maxh][maxh];
int read(){
int ret=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-')f=-f;ch=getchar();}
while (isdigit(ch)) ret=(ret<<3)+(ret<<1)+ch-'0',ch=getchar();
return ret*f;
}
int main(){
N=read(),K=read();
while (N--){
int a=read()+1,b=read()+1,c=read()+1,d=read()+1;
F[a][b]++,F[a][d]--,F[c][b]--,F[c][d]++;
}
for (int i=1;i<=1001;i++)
for (int j=1;j<=1001;j++){
F[i][j]+=F[i-1][j]+F[i][j-1]-F[i-1][j-1];
Ans+=F[i][j]==K;
}
printf("%d\n",Ans);
return 0;
}