## 题解

``````//minamoto
#include<bits/stdc++.h>
#define R register
#define inf 0x3f3f3f3f
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=505,M=1e5+5;
struct node{int x,y;}p[M],nfly,a,b;
inline void swap(node &a,node &b){node t=a;a=b,b=t;}
bitset<N>pfly[N],fly[N],now;double st[N];bool ans[N][N];
int n,m,k,top,mnx=inf,mny=inf,mxx=-inf,mxy=-inf,res;
int main(){
//  freopen("testdata.in","r",stdin);
fp(i,1,k){
cmin(mnx,p[i].x),cmin(mny,p[i].y),cmax(mxx,p[i].x),cmax(mxy,p[i].y);
}
mxx-=mnx,mxy-=mny;fp(i,1,k)p[i].x-=mnx,p[i].y-=mny,pfly[p[i].x].set(p[i].y);
fp(x,0,mxx){
top=0;
fp(i,1,k){
a=p[i],b=p[i==k?1:i+1];if(a.y>b.y)swap(a,b);
if((a.x<x&&b.x<x)||(a.x>x&&b.x>x)||(a.x==x&&b.x>x)||(b.x==x&&a.x>x))continue;
if(a.x==x&&b.x==x){
fp(y,a.y+1,b.y-1)pfly[x].set(y);
continue;
}
double k=1.0*(b.y-a.y)/(b.x-a.x);
st[++top]=k*(x-a.x)+a.y;
}
sort(st+1,st+1+top);
for(R int y=0,flag=0,i=1;y<=mxy;++y){
while(i<=top&&st[i]<y)++i,flag^=1;
if(flag||(i<=top&&st[i]==y))pfly[x].set(y);
}
}
fp(i,0,mxx)fp(y,0,m-mxy){
now=pfly[i]<<y;
fp(x,0,n-mxx)if(!ans[x][y]&&(now&fly[x+i]).any())ans[x][y]=1;
}
fp(x,0,n-mxx)fp(y,0,m-mxy)res+=!ans[x][y];
printf("%d\n",res);
return 0;
}``````

0条评论