Codeforces 66B:Petya and Countryside(水题)

Codex智能体从零搭建:环境配置、代码管理与MCP扩展实战 AI智能体(Agent)作为连接大语言模型与实际应用的关键技术,通过感知、决策与执行框架,将AI能力融入具体工作流。其核心原理在于利用提示工程、上下文管理与工具调用,将自然语言指令转化为可执行操作。在软件开发领域,AI智能体能够显著提升代码生成、项目管理和自动化任务的效率。通过Model Context Protocol(MCP)等标准化协议,智能体可以安全、结构化地集成外部工具与服务,实现能力扩展。本文聚焦于Codex这一AI驱动的代码助手平台,详细解析其环境配置、代码索引、记忆系统等核心模块,并深入探讨 阅读详情
B. Petya and Countryside
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.

Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 × 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:

As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.

Input

The first line contains a positive integer n (1 ≤ n ≤ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.

Output

Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.

Examples
input
1
2
output
1
input
5
1 2 1 2 1
output
3
input
8
1 2 1 1 1 3 3 4
output
6



题意:简化下意思,就是给你若干个紧挨着的长方形,这些长方形的宽度为1,高度为你所输入的值,比如图上的三号长方形,它的高度为3,如果在它上面浇水,水最多能漫多远距离(当低的长方形遇到比它高的长方形时,就停止流动)。这个题目就是求这些长方形中,漫水最远的那个长方形所漫的最远长度。

解题思路:看着题目数据不大,一个一个长方形求(枚举)。以每个长方形为起点,向左右两边扫,每扫完一个起点,则更新下max。

#include <stdio.h>
int a[1010];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		int max=-1;//初始化max 
		for(int i=0;i<n;i++)//大循环控制起点 
		{
			int cnt=1;//包括这个起点本身,所以初始化为1 
			int tmp=i;//tmp作每次的小起点 
			for(int j=tmp-1;j>=0;j--)//向左扫 
			{
				if(a[j]>a[tmp])//遇到高的了 
				break;
				tmp--;
				cnt++;
			}
			tmp=i;
			for(int j=tmp+1;j<n;j++)//向右扫 
			{
				if(a[j]>a[tmp])//遇到高的了 
				break;
				tmp++;
				cnt++;
			}
			if(cnt>max)//更新max 
			{
				max=cnt;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}



★教程1:matlab学习教程入门100例目录 ★基础入门 1.为什么要学习MATLAB 2.MATLAB安装 持续更新....... ★MATLAB基础编程语言熟悉 阅读详情

相关推荐

PROFINET方案选型指南:瑞萨/西门子/开源p-net协议栈对比实测

本文基于瑞萨RZ/N2L硬件平台,对瑞萨官方认证协议栈、西门子ERTECH及开源p-net三种PROFINET方案进行了实测对比。重点分析了PROFINET-IRT实时性、CPU/内存资源消耗、开发集成复杂度及许可证成本等核心指标,为工业设备制造商提供了从性能到商业决策的全面选型指南。

weixin_29291185的博客 217

CodeForces 66B Petya and Countryside (枚举)

B. Petya and Countryside time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya often travels to his

Calm微笑 671

Miniforge3部署教程,完美替代Anaconda3

大背景不介绍了,哎!直接上教程!

zzy_ucas的博客 1万+

CF 66B Petya and Countryside

然而这是一道大水题。。 主要思想就是以一个为中心,然后朝两边找。 然而暴力的代码一点也不优美。于是我们想办法直接处理,用递推就可以解决。 这是我在Code Forces里第一次交题目。。 #include using namespace std; int n,a[1001],f1[1005],f2[1005],ans; void read() { int i,j; cin>>n

Blackieonly的博客 474

4D 毫米波雷达:智驾普及的新路径(一)

总体而言,4D 毫米波雷达具有更佳的探测能力,更高的分辨率和精度,在人工智能技术的加持下,能够实现更加智能化的感知和跟踪,从而为自动驾驶、智能交通等领域提供更加可靠的数据支持。博世的第五代引入了俯仰维度,但其角度分辨率较差,且最大探测距离为。车载毫米波雷达的尺寸受限,我们认为通过算法的优化、天线内置等方式可以在保障性能的前提下,压缩尺寸,便于车企进行灵活的设计安装。在物理设计、天线性能设计、电连接、封装工艺和材料、散热处理、可靠性与自动化测试等方面进行持续优化,推出可大规模量产的高性能毫米波雷达解决方案。

奔袭的算法工程师 3964

共模电感在EMI滤波中的实战应用与设计技巧

本文深入探讨了共模电感在EMI滤波中的关键作用与设计技巧,涵盖电感值选择、饱和电流风险、磁芯材料性能及绕组工艺等实战经验。通过具体案例解析,展示了共模电感在开关电源、高速接口及汽车电子中的高效应用,帮助工程师解决电磁兼容问题并提升信号完整性。

weixin_27051161的博客 428

CodeForces 66B - Petya and Countryside(水题)

B. Petya and Countryside time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Little Petya often travels to his grandmother in the countryside.

Snakeflute的博客 581

RH850从0搭建Autosar开发环境【7】- Davinci Configurator之CanTp模块配置详解(上)

RH850从0搭建Autosar开发环境【7】- Davinci Configurator之CanTp模块配置详解(上)

weixin_42412049的博客 2308

【CodeForces】66B - Petya and Countryside(递增子串变形题,模拟)

B. Petya and Countryside time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya often travels to his

wyg1997 957

手把手教你学Simulink--基于未来出行解决方案的场景实例:电动飞行汽车(eVTOL)的动力系统建模与仿真

电动垂直起降飞行器零道路拥堵:三维空间飞行绿色低碳:全电驱动,零排放快速响应:城市内15分钟直达低噪音:相比直升机↓20dB📊 预测:2030年全球eVTOL市场规模将超300亿美元,中国、美国、欧洲加速适航认证。本文通过,构建了电动飞行汽车(eVTOL)动力系统高压电池系统建模电力电子(DC-DC、逆变器)实现PMSM电机+螺旋桨推进系统搭建完整飞行任务动态仿真性能KPI评估与优化。

MHD0815的博客 450

Electron - Electron failed to install correctly, please delete node_modules/electron and try install

Electron安装失败:Electron failed to install correctly, please delete node_modules/electron and try installing again,electron安装报错:Electron failed to install correctly...解决方案,Electron 未能正确安装,请删除 node_modules/electron,然后再次尝试安装,如何解决这个问题,手把手教你解决,在yarn dev时报错,electr

🏆 前端领域优质创作者 4374

【CodeForces】[66B]Petya and Countryside

题目理解有点难度 其实就是找出一个最大的“山”形 也就是先不递减再不递增的形状理解了题意 代码就很容易写了

BoilTask Talk Show 976

科研绘图系列:R语言circos图(circos plot)

科研绘图系列:R语言circos图(circos plot)

专注生信领域 3447

CodeForces 66BPetya and Countryside

Description Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This

菜鸟的自我修养 276

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

D - Petya and Countryside CodeForces - 66B(模拟)

D - Petya and Countryside CodeForces - 66B Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, ...

tomjobs的博客 523

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

NYOJ:244 16进制的简单运算(c语言基础)

16进制的简单运算 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述现在给你一个16进制的加减法的表达式,要求用8进制输出表达式的结果。 输入第一行输入一个正整数T(0 接下来有T行,每行输入一个字符串s(长度小于15)字符串中有两个数和一个加号或者一个减号,且表达式合法并且所有运算的数都小于31位 输出每个表达式输出占一行,输出

zugofn的博客 5609

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

NYOJ:题目113 字符串替换

字符串替换 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述编写一个程序实现将字符串中的所有"you"替换成"we" 输入输入包含多行数据  每行数据是一个字符串,长度不超过1000  数据以EOF结束 输出对于输入的每一行,输出替换后的字符串 样例输入 you are what you do 样例输出 we a

zugofn的博客 4299

NYOJ:题目111 分数加减法

分数加减法 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述编写一个C程序,实现两个分数的加减法 输入输入包含多行数据  每行数据是一个字符串,格式是"a/boc/d"。  其中a, b, c, d是一个0-9的整数。o是运算符"+"或者"-"。  数据以EOF结束  输入数据保证合法 输出对于输入数据的每一行输出两个分

zugofn的博客 3354

HDU:5908 Abelian Period(水题+技巧)

Abelian Period    Accepts: 288    Submissions: 984  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others) 问题描述 设SS是一个数字串,定义函数occ(S,x)occ(S,x)表示SS中数字xx的

zugofn的博客 1566

HDU:2073 无限的路(数学,水)

无限的路 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8089    Accepted Submission(s): 4197 Problem Description 甜甜从小就喜欢画图画,最近他买了一支智能画

zugofn的博客 1175

NYOJ:题目60 谁获得了最高奖学金

谁获得了最高奖学金 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述    某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同:   1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得;   2) 五四奖学金,每人4000元,期末平均成绩

zugofn的博客 1053

Light OJ:1136 Division by 3(规律)

1136 - Division by 3     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB There is sequence 1, 12, 123, 1234, ..., 12345678910, ... .

zugofn的博客 995

Codeforces 501B:Misha and Changing Handles(略水+小小技巧)

B. Misha and Changing Handles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Misha hacked the Codeforces si

zugofn的博客 885

Codeforces 500A:New Year Transportation(水题)

A. New Year Transportation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output New Year is coming in Line World

zugofn的博客 843

Codeforces 84A:Toy Army(水题)

Toy Army time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The hero of our story, Valera, and his best friend

zugofn的博客 790

Codeforces 300A:Array(易错)

A. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vitaly has an array of n distinct integers. Vitaly

zugofn的博客 779
上一篇: Codeforces 66A:Petya and Java(水题)
下一篇: Codeforces 75A:Life Without Zeros(水题)
zugofn
博客等级 码龄11年 43粉丝 278原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值