Timus 1935. Tears of Drowned 详解

魔法故事:古老预言家的蝙蝠皮保护术
古老预言家Tia Dalma利用特殊书籍保护珍贵蝙蝠皮,确保魔法元素不被破坏。本篇揭示如何计算最少所需书籍页数以保存稀有材料,涉及排序与最大值算法。

Old Captain Jack Sparrow’s friend Tia Dalma, the fortuneteller and prophetess, often makes potions. She has an outstanding collection of the rarest ingredients such as rat tails, fingers of drowned, tears of virgins and so on. And all these ingredients require special care.
Recently Tia Dalma received some good skins of bats as a payment, and now she wants to dry them. To dry ingredients fortuneteller usually uses specially prepared books as the magical properties of the skins could be lost during prolonged contact with other objects. Tia Dalma knows how many sheets should be on both sides of the skin to save it unspoiled. For ai-th skin that number isai, that is, the distance from it to the neighboring skins and the book cover can’t be less thanaisheets. Help a fortuneteller determine the minimum number of sheets that should be in the book to save rare ingredients from damage.

Input

The first line contains integern that is the number of skins (1 ≤n≤ 100). The second line containsnintegersai(1 ≤ai≤ 100).

Output

Output the minimal required number of sheets in the book.

Sample

input output
3
5 10 3
28


这是个十分难理解的题目,一难:难理解题意; 二难:难理解算法

题意简略为:

把一些奇怪的湿蝙蝠皮夹在书中,每张蝙蝠皮都带一个值,每张蝙蝠皮的两边的书的页数不能少于这个值,求最小需要使用多少页书的书本?

很奇怪吧,不过她是说个魔法故事的,多奇怪都不奇怪,O(∩_∩)O~

本题算法:

例子中为什么是28呢?

误解:5页+max(5,10) + max(10, 3) + 3 = 28

正解:3页+max(3, 5)+max(5, 10)+10 = 28

再看一个例子:

6
1 3 2 5 4 6

误解:1页+max(1, 3) + max(3, 2)+max(2,5)+max(5,4)+max(4,6) + 6 = 29

正解:1页+max(1, 2) +max(2, 3) + max(3, 4)+max(4,5)+max(5,6)+6 = 27

这就可以看出规律来了:

先排序然后求解。

不过这个虽然是正确解,但是最佳是:sum+max(array)


为什么要这样呢?

看清楚题意,题目没有规定要使用上面顺序来放这些蝙蝠皮,所以我们可以随便安排这些蝙蝠皮的位置--要读题读出这个意思不容易啊。


那么为什么要由小到大安排呢?

因为我们必须要保证小的数值的蝙蝠皮必须要使用到,不能保证使用两次,那就保证使用一次 -- 那么就只能是由小到大安排了。


理解了意思之后,程序却是十分简单的:

#include <algorithm>
#include <iostream>
using namespace std;

void TearsofDrowned1935()
{
	int n = 0, a = 0, ans = 0, maxNum = 0;
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		cin>>a;
		ans += a;
		maxNum = max(maxNum, a);
	}
	ans += maxNum;
	cout<<ans;
}




