Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前綴和

B. Laurenty and Shop

Time Limit: 1 Sec ?

Memory Limit: 256 MB

題目連接

http://codeforces.com/contest/586/problem/B

Description

A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.

The town where Laurenty lives in is not large. The houses in it are located in two rows, n houses in each row. Laurenty lives in the very last house of the second row. The only shop in town is placed in the first house of the first row.

The first and second rows are separated with the main avenue of the city. The adjacent houses of one row are separated by streets.

Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and cross the street. Different traffic lights can have different waiting time.

The traffic light on the crosswalk from the j-th house of the i-th row to the (j?+?1)-th house of the same row has waiting time equal to aij (1?≤?i?≤?2,?1?≤?j?≤?n?-?1). For the traffic light on the crossing from the j-th house of one row to the j-th house of another row the waiting time equals bj (1?≤?j?≤?n). The city doesn't have any other crossings.

The boy wants to get to the store, buy the products and go back. The main avenue of the city is wide enough, so the boy wants to cross it exactly once on the way to the store and exactly once on the way back home. The boy would get bored if he had to walk the same way again, so he wants the way home to be different from the way to the store in at least one crossing.

Figure to the first sample.

Help Laurenty determine the minimum total time he needs to wait at the crossroads.

Input

The first line of the input contains integer n (2?≤?n?≤?50) — the number of houses in each row.

Each of the next two lines contains n?-?1 space-separated integer — values aij (1?≤?aij?≤?100).

The last line contains n space-separated integers bj (1?≤?bj?≤?100).

?i??,C?i??,即此題的初始分值、每分鐘減少的分值、dxy做這道題需要花費的時間。

Output

Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home.

Sample Input

4
1 2 3
3 2 1
3 2 2 3

Sample Output

12

HINT

?

題意

給你兩行房子,你得從第一行第一個走到第二行最后一個,并從第二行最后一個再走回去

每條路都有權值,并且你走過去和走回來的路線要求不一樣,問你最小的花費是多少

題解:

首先統計前綴和之后,再暴力枚舉中間走的過道是哪些就好了

代碼:

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<iostream>
using namespace std;long long a[501];
long long b[501];
long long c[501];
long long suma[501];
long long sumb[501];
int main()
{int n;scanf("%d",&n);for(int i=1;i<n;i++){scanf("%d",&a[i]);suma[i]=a[i]+suma[i-1];}for(int i=1;i<n;i++){scanf("%d",&b[i]);sumb[i]=b[i]+sumb[i-1];}for(int i=1;i<=n;i++)scanf("%d",&c[i]);long long ans = -1;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(i==j)continue;if(ans == -1)ans = (suma[i-1]+sumb[n-1]-sumb[i-1]+c[i])+(suma[j-1]+sumb[n-1]-sumb[j-1]+c[j]);elseans = min(ans,(suma[i-1]+sumb[n-1]-sumb[i-1]+c[i])+(suma[j-1]+sumb[n-1]-sumb[j-1]+c[j]));}}cout<<ans<<endl;
}

?

轉載于:https://www.cnblogs.com/qscqesze/p/4873890.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/397422.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/397422.shtml
英文地址,請注明出處:http://en.pswp.cn/news/397422.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

python學習感悟第3節

在繼列表的學習之后&#xff0c;進行了元組的學習。元組和列表功能相似&#xff0c;只是元組不能進行修改&#xff0c;所以元組又叫只讀列表。 下面列舉的是一系列的字符串操作&#xff1a; name.capitalize() #首字母大寫 name.count("a") #數列表中有幾個a name…

MyBatis_ibatis和mybatis的區別【轉】

1. ibatis3.*版本以后正式改名為mybaits&#xff0c;它也從apache轉到了google code下&#xff1b;也就是說ibatis2.*&#xff0c;mybatis3.*。2. 映射文件的不同ibatis的配置文件如下<?xml version"1.0" encoding"UTF-8" ?><!DOCTYPE sqlMapCo…

android gallery自動播放,可循環顯示圖像的Android Gallery組件

類型&#xff1a;源碼相關大小&#xff1a;23.6M語言&#xff1a;中文 評分&#xff1a;9.1標簽&#xff1a;立即下載第 4 頁 實現循環顯示圖像的Gallery組件實現循環顯示圖像的Gallery組件在本節將組出與循環顯示圖像相關的ImageAdapter類的完整代碼。讀者可以從中看到上一節介…

docker內程序如何讀取dockerfile和compose.yml中設置的環境變量

docker內程序如何讀取dockerfile和compose.yml中設置的環境變量 背景 compose文件中配置了服務A和服務B&#xff0c;其中B服務調用了A服務的接口&#xff0c;那么B的實現代碼中該如何調用A的服務呢&#xff1f; 解決 compose文件中&#xff0c;服務B的配置加入A的接口&#xff…

2015年10月13日

關于掙錢&#xff0c;我覺得&#xff0c;只要興趣所在&#xff0c;能把事做好&#xff0c;錢自己就會來。收入上不去&#xff0c;往往是做的事情就不在高收入的那個區間&#xff0c;寫程序很難出富翁。說實話&#xff0c;外圍一天的消費可能就是你工資的好幾倍&#xff0c;不用…

Spring Boot Servlet

上一篇我們對如何創建Controller 來響應JSON 以及如何顯示數據到頁面中&#xff0c;已經有了初步的了解。 Web開發使用 Controller 基本上可以完成大部分需求&#xff0c;但是我們還可能會用到 Servlet、Filter、Listener、Interceptor 等等。 當使用spring-Boot時&#xff0c;…

