CodeForces 920A Water The Garden (C)

本文探讨了一种浇水策略,通过多个水龙头同时工作,确保整个花园在最短时间内得到充分灌溉。文章提供了两种算法实现方式,一种适用于复杂场景,另一种则更加简洁高效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目
It is winter now, and Max decided it’s about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can’t say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
在这里插入图片描述
The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.
在这里插入图片描述
The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn’t exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
1、There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
2、There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
3、There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.

题意:水龙头浇水,1个单位时间往外扩散一块地(所有水龙头同时扩散),求能给所有地浇上水的最短时间

 //复杂版
 #include <stdio.h>
int main()
{
	int t,n,k,s[200],i,x[200],max;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d",&n,&k);
		for(i=0;i<k;i++)
			scanf("%d",&x[i]); 
		for(i=0;i<k;i++)
		{
			if(i==0)       // 如果是第一个水龙头        
			{
			    if(k==1)      // 如果只有1个水龙头          
		            s[0]=x[0]>(n-x[0]+1)?x[0]:(n-x[0]+1);
		        else
		            s[0]=x[0]>((x[1]-x[0])/2+1)?x[0]:((x[1]-x[0])/2+1);
		    }
		    else if(i>0&&i<k-1)
		    	s[i]=((x[i]-x[i-1])/2+1)>((x[i+1]-x[i])/2+1)?((x[i]-x[i-1])/2+1):((x[i+1]-x[i])/2+1);
		    else if(i==k-1)      // 如果是最后一个水龙头
		        s[i]=((x[i]-x[i-1])/2+1)>(n-x[i]+1)?((x[i]-x[i-1])/2+1):(n-x[i]+1);
	    }
	    max=s[0];
	    for(i=0;i<k;i++)
		if(max<s[i]) 
		    max=s[i];
	    printf("%d\n",max);
	} 
	return 0;
}
//简单版
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	int t,n,k,x[210];
	scanf("%d",&t);
	while(t--)
	{
		int maxt=0;
		scanf("%d%d",&n,&k);
		for(int i=0;i<k;i++)
		{
			scanf("%d",&x[i]);
			if(i==0) maxt=x[i];
			if(i==k-1) maxt=max(maxt,n-x[i]+1);
			if(i>0&&i<=k-1) maxt=max(maxt,(x[i]-x[i-1])/2+1);
		}
		printf("%d\n",maxt);
	}
	return 0;
}
内容概要:该论文聚焦于T2WI核磁共振图像超分辨率问题,提出了一种利用T1WI模态作为辅助信息的跨模态解决方案。其主要贡献包括:提出基于高频信息约束的网络框架,通过主干特征提取分支和高频结构先验建模分支结合Transformer模块和注意力机制有效重建高频细节;设计渐进式特征匹配融合框架,采用多阶段相似特征匹配算法提高匹配鲁棒性;引入模型量化技术降低推理资源需求。实验结果表明,该方法不仅提高了超分辨率性能,还保持了图像质量。 适合人群:从事医学图像处理、计算机视觉领域的研究人员和工程师,尤其是对核磁共振图像超分辨率感兴趣的学者和技术开发者。 使用场景及目标:①适用于需要提升T2WI核磁共振图像分辨率的应用场景;②目标是通过跨模态信息融合提高图像质量,解决传统单模态方法难以克服的高频细节丢失问题;③为临床诊断提供更高质量的影像资料,帮助医生更准确地识别病灶。 其他说明:论文不仅提供了详细的网络架构设计与实现代码,还深入探讨了跨模态噪声的本质、高频信息约束的实现方式以及渐进式特征匹配的具体过程。此外,作者还对模型进行了量化处理,使得该方法可以在资源受限环境下高效运行。阅读时应重点关注论文中提到的技术创新点及其背后的原理,理解如何通过跨模态信息融合提升图像重建效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值