CCF-CSP第13次认证第一题——跳一跳【简单】
CCF-CSP第13次认证第一题——跳一跳
官网链接:TUOJ
参考题解
#include <iostream>
#include <vector>
using namespace std;
int main () {
int id, score = 0, last_center_score = 0;
bool valid = false; //记录上次是否是中心
cin >> id;
while(id != 0) {
if(id == 1) {
score += 1;
valid = false;
}else if(id == 2) {
if(valid) {
score += last_center_score + 2;
last_center_score += 2;
}else {
valid = true;
score += 2;
last_center_score = 2;
}
}
cin >> id;
}
cout << score;
return 0;
}