• CodeForces 430A Points and Segments (easy)(构造)题解


    题意:之前愣是没看懂题意...就是给你n个点的坐标xi,然后还规定了Li,Ri,要求给每个点染色,每一组L,R内的点红色和黑色的个数不能相差大于1个,问你能不能染成功,不能输出-1,能就按照输入的顺序输出颜色

    思路:我会说我根本没想到怎么做吗?显然只要交替染色相差就不会大于1

    代码:

    #include<set>
    #include<map>
    #include<stack>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<string>
    #include<cstdio>
    #include<cstring>
    #include<sstream>
    #include<iostream>
    #include<algorithm>
    typedef long long ll;
    using namespace std;
    const int maxn = 100 + 10;
    const int MOD = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    struct node{
        int id, col, i;
        bool operator < (const node x) const{
            return id < x.id;
        }
    }a[maxn];
    bool cmp(node x, node y){
        return x.i < y.i;
    }
    int main(){
        int n, m, c;
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; i++) scanf("%d", &a[i].id), a[i].i = i;
        for(int i = 1; i <= m; i++) scanf("%d%d", &c, &c);
        sort(a + 1, a + n + 1);
        for(int i = 1; i <= n; i++) a[i].col = i & 1;
        sort(a + 1, a + n + 1, cmp);
        for(int i = 1; i <= n; i++){
            if(i != 1) printf(" ");
            printf("%d", a[i].col);
        }
        printf("
    ");
        return 0;
    }
  • 相关阅读:
    uniapp开发微信小程序
    requests自动登录禅道并提交bug 测试
    [转载]使用CPU时间戳进行高精度计时
    lu面
    音量控制面板项目说明
    【转载】粤语翻译工具
    专业操盘手的买卖法则
    自动刷新查询火车票脚本
    股东权益和权益比
    异形魔方SQ1的暴力解法
  • 原文地址:https://www.cnblogs.com/KirinSB/p/10389239.html
Copyright © 2020-2023  润新知