Codeforces 821C - Okabe and Boxes
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 821C - Okabe and Boxes
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
821C - Okabe and Boxes
思路:模擬。因?yàn)橹恍枰容^棧頂和當(dāng)前要?jiǎng)h除的值就可以了,所以如果棧頂和當(dāng)前要?jiǎng)h除的值不同時(shí),棧就可以清空了(因?yàn)橄乱淮蔚臈m敳豢赡艹霈F(xiàn)在前面那些值中)。
代碼:
#include<bits/stdc++.h> using namespace std; #define ll long long vector<int>st; int main() {ios::sync_with_stdio(false);cin.tie(0);int n,temp=1,ans=0;string s;cin>>n;for(int i=0;i<n*2;i++){cin>>s;if(s[0]=='a'){int a;cin>>a;st.push_back(a);}else{if(!st.empty()&&st.back()!=temp)st.clear(),ans++;else if(!st.empty())st.pop_back();temp++;}}cout<<ans<<endl; return 0; }轉(zhuǎn)載于:https://www.cnblogs.com/widsom/p/7250223.html
總結(jié)
以上是生活随笔為你收集整理的Codeforces 821C - Okabe and Boxes的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 12.9会议记录
- 下一篇: [Leetcode]第[58]题[JAV