2017上海市高校程序设计邀请赛_F
2017-07-04 15:10
190 查看
problem list
F 蚂蚁
刚开始想的是对于序列里面数值大小打标记之类的
但是想想复杂度太高
用栈来做模拟,选择一个方向push,另一个方向作为pop的判定,中途计算ans
F 蚂蚁
但是想想复杂度太高
用栈来做模拟,选择一个方向push,另一个方向作为pop的判定,中途计算ans
#include <bits/stdc++.h> using namespace std; typedef long long LL ; typedef unsigned long long ULL ; const int maxn = 1000 + 10 ; const int inf = 0x3f3f3f3f ; const int npos = -1 ; const double eps = 1e-20 ; int n, a, b, ans; std::stack< int > s; int main(){ // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); while(~scanf("%d",&n)){ ans=0; while(!s.empty()){s.pop();} for(int i=1;i<=n;i++){ scanf("%d %d",&a,&b); if(b){ s.push(a); }else{ while(!s.empty() && s.top()<a){s.pop();} ans+=s.empty(); } } ans+=s.size(); printf("%d\n",ans); } return 0; }
相关文章推荐
- 2017上海市高校程序设计邀请赛_K
- 2017上海市高校程序设计邀请赛_L
- 2017上海市高校程序设计邀请赛_E
- 2017上海市高校程序设计邀请赛_A
- 2017上海市高校程序设计邀请赛_G
- 2017上海市高校程序设计邀请赛_C
- 2017上海市高校程序设计邀请赛_I
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 A. 足球锦标赛
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 E.章鱼哥没有女朋友
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 (重现)
- 游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 (重现)F. 蚂蚁
- 「游族杯」上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 (重现) Problem D. 萝莉理论计算机科学家
- 上海市高校程序设计邀请赛暨华东师范大学第九届 ECNU Coder 程序设计竞赛 C. 神奇怪兽在哪里
- k.计软联谊 「游族杯」上海市高校程序设计邀请赛(数论)
- 2017陕西省大学生程序设计竞赛邀请赛总结!
- 华南理工大学第二届“超级码力”程序设计竞赛暨广东省高校邀请赛
- 2017武汉大学华中地区程序设计邀请赛个人感悟
- 大学生程序设计竞赛暨西南地区高校邀请赛 赛后总结
- 2017第七届吉首大学“新星杯”程序设计大赛(暨新生网络同步赛)