Bzoj 1628 && 1683: [Usaco2007 demo]city Skyline (analog)

Source: Internet
Author: User

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

Outputs an integer representing the minimum number of buildings in the city Sample Input 1 1 2 2 5 1 6 3 8 1 One 0 2 3 2 Sample Output 1


x because the input is guaranteed to increment, so meaningless

This maintains a priority queue (better with the stack), each input a Y, will >=y all pop up, each popup a ans++, and then y into the queue

Finally, remember to count a y=0.


#include <stdio.h>
#include <queue>
using namespace std;
priority_queue<int> Q;
int main (void)
{
	int n, W, I, x, ans = 0;
	scanf ("%d%d", &n, &w);
	for (i=1;i<=n;i++)
	{
		scanf ("%*d%d", &x);
		while (Q.empty () ==0 && q.top () >x)
		{
			ans++;
			Q.pop ();
		}
		if (Q.empty () | | q.top () <x)
			Q.push (x);
	while (Q.empty () ==0)
	{
		if (q.top ()!=0)
			ans++;
		Q.pop ();
	}
	printf ("%d\n", ans);
	return 0;
}

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.