基于相關性分析系統性能瓶頸

測試的過程中&#xff0c;難免需要會遇到一些性能瓶頸&#xff0c;那么就要求我們能夠分析出性能瓶頸&#xff0c;并給出解決方案。性能瓶頸很抽象&#xff0c;我們可以通過數據使其具象。以我工作內容為例&#xff0c;服務器處理數據的能力是有限的&#xff0c;那么其處理的邊…

curl網站開發指南

curl網站開發指南 作者&#xff1a; 阮一峰 日期&#xff1a; 2011年9月 4日 我一向以為&#xff0c;curl只是一個編程用的函數庫。 最近才發現&#xff0c;這個命令本身&#xff0c;就是一個無比有用的網站開發工具&#xff0c;請看我整理的它的用法。 curl網站開發指南 阮一…

android格式化時間中文版,Android 仿微信聊天時間格式化顯示功能

本文給大家分享android仿微信聊天時間格式化顯示功能。在同一年的顯示規則&#xff1a;如果是當天顯示格式為 HH:mm 例&#xff1a;14:45如果是昨天,顯示格式為 昨天 HH:mm 例&#xff1a;昨天 13:12如果是在同一周 顯示格式為 周一 HH:mm 例&#xff1a;周一14:05如果不是同一…

java分享第十七天-01(封裝操作xml類)

做自動化測試的人&#xff0c;都應該對XPATH很熟悉了&#xff0c;但是在用JAVA解析XML時&#xff0c;我們通常是一層層的遍歷進去&#xff0c;這樣的代碼的局限性很大&#xff0c;也不方便&#xff0c;于是我們結合一下XPATH&#xff0c;來解決這個問題。所需要的JAR包&#xf…

Ubuntu12.04 內核樹建立

先查看自己使用的內核版本 linlin-virtual-machine:~$ uname -r 3.2.0-23-generic 如果安裝系統時&#xff0c;自動安裝了源碼。在 /usr/src 目錄下有對應的使用的版本目錄。 linlin-virtual-machine:~$ cd /usr/src linlin-virtual-machine:/usr/src$ ls linux-headers-3.2.0…

【mysql】Innodb三大特性之double write

1、doublewrite buffer&#xff08;mysql官方的介紹&#xff09; InnoDB uses a novel file flush technique called doublewrite. Before writing pages to the data files, InnoDB first writes them to a contiguous area called the doublewrite buffer. Only after the wr…

android crop 大圖,com.android.camera.action.CROP 實現圖片剪裁

APP 中選取圖片之后&#xff0c;有時候需要進行剪裁&#xff0c;比如頭像。以下是啟動代碼。在我的項目中&#xff0c;傳的是 filePath&#xff0c;所以我轉了一下&#xff0c;但實際上從相冊選擇圖片后&#xff0c;用 data.getData() 就可獲得 uri。Uri uri Uri.fromFile(new…

Who Gets the Most Candies? POJ - 2886 (線段樹)

按順時針給出n個小孩&#xff0c;n個小孩每個人都有一個紙&#xff0c;然后每個人都有一個val&#xff0c;這個val等于自己的因子數&#xff0c;如果這個val是正的&#xff0c;那就順時針的第val個孩子出去&#xff0c;如果是負的話&#xff0c;就逆時針的第val個孩子出去&…

javax.validation.ValidationException: Unable to find a default provider

2019獨角獸企業重金招聘Python工程師標準>>> [ERROR] [2016-11-16 13:58:21 602] [main] (FrameworkServlet.java:457) Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name org.springframewo…

第十章練習題----2

package com.Hanqi2;public class xitizhuhanshu {public static void main(String[] args) {// TODO Auto-generated method stubxiti tm new xiti("黑色","15寸");xitizhs tm3 new xitizhs("藍色","15寸");tm.Call("654"…

關于微信“被返回頁”在被返回時自動刷新

網上有很多這些文章&#xff0c;但我覺得沒一篇真正解決這個問題&#xff0c;倒是能給人一個解決方案的思路&#xff0c;對&#xff0c;就是posState事件。 要解決這個問題也不難&#xff0c;使用history的replaceState屬性替換當前網頁鏈接&#xff08;其實作用是在不增加hist…

android視頻播放器api,03.視頻播放器Api說明

03.視頻播放器Api說明目錄介紹01.最簡單的播放02.如何切換視頻內核03.切換視頻模式04.切換視頻清晰度05.視頻播放監聽06.列表中播放處理07.懸浮窗口播放08.其他重要功能Api09.播放多個視頻10.VideoPlayer相關Api11.Controller相關Api12.邊播放邊緩存api13.類似抖音視頻預加載14…

使用Python重命名MP3標簽

從Window復制MP3文件的到Ubuntu下&#xff0c;MP3標簽很多是亂碼。于是想自己寫個Python程序處理一下。 從酷狗復制過來的音樂文件名都是“作者 - 標題”&#xff0c;所以可以通過解析文件名直接獲取作者和標題信息。 需要下載eyeD3模塊 $ sudo apt-get install python-eyed3 代…

Taurus.MVC 2.0 開源發布:WebAPI開發教程

背景&#xff1a; 有用戶反映&#xff0c;Tausus.MVC 能寫WebAPI么&#xff1f; 能&#xff01; 教程呢&#xff1f; 嗯&#xff0c;木有&#xff01; 好吧&#xff0c;剛好2.0出來&#xff0c;就帶上WEBAPI教程了&#xff01; 開源地址&#xff1a; https://github.com/cyq116…