[Usaco2007 Demo] [BZOJ1628] City skyline

Source: Internet
Author: User

1628: [Usaco2007 demo]city Skyline time limit:5 Sec Memory limit:64 MB
submit:320 solved:260
[Submit] [Status] [Discuss] The first line of Descriptioninput gives N,w the second line to the n+1 line: Each row gives two integers x, y, the input is strictly incremented, and the first X is always 1Output

Outputs an integer that represents the minimum number of buildings in the city

Sample Input10 26
1 1
2 2
5 1
6 3
8 1
11 0
15 2
17 3
20 2
22 1

INPUT DETAILS:

The case mentioned above

Sample Output6
HINT Source

Silver

A monotonic stack has at most a maximum of n buildings, and if there are two storeys of equal height and there is no lower building than these, the number of buildings can be-1.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<Set>using namespacestd;intn,x,w,h[50005],ans,top,stack[50005];intMain () {scanf ("%d%d",&n,&W); Ans=N;  for(intI=1; i<=n;i++) scanf ("%d%d",&x,&H[i]);  for(intI=1; i<=n;i++)     {         while(H[i]<stack[top]) top--; if(H[i]==stack[top]) ans--; Elsestack[++top]=H[i]; } printf ("%d", ans); return 0;}

[Usaco2007 Demo] [BZOJ1628] City skyline

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.