URAL 2069. Hard Rock (分类讨论)
2016-08-22 20:21
465 查看
传送门:题目传送门
大体题意:
告诉你一个m*n 的矩形,矩形的每一条边都有一个权值,求得从左上角走到右下角最下权值的最大值!
思路:
比赛没有做出来,样例完全没弄懂,= =
明白了题意还是很简单的!
既然每条边的权值都是一样的,那么从左上角走到右下角的方式就可以分为四种!
走到终点可以有两种方式,竖着走下去,和横着走下去!
关于横着走下去又可以分为两种:
1.先走第一条竖边,在走最后一条横边!
2. 走第一条横边一段距离,然后走中间的某一条竖边,在走最后一条横边!
关于竖着类似!讨论就行 就那么四种!
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;
const int inf = 0x3f3f3f3f;
int a[maxn],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 hormax = -inf;
int vermax = -inf;
for (int i = 1; i < n-1; ++i) vermax = max(vermax,a[i]);
for (int i = 1; i < m-1; ++i) hormax = max(hormax,b[i]);
int ans = -1;
ans = max(ans,min(a[0],b[m-1]));
ans = max(ans,min(min(vermax,b[m-1]),b[0]));
ans = max(ans,min(b[0],a[n-1]));
ans = max(ans,min(min(a[0],hormax),a[n-1]));
printf("%d\n",ans);
return 0;
}
Time limit: 1.0 second
Memory limit: 64 MB
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 109. For example, if rockers go along the street with popularity
equal to 109 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!
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 109.
Problem Author: Oleg Merkurev (prepared by Alexander Borzunov)
Problem Source: Ural Regional School Programming Contest 2015
Tags: none (
hide tags for unsolved problems
)
Difficulty: 152 Printable version Submit
solution Discussion (5)
All submissions (1352) All
accepted submissions (604) Solutions rating (419)
大体题意:
告诉你一个m*n 的矩形,矩形的每一条边都有一个权值,求得从左上角走到右下角最下权值的最大值!
思路:
比赛没有做出来,样例完全没弄懂,= =
明白了题意还是很简单的!
既然每条边的权值都是一样的,那么从左上角走到右下角的方式就可以分为四种!
走到终点可以有两种方式,竖着走下去,和横着走下去!
关于横着走下去又可以分为两种:
1.先走第一条竖边,在走最后一条横边!
2. 走第一条横边一段距离,然后走中间的某一条竖边,在走最后一条横边!
关于竖着类似!讨论就行 就那么四种!
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;
const int inf = 0x3f3f3f3f;
int a[maxn],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 hormax = -inf;
int vermax = -inf;
for (int i = 1; i < n-1; ++i) vermax = max(vermax,a[i]);
for (int i = 1; i < m-1; ++i) hormax = max(hormax,b[i]);
int ans = -1;
ans = max(ans,min(a[0],b[m-1]));
ans = max(ans,min(min(vermax,b[m-1]),b[0]));
ans = max(ans,min(b[0],a[n-1]));
ans = max(ans,min(min(a[0],hormax),a[n-1]));
printf("%d\n",ans);
return 0;
}
2069. Hard Rock
Time limit: 1.0 secondMemory limit: 64 MB
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 109. For example, if rockers go along the street with popularity
equal to 109 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 ≤ n, m ≤ 105), separated by space. Theseare 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 109.
Output
Output a single integer which is a maximal possible route coolness.Samples
input | output |
---|---|
2 3 4 8 2 7 3 | 4 |
4 3 | 12 |
Notes
Explanation of the first sample (the "coolest" route is highlighted):Problem Author: Oleg Merkurev (prepared by Alexander Borzunov)
Problem Source: Ural Regional School Programming Contest 2015
Tags: none (
hide tags for unsolved problems
)
Difficulty: 152 Printable version Submit
solution Discussion (5)
All submissions (1352) All
accepted submissions (604) Solutions rating (419)
相关文章推荐
- URAL 2069 Hard Rock(思路)
- ural 2069. Hard Rock
- ural 2069 Hard Rock
- Ural 2069 Hard Rock
- URAL 1557 Network Attack 图论,连通性,tarjain,dfs建树,分类讨论 难度:2
- Ural 2069 Hard Rock
- G - Hard Rock URAL - 2069 ----思维题
- 【找规律】URAL - 2069 - Hard Rock
- URAL 2069 Hard Rock (最短路)
- 【HDU】5957 Query on a graph【分类讨论+bfs序线段树】
- ZOJ - 3993 - Safest Buildings(概率,分类讨论)
- CodeM美团点评编程大赛初赛A轮 C.倒水【二分+分类讨论】
- hdu4822 Tri-War 树上分类讨论
- 科学计数法还原成实数 CodeForces - 697B(分类讨论)
- hdu 5461(分类讨论)
- 4进制加法-C++实现-分类讨论
- CF 375D. Tree and Queries加强版!!!【dfs序分块 大小分类讨论】
- CodeForces 788B - Weird journey [ 分类讨论 ] [ 欧拉通路 ]
- 8-30(高斯,树状数组,分类讨论,stl)
- CF 305A(Strange Addition-贪心+分类讨论)