题意:给定 n + m 个街道,问你从左上角走到右下角的所有路的权值最小的中的最大的。

析:我们只要考虑几种情况就好了,先走行再走列和先走列再走行差不多。要么是先横着,再竖着,要么是先横再竖再横,要么是先横再竖再横再竖,全考虑一下就好了。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define frer freopen("in.txt", "r", stdin)
#define frew freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const char *mark = "+-*";
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int row[maxn], col[maxn]; int solve(int *a, int r, int *b, int c){
int ans1 = min(a[0], b[c]);
int ans2 = min(a[0], a[r]);
int cnt = 0;
for(int i = 0; i <= c; ++i)
cnt = max(cnt, b[i]);
ans2 = min(ans2, cnt);
int ans3 = min(a[0], b[c]);
int rr = 0;
for(int i = 0; i <= r; ++i)
rr = max(rr, a[i]);
ans2 = min(ans2, min(cnt, rr));
return max(ans1, max(ans2, ans3));
} int main(){
while(scanf("%d %d", &m, &n) == 2){
for(int i = 0; i < m; ++i)
scanf("%d", &col[i]);
for(int j = 0; j < n; ++j)
scanf("%d", &row[j]);
int ans = solve(row, n-1, col, m-1);
ans = max(ans, solve(col, m-1, row, n-1));
printf("%d\n", ans);
}
return 0;
}

  

URAL 2069 Hard Rock (最短路)的更多相关文章

  1. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  2. 【找规律】URAL - 2069 - Hard Rock

    题解及证明:http://www.cnblogs.com/StupidBoy/p/5241258.html #include<cstdio> #include<algorithm&g ...

  3. URAL 1085 Meeting(最短路)

    Meeting Time limit: 2.0 secondMemory limit: 64 MB K friends has decided to meet in order to celebrat ...

  4. URAL 1934 Black Spot(最短路)

    Black Spot Time limit: 1.0 secondMemory limit: 64 MB Bootstrap: Jones's terrible leviathan will find ...

  5. BZOJ.2069.[POI2004]ZAW(最短路Dijkstra 按位划分)

    题目链接 \(Description\) 给定一张带权图(边是双向的,但不同方向长度不同).求从1出发,至少经过除1外的一个点,再回到1的最短路.点和边不能重复经过. \(n\leq5000,m\le ...

  6. Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)

    1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...

  7. bzoj 2069 [ POI 2004 ] ZAW —— 多起点最短路 + 二进制划分

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2069 首先,对于和 1 相连的点,一定是从某个点出发,回到另一个点: 所以需要枚举起点和终点 ...

  8. DP/最短路 URAL 1741 Communication Fiend

    题目传送门 /* 题意:程序从1到n版本升级,正版+正版->正版,正版+盗版->盗版,盗版+盗版->盗版 正版+破解版->正版,盗版+破解版->盗版 DP:每种情况考虑一 ...

  9. URAL 1002 Phone Numbers(KMP+最短路orDP)

    In the present world you frequently meet a lot of call numbers and they are going to be longer and l ...

随机推荐

  1. 代码开光,Orz

    有一次在cf上看到了,666,- - // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/ ...

  2. 对比C++中的指针和引用

    指针和引用在形式上比较好区分,由于有很多相似的功能,因此在使用上容易混淆.因此有必要对指针和引用进行对比,以便于在使用时使程序正确高效. 1.引用不可以为空,而指针可以为空. 我们知道引用是对象的别名 ...

  3. Python内置数据类型之Dictionary篇

    1.查看函数XXX的doc string. Python的函数是有属性的,doc string便是函数的属性.所以查看函数XXX的属性的方法是模块名.XXX.__doc__ 2.模块的属性 每个模块都 ...

  4. 【C#学习笔记】改变字体

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. Hive 中函数总结

    Hive supports three types of conditional functions. These functions are listed below: IF( Test Condi ...

  6. unable to load default svn client

    解决方法: .windows->preferences->Team->SVN->SVN接口  选择SVNKit...

  7. myeclipse10添加jQuery自动提示

    首先先要在装上spket插件,这个网上有好多教程,我就不详细说了,主要说一下后面的设置,因为我发现我按照网上的装完也设置完没办法使用自动提示功能,以下是我根据前辈的经验然后自己摸索出来的: 选中所建的 ...

  8. Python在centos下的安装

    1.wget http://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz默认下载到主目录下 2.tar xzf Python-2.6.6.tgz 3 ...

  9. 【LeetCode】217 & 219 - Contains Duplicate & Contains Duplicate II

     217 - Contains Duplicate Given an array of integers, find if the array contains any duplicates. You ...

  10. java基础语法知识

    1.用消息框显示加法计算结果 package plusdialog; import javax.swing.JOptionPane;  // import class JOptionPane publ ...