跳到正文

题解

P11011 「ALFR Round 4」A 点的覆盖

liuyuanpei约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P11011

版本

  1. v1当前

赛时改了半个小时的橙题,特此纪念

这一题建议打上数学和组合数学的标签。

因为要能全部覆盖 p1,p2,p3......pnp_{1},p_{2},p_{3}......p_{n},所以一定要求一个最小的矩形可以把这 nn 个点覆盖,即求出这 nn 个点的横纵坐标的最大值和最小值。

如图,可以发现,只要一个矩形可以包含蓝色矩形就可以加入答案,而方法就是求蓝色矩形到每条边可以的情况数的乘积。

代码:

C++
# include <iostream>
# include <cmath>
# include <cstring>
# include <string>
# include <algorithm>
# include <stack>
# include <queue>
# include <vector>
# include <set>
# include <map>
using namespace std;
int mod=1e9+7;//求模
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio (false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,x1,y1,x2,y2,x,y;
    long long s1=0,s2=0,s3=0,s4=0;
    long long max1=-1e9,max2=-1e9,min1=1e9,min2=1e9;
	//特别注意:不开 Long Long 见祖宗!
    cin >>n>>x1>>y1>>x2>>y2;
    for (int i=1;i<=n;i++){
    	cin >>x>>y;
    	max1=max(max1,x);
    	max2=max(max2,y);
    	min1=min(min1,x);
    	min2=min(min2,y);
    	//求 n 个点的边界值
	}
	s1=min1-x1+1;
	s2=x2-max1+1;
	s3=min2-y2+1;
	s4=y1-max2+1;
	//因为是可以选的情况,所以一定要 +1
	cout <<s1*s2%mod*s3%mod*s4%mod<<endl;
	//注意取模
    return 0;
}
原文