题解 | #涂颜料#

涂颜料

https://www.nowcoder.com/practice/4ef038ae1c5f4524b8a8a0c1e6b062a1

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> paint(n, 0);
    vector<pair<int , int>> lr;

    while (q--) { // 注意 while 处理多个 case
        pair<int , int> tmp;
        cin >> tmp.first >> tmp.second;
        tmp.first--;
        tmp.second--;
        lr.emplace_back(tmp);
    }

    for (int i = 0; i < lr.size(); i++){
        paint[lr[i].first]++;
        if (lr[i].second+1 != paint.size()) paint[lr[i].second+1]--;
    }
    
    int sum = 0;

    for (int i = 0; i < paint.size(); i++) {
        sum += paint[i];
        if (sum == 0){
            cout << 'O';
        } else if ((sum - 1) % 3 == 0) cout<<'R';
        else if ((sum - 1) % 3 == 1) cout << 'G';
        else if ((sum - 1) % 3 == 2) cout << 'B';
    }

}
// 64 位输出请用 printf("%lld")

储存端点数据最后遍历整个数组,通过端点和判断颜色

全部评论
小马的题?
点赞 回复 分享
发布于 2024-03-12 17:42 福建

相关推荐

07-03 16:13
嘉应学院 Python
xiaolihuam...:很明显骗子,如果是hr直接约你面试了,哪用得着内推,如果是员工的话,你得多优秀,一线员工直接加你微信,
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务