CF 586B 起点到终点的最短路和次短路之和
2024-08-30 10:41:46
起点是右下角 终点是左上角
每次数据都是两行的点 输入n 表示有n列
接下来来的2行是 列与列之间的距离
最后一行是 行之间的距离
枚举就行
Sample test(s)
input
4
1 2 3
3 2 1
3 2 2 3
output
12
input
3
1 2
3 3
2 1 3
output
11
input
2
1
1
1 1
output
4
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ; const int INF = 0x3f3f3f3f ; int a[][] ;
int b[] ; int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
int i , j ;
int sum = ;
for (i = ; i < ; i++)
for (j = ; j < n- ; j++)
scanf("%d" , &a[i][j]) ;
for (i = ; i < n ; i++)
scanf("%d" , &b[i]) ;
int ans[] = {INF , INF , INF} ;
for (i = ; i < n- ; i++)
{
sum += a[][i] ;
}
sum += b[] ;
ans[] = sum ;
sort(ans , ans+) ;
for (i = ; i < n- ; i++)
{
sum = sum - a[][i] + a[][i] ;
sum = sum - b[i] + b[i+] ;
ans[] = sum ;
sort(ans , ans+) ;
}
printf("%d\n" , ans[] + ans[]) ; }
return ;
}
最新文章
- CentOS 6.3下 安装 Mono 3.2 和Jexus 5.4
- LinkedList源码阅读笔记(基于JDK1.8)
- 第 20 章 CSS3 前缀和 rem
- [转]设置Android手机以使用ARM Streamline进行性能分析(二)
- 一个简单的3DTouch、Peek和Pop手势Demo,附github地址
- Web应用程序系统的多用户权限控制设计及实现-用户模块【7】
- [部署]CentOS yum源
- codevs 1133 表达式的值
- 鸟哥的linux私房菜学习记录之程序管理和SElinux初探
- Javascript 数组之判断取值和数组取值
- openstack(liberty):部署实验平台(二,简单版本软件安装 part2)
- TFS客户端登录用户修改
- js 基于函数伪造的方式实现继承
- 绝对URL和相对URL
- 数据结构(RMQ):UVAoj 11235 Frequent values
- selenium 学习笔记 ---新手学习记录(3) 问题总结(java)
- 【Machine Learning】Mahout基于协同过滤(CF)的用户推荐
- kvm学习小计
- java列表数据基本操作
- Linux Apache配置https访问