题解归档 - cf2236A
本文最后由方少年更新于2026 年 6 月 28 日,已超过0天没有更新。如果文章内容或图片资源失效,请留言反馈,将会及时处理,谢谢!
题解归档 - cf2236A
本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。
- 本地编号:
cf2236A - 本地来源:
problems/cf2236A/idea.md - 题目链接:https://codeforces.com/contest/2236/problem/A
思路
pattern:
range minimization
claim:
The minimum valid k is max(h)-min(h)+1.
why:
If the final common height is H, every tower needs 1<=H-h_i<=k, so H must be at least max(h)+1 and k must be at least H-min(h). The best choice is H=max(h)+1.
check:
For n<=5 and h_i<=6 this formula can be brute-forced by trying H and k directly.
edge:
If all heights are equal, each tower still must be increased by at least 1, so the answer is 1.
代码
来源:problems/cf2236A/solution.cpp
/* Author: likely
* Time: 2026-06-19 10:49:39
**/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=10;
ll p[maxn+5],n,i,j,k,mn,mx;
int main(){
ll t;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
mn=1e18;
mx=0;
for(i=1;i<=n;i++){
scanf("%lld",&p[i]);
mn=min(mn,p[i]);
mx=max(mx,p[i]);
}
printf("%lld\n",mx-mn+1);
}
return 0;
}
~ ~ The End ~ ~
文章标题:题解归档 - cf2236A
文章链接:https://www.fangshaonian.cn/archives/303/
最后编辑:2026 年 6 月 28 日 19:06 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)