Kickstart2019_Round D

这一场的analysis出的好慢啊。。


A:

看出一个性质:两个数字异或以后的数位奇偶性满足只有在奇加偶的情况下才等于奇。所以就是找最大长度的区间使得区间内有偶数个“奇数字”。

Set的end()不能当成rbegin()用啊。。

B:

翻了半天,找到一个令人拍案叫绝的中国人写的std,非常精妙

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <set>
using namespace std;

const int maxn = 1e5 + 5;
const int INF = 1e9 + 7;
int x[maxn], type[maxn];
set<int> clockwise, anticlock;
int N, G, M;
int num[maxn][2];
int ans[maxn];

int change(int time){
    while(time <= 0){
        time += N;
    }while(time > N){
        time -= N;
    }
    return time;
}

int main(){
    int T;
    int cas = 0;
    cin >> T;
    while(T--){
        cin >> N >> G >> M;
        clockwise.clear();
        anticlock.clear();
        memset(num, 0, sizeof(num));
        for(int i = 1;i <= G;i++){
            char s[3];
            scanf("%d%s", &x[i], s);
            if(s[0] == 'C'){
                type[i] = 0;
                clockwise.insert(x[i]);
                clockwise.insert(x[i] - N);
                clockwise.insert(x[i] - N*2);
            }else{
                type[i] = 1;
                anticlock.insert(x[i]);
                anticlock.insert(x[i] + N);
                anticlock.insert(x[i] + N*2);
            }
        } 
        int mod = M % N;
        if(M > N){
            M = N + mod;
        }
        for(int i = 1;i <= N;i++){
            int t1, t2;
            auto it = clockwise.lower_bound(i - M);
            auto it2 = anticlock.upper_bound(i + M);
            if((it == clockwise.end()) || ((*it) > i)){
                 t1 = INF;   
            }else{
                t1 = (*it) - (i - M);
            }
            if(it2 == anticlock.begin()){
                t2 = INF;
            }else{
                it2--;
                if((*it2) < i){
                    t2 = INF;
                }else{
                    t2 = (i + M) - (*it2);
                }
            }
            if(t1 == INF && t2 == INF)continue;
            else{
                if(t1 == INF){
                    num[change(*it2)][1]++;    
                }else if(t2 == INF){
                    num[change(*it)][0]++;
                }else{
                    if(t1 < t2){
                        num[change(*it)][0]++;
                    }else if(t1 == t2){
                        num[change(*it)][0]++;
                        num[change(*it2)][1]++;
                    }else{
                        num[change(*it2)][1]++;
                    }
                }
            }
        }
        printf("Case #%d:", ++cas);
        for(int i = 1;i <= G;i++){
            printf(" %d", num[x[i]][type[i]]);
        }
        puts("");
    }
    return 0;
}

C:

看成找出K+1个站点。然后枚举中间那个加油站,正着反着用priority_queue()维护两遍前K/2小就可以了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值