辣鸡(ljh)
Posted 2018hzoicyf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了辣鸡(ljh)相关的知识,希望对你有一定的参考价值。
大模拟,按一个点(左下或右上)排序,考虑对他的贡献有四个方向,再减枝即可
第二个样例的图,拿走不谢
#include<cstdio> #include<iostream> #include<algorithm> #define int long long #define MAXN 100010 using namespace std; int n; inline int maxn(int a,int b) return a>b?a:b; inline int minn(int a,int b) return a<b?a:b; struct rr int x1,x2,y1,y2; friend bool operator <(const rr &a,const rr &b) if(a.x1==b.x1)return a.y1<b.y1; return a.x1<b.x1; qw[MAXN]; int ans; inline int nei(rr a) return (a.x2-a.x1)*(a.y2-a.y1)*2; signed main() //freopen("da.in","r",stdin); scanf("%lld",&n); for(int i=1;i<=n;++i) scanf("%lld%lld%lld%lld",&qw[i].x1,&qw[i].y1,&qw[i].x2,&qw[i].y2); ans+=nei(qw[i]); //cout<<ans<<endl; sort(qw+1,qw+n+1); int x1,x2,y1,y2,nx1,nx2,ny1,ny2; for(int i=1;i<=n;++i) x1=qw[i].x1;x2=qw[i].x2; y1=qw[i].y1;y2=qw[i].y2; //cout<<"QwQ"<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl; for(int j=i+1;j<=n;++j) nx1=qw[j].x1;nx2=qw[j].x2; ny1=qw[j].y1;ny2=qw[j].y2; //cout<<nx1<<" "<<ny1<<" "<<nx2<<" "<<ny2<<endl; if(nx1>x2+1)break; if(ny1>y2+1)continue; if(ny2+1<y1)continue; if(ny2+1==y1||ny1==y2+1) if(nx1==x2+1) ++ans; continue; //cout<<nx1<<" "<<ny1<<" "<<nx2<<" "<<ny2<<endl; ans+=2*(minn(x2,nx2)-maxn(x1,nx1)+1); if(x1==nx1)--ans; if(x2==nx2)--ans; //cout<<ans<<endl; continue; if(nx1==x2+1) //cout<<nx1<<" "<<ny1<<" "<<nx2<<" "<<ny2<<endl; ans+=2*(minn(y2,ny2)-maxn(y1,ny1)+1); if(y1==ny1)--ans; if(y2==ny2)--ans; //cout<<ans<<endl; continue; printf("%lld\\n",ans);
以上是关于辣鸡(ljh)的主要内容,如果未能解决你的问题,请参考以下文章