using c++ Write a programme that: reads the description of buildings from the standard input,determines the minimum number of posters needed to entirely cover their north faces,writes out the outcome to the standard output?
- برمجة سي بلس بلس
- برمجة
- 2021-05-27
- ahmadghneem
الأجوبة
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const int N = 5e5 + 2;
int n, d[N], res, h[N];
stack<int> s;
int main() {
freopen("input.txt", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", d + i, h + i);
if (s.empty()) {
res++;
s.push(h[i]);
} else {
while (s.top() > h[i]) {
s.pop();
if (s.empty())
break;
}
if (s.empty()) {
res++;
s.push(h[i]);
} else {
if (s.top() == h[i])
continue;
else {
res++;
s.push(h[i]);
}
}
}
}
cout << res;
return 0;
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال