Ural 2069 Hard Rock
来源:互联网 发布:java软件工程师就业班 编辑:程序博客网 时间:2024/06/06 03:31
Description
Ilya is a frontman of the most famous rock band on Earth. Band decided to make the most awesome music video ever for their new single. In that music video Ilya will go through Manhattan standing on the top of a huge truck and playing amazing guitar solos. And during this show residents of the island will join in singing and shaking their heads. However, there is a problem. People on some streets hate rock.
Recall that Manhattan consists of n vertical and m horizontal streets which form the grid of (n − 1)×(m− 1) squares. Band’s producer conducted a research and realized two things. First, band’s popularity is constant on each street. Second, a popularity can be denoted as an integer from 1 to
So, a route goes from the upper left corner to the bottom right corner. Let us define the route coolness as the minimal popularity over all streets in which rockers passed non-zero distance. As you have probably guessed, the musicians want to find the route with the maximal coolness. If you help them then Ilya will even give you his autograph!
Input
In the first line there are integers n and m (
In the following n lines there are popularity values (one value on each line) on vertical streets in the order from left to right.
In the following m lines there are popularity values (one value on each line) on horizontal streets in the order from top to bottom.
It is guaranteed that all popularity values are integers from 1 to
Output
Output a single integer which is a maximal possible route coolness.
题意
问有纵向 n 条路,横向 m 条路,且彼此交叉,从左到右依次给出 n 条纵向路的权值,从上到下依次给出 m 条横向路的权值,问如何从左上点经过若干条横纵路到达右下点,使得进过道路的最小权值最大。
分析
此题重点在于思维,由于从左上到右下,则必然纵向 1 号路与 n 号路,横向 1 号路与 m 号路均必有至少两条被走到。
同时,可以想到,走到道路越少,则使得最终权值变小的可能越少。故组合情况共四种:
- 纵向 1 号路 - 横向 m 号路
- 纵向 1 号路 - 横向 x 号路 - 纵向 n 号路
- 横向 1 号路 - 纵向 n 号路
- 横向 1 号路 - 纵向 y 号路 - 横向 m 号路
此处要求的 x 为横向路中除 1, m 路外权值最大的路,y 为纵向路中除 1, n 路外权值最大的路
代码
#include<bits/stdc++.h>using namespace std;const int inf = 1e9 + 7;int col[100010], row[100010];int main(){ for(int n,m;scanf("%d %d",&n,&m)!=EOF;) { for(int i=1;i<=n;i++) scanf("%d",&col[i]); for(int j=1;j<=m;j++) scanf("%d",&row[j]); sort(col+2, col+n); sort(row+2, row+m); int ans = 0; int t1 = min(col[1], row[m]); int t2 = min(col[1], min(row[m-1], col[n])); int t3 = min(row[1], col[n]); int t4 = min(row[1], min(col[n-1], row[m])); ans = max(ans, t1); ans = max(ans, t2); ans = max(ans, t3); ans = max(ans, t4); printf("%d\n",ans); }}
- ural 2069 Hard Rock
- Ural 2069 Hard Rock
- Ural 2069 Hard Rock
- URAL 2069 Hard Rock(思路)
- URAL 2069. Hard Rock (分类讨论)
- URAL 1254 Die Hard (SPFA)
- hard
- [rock]冷血动物
- Rock myself
- ROCK介绍
- ROCK算法
- Post-rock
- URAL
- 【ural】
- URAL
- URAL
- URAL
- URAL
- mp4文件播放不了
- mybatisgeneratormodel-mybatis逆向工程
- table中th内容水平垂直居中
- LeetCode 24. Swap Nodes in Pairs
- JAVA--HashCode 基础(判断对象是否相等)
- Ural 2069 Hard Rock
- Android TextSwitcher 文本切换器
- Qt使用QStackedWidget实现堆栈窗口
- UNIX高级编程-高级I/O
- 主分区 逻辑分区
- [数据表设计] - 商品模型数据架构图
- Java集合框架总结
- [yii2] -- [ActiveForm] -- ActiveForm的使用方法
- 可变参数