A Architecture
Your brother has won an award at the recent Breakthroughs in Architectural Problems Conference and has been given the once in a lifetime opportunity of redesigning the city center
of his favorite city Nijmegen. Since the most striking parts of a city’s layout are the skylines,
your brother has started by drawing ideas for how he wants the northern and eastern skylines
of Nijmegen to look. However, some of his proposals look rather outlandish, and you are
starting to wonder whether his designs are possible.
For his design, your brother has put an R × C grid on the city. Each cell of the city will
contain a building of a certain height. The eastern skyline is given by the tallest building in
each of the R rows, and the northern skyline is given by the tallest building in each of the C
columns.
A pair of your brother’s drawings of skylines is possible if and only if there exists some way
of assigning building heights to the grid cells such that the resulting skylines match these
drawings.
Figure A.1 shows a possible city with the northern and eastern skylines exactly as given in
the input of the first sample.
1 2 3 4
0 1 2 3
1 2 1 1
1 0 1 1
Figure A.1: Example city showing sample 1 has a valid solution.
Input
• The first line consists of two integers 1 ≤ R, C ≤ 100, the number of rows and columns
in the grid.
• The second line consists of R integers x1, . . . , xR describing the eastern skyline (0 ≤ xi ≤ 1000
for all i).
• The third line consists of C integers y1, . . . , yC describing the northern skyline (0 ≤ yj ≤ 1000
for all j).
Output
Output one line containing the string possible if there exists a city design that produces
the specified skyline, and impossible otherwise.
Sample Input 1 Sample Output 1
4 4
4 3 2 1
1 2 3 4
possible
2 Problem A: Architecture
Sample Input 2 Sample Output 2
4 4
1 2 3 4
1 2 3 2
impossible
这道题其实第一行为 4 4 4 4最大值是4,第一行为1 1 1 4,最大值也是4.
所以说存在很多种可能性。只要是找出一定不成立的条件,那剩下的就是可能的
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e2+10;
int r,c;
bool ok;
int a=-0x3f3f3f3f;
int x[maxn],y[maxn];
int main(){
scanf("%d%d",&r,&c);
for(int i=1;i<=r;i++)
scanf("%d",&x[i]);
for(int i=1;i<=c;i++)
scanf("%d",&y[i]);
for(int i=1;i<=r;i++){
a=max(a,x[i]);
}
for(int i=1;i<=c;i++){
if(a==y[i]){
ok=true;
}
if(a<y[i]){
cout<<"impossible"<<endl;
return 0;
}
}
if(ok)
cout<<"possible"<<endl;
else
cout<<"impossible"<<endl;
return 0;
}