/*
因为房子均为方形
有多少栋房,即模拟出入栈即可,
后一个比起一个高的都入栈
后一个比前一个小就出站并且楼房数加一
注意开始结束都是水平线上即y=0
*/
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
stack<int> st;
st.push(0);
int cnt=0;
int x,y;
for(int i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
while(!st.empty()&&st.top()>y)
{
st.pop();
cnt++;
}
if(y!=st.top())
{
st.push(y);
}
}
while(!st.empty()&&st.top()>0)
{
st.pop();
cnt++;
}
printf("%d\n",cnt);
}
return 0;
}
POJ 3044(楼房数)(栈模拟)
最新推荐文章于 2021-08-01 01:17:32 发布