G - Hard Rock URAL - 2069 ----思维题

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 10  9. For example, if rockers go along the street with popularity equal to 10  9 then people will greet them with a hail of applause, fireworks, laser show and boxes with... let it be an orange juice. On the other hand, if rockers go along the street with popularity equal to 1 then people will throw rotten tomatoes and eggs to the musicians. And this will not help to make the most awesome music video!
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 (2 ≤  nm ≤ 10  5), separated by space. These are the numbers of vertical and horizontal streets, respectively.
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 10  9.
Output
Output a single integer which is a maximal possible route coolness.
Example
input output
2 3
4
8
2
7
3
4
4 3
12
4
12
3
21
5
16
12

Notes

Explanation of the first sample (the "coolest" route is highlighted):
Problem illustration

题目链接:https://cn.vjudge.net/contest/160744#problem/G


题目的意思就是给你一个网格,网格的每一条横线或者竖线权值相同,求从左上走到右下的路线中最小值最大的权值。

一开始理解错题意了,UMR还以为我理解了。。卡了我半小时,懂了题意很容易就出了,我们找到横着和竖着的最大边,我们考虑四种情况,横:1对于每一个点可以直接向下走,2先横着走再向下走,竖着一样,四个边界单独跑。

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=100010;
int a[maxn];
int b[maxn];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    int max1=-inf,max2=-inf;
    for(int i=1;i<n-1;i++){
        max2=max(max2,a[i]);
    }
    for(int i=1;i<m-1;i++){
        max1=max(max1,b[i]);
    }
    int ans=-1;
    ans=max(ans,min(a[0],b[m-1]));
    ans=max(ans,min(b[0],a[n-1]));
    ans=max(ans,min(min(max2,b[m-1]),b[0]));
    ans=max(ans,min(min(max1,a[n-1]),a[0]));
    cout<<ans<<endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值