Topic Link: Portal
Test instructions
There are N heights of the Hi Peaks, then sea level, initially 0, and then the plane will rise by one meter every second.
Then given the M-moment, it is obviously a piece of time when the peak is divided into a few pieces at the beginning of the first.
Analysis:
We will look at the sea is not moving, and then to consider the time backwards, considering that the mountain is gradually rising, and then if it's
Before this time, if the peaks of its left and right are not present, then the number of blocks will increase, or if both sides
If that happens then the number of blocks will be reduced by one.
The code is as follows:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int MAXN = 1e6+10;struct nod{int id,h; BOOL operator < (const struct NOD &tmp) const{return h>tmp.h; }}p[maxn];int s[maxn];int ans[maxn];bool vis[maxn];int main () {int t,n,m,cas=1; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n,&m); for (int i=0;i<n;i++) {scanf ("%d", &p[i].h); P[i].id=i; } for (int i=0;i<m;i++) {scanf ("%d", &s[i]); } sort (p,p+n); memset (vis,0,sizeof (VIS)); int i,j,high=0; for (i=m-1,j=0;i>=0;i--) {for (; j<n&&s[i]<p[j].h;j++) {vis[p[j].id]=1; if (p[j].id==0| |! Vis[p[j].id-1]) && (p[j].id==n-1| |! VIS[P[J].ID+1])//left and right both sides have no dew to high++; else if ((P[j].id>0&&vis[p[j].id-1]) && (p[j].id<n-1&&VIS[P[J].ID+1]) high--; } Ans[i]=high; } printf ("Case #%d:", cas++); for (int i=0;i<m;i++) {if (i==m-1) printf ("%d\n", Ans[i]); else printf ("%d", ans[i]); }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Acdream 1205 disappeared Block (analog)