C - Merge the balls
https://atcoder.jp/contests/abc351/tasks/abc351_c
思路
使用stack 记录 序列路径
对栈顶两个元素 尝试做缩减处理。
Code
https://atcoder.jp/contests/abc351/submissions/52873456
int n; stack<long long> sq; int main() { cin >> n; for(int i=0; i<n; i++){ long long temp; cin >> temp; if (sq.size() == 0){ sq.push(temp); } else { sq.push(temp); while(sq.size() >= 2){ int topfirst = sq.top(); sq.pop(); int topsecond = sq.top(); sq.pop(); if (topfirst == topsecond){ sq.push(topfirst+1); } else { sq.push(topsecond); sq.push(topfirst); break; } } } } cout << sq.size() << endl; return 0; }
标签:balls,int,topsecond,sq,Merge,abc351,push,topfirst From: https://www.cnblogs.com/lightsong/p/18164573