icpc:problems:usaco22jan_cow_frisbee_s
目录
problems | |
---|---|
名称 | Cow Frisbee S |
题目编号 | USACO22JAN_S2 |
题目链接 | luogu.com.cn/… |
来源 | USACO |
算法分类 | 单调栈 |
难易程度 | 容易 |
Cow Frisbee S
想法
维护一个从i往左看,能看到的栈,也就是单调递减的栈。
代码实现
#include<iostream> #include<stack> using namespace std; int main() { long long int n, temp, ans = 0; cin >> n; stack<pair<int, long long int> >s; for (int i = 0; i < n; ++i) { cin >> temp; while((!s.empty()) && s.top().second <= temp) { ans += i - s.top().first + 1; s.pop(); } if(!s.empty()) ans += i - s.top().first + 1; s.push(make_pair(i, temp)); } cout << ans; return 0; }
板书
/app/www/public/data/pages/icpc/problems/usaco22jan_cow_frisbee_s.txt · 最后更改: 2023/02/08 08:25 由 温婕莺