Codeforces Round #325 (Div. 2) B
1 second
256 megabytes
standard input
standard output
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 itexactly 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.
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).
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.
4
1 2 3
3 2 1
3 2 2 3
12
3
1 2
3 3
2 1 3
11
2
1
1
1 1
4
The first sample is shown on the figure above.
In the second sample, Laurenty's path can look as follows:
- Laurenty crosses the avenue, the waiting time is 3;
- Laurenty uses the second crossing in the first row, the waiting time is 2;
- Laurenty uses the first crossing in the first row, the waiting time is 1;
- Laurenty uses the first crossing in the first row, the waiting time is 1;
- Laurenty crosses the avenue, the waiting time is 1;
- Laurenty uses the second crossing in the second row, the waiting time is 3.
In total we get that the answer equals 11.
In the last sample Laurenty visits all the crossings, so the answer is 4.
题意: 两行n列建筑物 对应的有 (n-1) *2个东 西建筑物的过马路的等待时间 n个南北建筑的过马路的等待时间 问从左上角到右下角往返的最短时间
往返的轨迹不能相同 只能通过南北路口一次
, so the boy wants to cross itexactly once on the way to the store and exactly once on the way back home.
题解: n只有50 并且 南北路口只能通过一次 枚举出50种情况 排序后 因为往返轨迹不能相同 输出 ans[1]+ans[2];'
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n;
int a[];
int b[];
int c[];
int ans[];
int main()
{
memset(ans,,sizeof(ans));
scanf("%d",&n);
for(int i=;i<=n-;i++)
scanf("%d",&a[i]);
for(int i=;i<=n-;i++)
scanf("%d",&b[i]);
for(int j=;j<=n;j++)
scanf("%d",&c[j]);
for(int i=;i<=n-;i++)
{
for(int k=;k<=i;k++)
ans[i+]=ans[i+]+a[k];
for(int k=i+;k<=n-;k++)
ans[i+]=ans[i+]+b[k];
ans[i+]+=c[i+];
}
sort(ans+,ans+n+);
printf("%d\n",ans[]+ans[]);
return ;
}
Codeforces Round #325 (Div. 2) B的更多相关文章
- Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid
F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #325 (Div. 2) D. Phillip and Trains BFS
D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/ ...
- Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力
C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...
- Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题
A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...
- 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/p ...
- Codeforces Round #325 (Div. 2) Phillip and Trains dp
原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...
- Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟
原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...
- Codeforces Round #325 (Div. 2) Alena's Schedule 模拟
原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...
- Codeforces Round #325 (Div. 2) D bfs
D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning
折半搜索,先搜索一半的数字,记录第一个人的值,第二个人.第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案. 代码 #include<cstdio> ...
随机推荐
- 获取点击li的当前索引
获取点击li的当前索引 点击特定次序的li 展现特定的页面 $('.wgsb').find('.wangge_data_list li').click(function(){ var index=$ ...
- 关于IT人的一些消遣区
https://www.csdn.net/http://www.51cto.com/http://bestcbooks.com/http://www.jobbole.com/http://www.co ...
- python -- sftp的方式下载终端文件
可以通过paramiko模块进行远程连接,然后指定文件夹,进行下载. sf = paramiko.Transport((host, port) #创建链接对象,需要终端ip以及sftp使用的端口号 ...
- Python必学:使用哪款文本编辑器更好?
Python的交互式命令行写程序,好处是一下就能得到结果,坏处是没法保存,下次还想运行的时候,还得再敲一遍. 所以,实际开发的时候,我们总是使用一个文本编辑器来写代码,写完了,保存为一个文件,这样,程 ...
- 搭建一个简单的dns缓存服务器
环境:linux 软件:bind97,bind97-utils, bind97-libs ip:192.168.192.130:192.168.192.131 -------------------- ...
- Codeforces146D 概率DP
Bag of mice The dragon and the princess are arguing about what to do on the New Year's Eve. The drag ...
- POJ:2431-Expedition
Expedition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20089 Accepted: 5786 Descripti ...
- 适配IE8+等浏览器的适配播放插件
function myBrowser(){ var userAgent = navigator.userAgent; //ȡ���������userAgent�ַ� var isOpera = us ...
- Android 中运行时权限获取联系人信息 Demo
代码比较简单... AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <m ...
- 2037: [Sdoi2008]Sue的小球
2037: [Sdoi2008]Sue的小球 链接 题解 论文 代码 #include<cstdio> #include<algorithm> #include<cstr ...