第三题就是个坑比,题意自己没讲清楚,比如如果碰到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

相关推荐

不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
05-09 14:45
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-27 20:15
还能挽救吗?找同学帮忙看了一下&nbsp;字节怎么能如此对我
牛客26396789...:你这是严重红线,被发现你自己永远进不去,你那个同学直接走人,你还敢宣扬
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务