跳到正文

题解

题解:P10358 [PA2024] Obrazy

EMO_smile约 3 分钟
原文
文章信息与版本

文章信息

发布
2024年7月30日
收录
2026年9月21日
更新
2026年11月13日
篇幅
约 3 分钟
获赞
4
题目
P10358

版本

  1. v1当前

P10358 [PA2024] Obrazy

题目传送门

题意分析:

1.特判

我们很容易能够想到本题的特殊判断:即当最小的画框都不可能覆盖整个矩形墙面时,输出 −1-1。

2.常规

若我们将墙面的长设为 ll,宽设为 rr,画框最小边长为 a[i]a[i],画框可覆盖面积为 ansans(因为需要保证画框的完整性,不能让一个 2×22\times2 的画框变为 1×41\times4),易得:

ans=((l−(l mod a[i]))×(r−(r mod a[i]));ans=((l-(l\bmod a[i]))\times(r-(r\bmod a[i]));

当 ans<l×rans < l\times r 时,输出 −1-1。

我们可用一个变量 tmptmp 来表示当前画框可覆盖面积, a1[i]a1[i] 来判断第 ii 个画框的面积,判断当前有多少个 a1[i−1]a1[i-1] 面积的画框可以被 a1[i]a1[i] 整除即可:

C++
tmp=(l-(l%a[i]))*(r-(r%a[i]));
ans-=tmp/a1[i-1];//较小画框可换数量
ans+=tmp/a1[i];//较大画框可换数量

代码:

C++
//#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
inline long long read(){//快读
	long long x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-'){
			f=-1;
		}
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+(c^'0');
		c=getchar();
	}
	return x*f;
}
void write(int x){//快写(虽然不经常用)
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9){
		write(x/10);
	}
	putchar(x%10+'0');
	return;
}
long long a[1145141],f[1145141],n,m,l,r,a1[1145141];
int main(){
	l=read();r=read();
	m=l*r;//计算总面积
	n=read();
	long long ans=0;
	for(int i=1;i<=n;i++){
		a[i]=read();
		a1[i]=a[i]*a[i];
		if(i==1){//特判:最小画框有无可能全部覆盖
			ans=(l-(l%a[i]))*(r-(r%a[i]));
			ans=ans/a1[i];
			if(ans*a1[i]<m){
				cout<<-1;
				exit(0);//=return 0;
			}
		}else{
			long long tmp=(l-(l%a[i]))*(r-(r%a[i]));//tmp表示当前画框可覆盖面积
			ans-=tmp/a1[i-1];//较小画框可换数量
			ans+=tmp/a1[i];//较大画框可换数量
		}
	}
	cout<<ans;
	return 0;
}
原文
存档评论5 条抓取于