Acdream 1205 disappeared Block (analog)

Source: Internet
Author: User

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&&AMP;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.