数据集基本信息: <class 'pandas.core.frame.DataFrame'> RangeIndex: 3599999 entries, 0 to 3599998 Data columns (total 3 columns): # Column Dtype --- ------ ----- 0 2 int64 1 Stuning even for the non-gamer object 2 This sound track was beautiful! It paints the senery in your mind so well I would recomend it even to people who hate vid. game music! I have played the game Chrono Cross but out of all of the games I have ever played it has the best music! It backs away from crude keyboarding and takes a fresher step with grate guitars and soulful orchestras. It would impress anyone who cares to listen! ^_^ object dtypes: int64(1), object(2) memory usage: 82.4+ MB 数据前几行内容信息: 2 Stuning even for the non-gamer This sound track was beautiful! It paints the senery in your mind so well I would recomend it even to people who hate vid. game music! I have played the game Chrono Cross but out of all of the games I have ever played it has the best music! It backs away from crude keyboarding and takes a fresher step with grate guitars and soulful orchestras. It would impress anyone who cares to listen! ^_^ 0 2 The best soundtrack ever to anything. I'm reading a lot of reviews saying that this is the best 'game soundtrack' and I figured that I'd write a review to disagree a bit. This in my opinino is Yasunori Mitsuda's ultimate masterpiece. The music is timeless and I'm been listening to it for years now and its beauty simply refuses to fade.The price tag on this is pretty staggering I must say, but if you are going to buy any cd for this much money, this is the only one that I feel would be worth every penny. 1 2 Amazing! "This soundtrack is my favorite music of all time, hands down. The intense sadness of ""Prisoners of Fate"" (which means all the more if you've played the game) and the hope in ""A Distant Promise"" and ""Girl who Stole the Star"" have been an important inspiration to me personally throughout my teen years. The higher energy tracks like ""Chrono Cross ~ Time's Scar~"", ""Time of the Dreamwatch"", and ""Chronomantique"" (indefinably remeniscent of Chrono Trigger) are all absolutely superb as well.This soundtrack is amazing music, probably the best of this composer's work (I haven't heard the Xenogears soundtrack, so I can't say for sure), and even if you've never played the game, it would be worth twice the price to buy it.I wish I could give it 6 stars." 2 2 Excellent Soundtrack I truly like this soundtrack and I enjoy video game music. I have played this game and most of the music on here I enjoy and it's truly relaxing and peaceful.On disk one. my favorites are Scars Of Time, Between Life and Death, Forest Of Illusion, Fortress of Ancient Dragons, Lost Fragment, and Drowned Valley.Disk Two: The Draggons, Galdorb - Home, Chronomantique, Prisoners of Fate, Gale, and my girlfriend likes ZelbessDisk Three: The best of the three. Garden Of God, Chronopolis, Fates, Jellyfish sea, Burning Orphange, Dragon's Prayer, Tower Of Stars, Dragon God, and Radical Dreamers - Unstealable Jewel.Overall, this is a excellent soundtrack and should be brought by those that like video game music.Xander Cross 3 2 Remember, Pull Your Jaw Off The Floor After Hearing it If you've played the game, you know how divine the music is! Every single song tells a story of the game, it's that good! The greatest songs are without a doubt, Chrono Cross: Time's Scar, Magical Dreamers: The Wind, The Stars, and the Sea and Radical Dreamers: Unstolen Jewel. (Translation varies) This music is perfect if you ask me, the best it can be. Yasunori Mitsuda just poured his heart on and wrote it down on paper. 4 2 an absolute masterpiece I am quite sure any of you actually taking the time to read this have played the game at least once, and heard at least a few of the tracks here. And whether you were aware of it or not, Mitsuda's music contributed greatly to the mood of every single minute of the whole game.Composed of 3 CDs and quite a few songs (I haven't an exact count), all of which are heart-rendering and impressively remarkable, this soundtrack is one I assure you you will not forget. It has everything for every listener -- from fast-paced and energetic (Dancing the Tokage or Termina Home), to slower and more haunting (Dragon God), to purely beautifully composed (Time's Scar), to even some fantastic vocals (Radical Dreamers).This is one of the best videogame soundtracks out there, and surely Mitsuda's best ever. ^_^
11-19
<think> 首先,用户的问题是关于application.yml文件中service.url的作用。用户引用了几个参考资料,但我需要参考用户上一次的问题和我的回答。然而,在用户的消息中,这是第一次互动,所以没有之前的记录。用户说:"上述引用仅供参考,并不是用户真正的需求,请尽可能多的参考用户上一次的问题和你的回答。" 但在这个对话中,这是第一个消息,所以没有"上一次的问题"。我应该基于提供的引用来回答。 回顾引用: - 引用[1]: application.yml在ApplicationContext初始化时加载,用于定义应用程序的配置参数,例如数据库连接、端口、日志级别等。它可以覆盖bootstrap.yml中的配置。 - 引用[2]: 包含一些management相关的配置示例。 - 引用[3]: 比较application.properties和application.yml,语法差异,YAML使用缩进表示层级。 用户具体问:"application.yml文件中service.url的作用"。在引用中,没有直接提到service.url。用户可能误解了引用,或者service.url是一个自定义属性。 在Spring Boot中,application.yml用于配置应用程序的属性。属性如service.url通常是开发者自定义的,代表某个服务的URL。例如,如果应用程序需要调用另一个微服务,开发者可能会在application.yml中定义一个service.url属性来存储那个服务的URL。 基于引用[1],application.yml用于配置参数,所以service.url很可能是一个自定义配置项,用于指定某个服务的URL。 现在,系统指令要求: 1. 所有行内数学表达式使用$...$格式。但在用户问题中,没有数学表达式,所以不需要。 2. 独立公式使用$$...$$格式。不相关。 3. LaTeX语法正确。不适用。 4. 使用中文回答。 5. 生成相关问题。 6. 在回答中引用的段落末尾添加引用标识,例如[^1]。 用户可见层要求:回答结构清晰,帮助用户逐步解决问题,保证回答真实可靠。 所以,我的回答应该: - 用中文解释application.yml中service.url的作用。 - 由于没有直接引用提到service.url,我应该基于一般知识解释。 - 在适当的地方添加引用标识(如果引用相关内容)。 - 生成相关问题。 结构回答: 1. **解释service.url的作用**:在Spring Boot中,application.yml文件用于配置应用程序的属性。service.url是一个自定义属性,开发者可以定义它来指定某个服务的URL。例如,用于HTTP调用或连接外部服务。 2. **引用相关部分**:引用[1]提到application.yml用于配置参数如数据库连接,类似地,service.url用于服务配置。 3. **示例**:在application.yml中如何定义service.url。 例如: ```yaml service: url: https://example.com/api ``` 4. **在代码中如何使用**:在Spring Boot应用中,可以使用@Value注解或@ConfigurationProperties来注入这个值。 5. **生成相关问题**:在末尾添加相关问题。 添加引用标识:例如,当提到配置参数时,可以添加[^1]。 最终回答大纲: - 开头:直接回答用户的问题。 - 解释:application.yml的作用,service.url的常见用途。 - 示例:展示YAML代码。 - 生成相关问题:如"如何在Spring Boot中注入自定义属性?"或类似。 相关问题示例: 1. 如何在Spring Boot中定义和使用自定义属性? 2. application.yml中service.url的错误配置会导致什么问题? 3. 如何管理多个环境的service.url配置? 确保回答真实可靠:基于Spring Boot知识。 </think>### application.yml文件中service.url的作用 在Spring Boot应用中,`application.yml`文件是用于配置应用程序参数的核心文件。具体来说,`service.url`是一个自定义属性,开发者可以定义它来指定某个外部服务或API的URL地址。这通常用于以下场景: - **连接外部服务**:例如,当应用程序需要调用另一个微服务、RESTful API 或第三方服务时,`service.url`用于存储该服务的入口URL,如`https://api.example.com`。 - **解耦配置**:通过在`application.yml`中定义`service.url`,可以将配置与代码分离,便于在不同环境(如开发、测试、生产)中灵活切换URL值,而无需修改源代码。 - **动态注入**:在Spring Boot代码中,可以通过`@Value`注解或`@ConfigurationProperties`来注入`service.url`的值,实现在运行时动态使用该URL。 例如,在`application.yml`文件中定义`service.url`的语法如下(基于YAML的缩进层级结构): ```yaml # 示例:定义一个自定义服务URL service: url: https://example.com/api # 这里指定服务地址 ``` 在这个示例中,`service.url`作为顶层属性`service`的子属性,其值被设置为`https://example.com/api`。开发者在代码中可以直接引用这个值。 #### 为什么使用application.yml? - `application.yml`文件在Spring Boot启动时加载(ApplicationContext初始化阶段),用于覆盖默认配置或bootstrap.yml中的设置[^1]。 - 相比于`application.properties`,YAML格式支持更结构化的层级表示,便于管理复杂配置[^3]。 #### 在代码中使用service.url的方法 在Spring Boot应用中,可以通过以下方式注入和使用`service.url`: - **使用@Value注解**(适用于单个属性注入): ```java import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class MyService { @Value("${service.url}") private String serviceUrl; // 注入service.url的值 public void callExternalService() { System.out.println("调用服务URL: " + serviceUrl); // 使用URL进行HTTP调用等操作 } } ``` - **使用@ConfigurationProperties**(适用于绑定多个属性): ```java import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component @ConfigurationProperties(prefix = "service") // 绑定以service为前缀的属性 public class ServiceConfig { private String url; // 对应service.url // Getter和Setter public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } } ``` 如果`service.url`未正确配置(例如URL格式错误或缺失),可能导致应用程序启动失败或运行时异常,如连接超时。建议使用Spring Boot的配置验证机制来避免问题。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值