第三题就是个坑比,题意自己没讲清楚,比如如果碰到0破坏了方块那这一步还算不算是一步,连续两次遇到转向破坏了第二个转向,第二个转向还转不转 最后时间不够了,交了卷才写出了能AC的代码- - #include<iostream> #include<vector> #include<string> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; vector<int> stage; while (n--) { string cur; cin >> cur; if (cur[0] == '<') stage.emplace_back(-2); else if (cur[0] == '>') stage.emplace_back(-3); else stage.emplace_back(stoi(cur)); } while (q--) { int start, end; cin >> start >> end; vector<int> cur_stage(stage.begin() + start - 1, stage.begin() + end); int i = 0, score = 0, direct = 1; bool flag = false; while (i >= 0 && i < cur_stage.size()) { if (cur_stage[i] > 0) { flag = false; score += cur_stage[i]; cur_stage[i]--; } else if (cur_stage[i] != 0){ if (!flag) { if (cur_stage[i] == -2) direct = 0; else direct = 1; flag = true; } else cur_stage[i] = 0; } if (direct) i++; else i--; } cout << score << endl; } system("pause"); return 0; }
点赞 2

相关推荐

02-24 16:48
已编辑
电子科技大学 Java
宇宙究极无敌耀孝子:如果你计网和算法都还没准备,建议别面。 字节用go多,spring之类问得很少,重点问计网,mysql,redis,穿插点java和操作系统的八股,然后必做算法,两道算法如果都没a出来可以说是必挂。 你取消面试就算有影响凭你的bg秋招肯定还能面,要是一面就脏面评了春招秋招肯定就白瞎了。
点赞 评论 收藏
分享
牛客网
牛客企业服务