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> ...
随机推荐
- django+xadmin在线教育平台(七)
4-3 新建项目 Python2.7 创建虚拟环境. mkvirtualenv mxonline2 安装django pip install django==1.9.8 注意Python2下此处必须用 ...
- P1338 末日的传说 逆序数对
题目描述 只要是参加jsoi活动的同学一定都听说过Hanoi塔的传说:三根柱子上的金片每天被移动一次,当所有的金片都被移完之后,世界末日也就随之降临了. 在古老东方的幻想乡,人们都采用一种奇特的方式记 ...
- 初见akka-01
最近在学习akka,在看rpc相关的东西,有点脑子疼,哈哈 1.需求: 目前大多数分布式架构底层通信是通过RPC实现的,RPC框架非常多, 比如我们学过的Hadoop项目的RPC通信框架,但是Hado ...
- 基于HDP版本的YDB安装部署(转)
第三章 YDB依赖环境准备 一.硬件环境 硬件如何搭配,能做到比较高的性价比,不存在短板.合理的硬件搭配,对系统的稳定性也很关键. 1.CPU不是核数越高越好,性价比才是关键. 经常遇到很多的企业级客 ...
- .Net Mvc 4 Route路由
1.前言 在创建一个MVC项目后就可以,在App_Start文件下的RouteConfig.cs里面就可以定义我们的路由规则,其中已经有默认的路由规则了,routes.IgnoreRoute是让路由规 ...
- 3714: [PA2014]Kuglarz
3714: [PA2014]Kuglarz 链接 思路: 好题.对于每个点都需要确定它的值,那么一个点可以直接询问[i,i]来确定,或者已经知道了[i,j]和[i+1,j]推出来. 但是可能产生冲突, ...
- Android 支付宝H5 没有回调
今天测试反馈问题,说,手机上没有安装支付宝的,调用支付宝支付之后,没有回调.不提示成功也不提示失败. 我自己试了半天也都是没有问题 .后来终于可以试出来了. 发现原来是,清单里面注册的Activity ...
- Java 基本数据类型总结一
Java基本数据类型总结一 基本类型,或者叫做内置类型,是JAVA中不同于类的特殊类型.它们是我们编程中使用最频繁的类型.java是一种强类型语言,第一次申明变量必须说明数据类型,第一次变量赋值称为变 ...
- web开发学习之路是否有尽头
Linux/Git/Pip/Npm/Composer Apache/Ngnix Mysql/MongoDb/Redis PHP/Python/NodeJS javascript/jQuery/Expr ...
- 18、bootStap JavaScript插件
1.模态框 <!--模态框经过了优化,更加灵活,以弹出对话框的形式出现,具有最小和最实用的功能集.--> <button type="button" class= ...