zoukankan      html  css  js  c++  java
  • CSTC 2017 要匙

    题链

     老了,这种题也调了一个小时。机房里一群人在搞基,无心写代码。

    #include<bits/stdc++.h>
    #define N 2000005
    using namespace std;
    int p[N],ppp[N],sum[N],*id=ppp+N/2,anw,now,px[N>>1];
    int seed, n, k, S;
    int getrand()
    {
        seed = ((seed * 12321) ^ 9999) % 32768;
        return seed;
    }
    void generateData()
    {
        scanf("%d%d%d",&k,&seed,&S);
        int t = 0;
        n = k * 2 + 1;
        memset(p, 0, sizeof(p));
        for (int i = 1; i <= n; i++)
        {
            p[i] = (getrand() / 128) % 2;
            t += p[i];
        }
        int i = 1;
        while (t > k)
        {
            while (p[i] == 0)
                i++;
            p[i] = 0;
            t--;
        }
        while (t < k)
        {
            while (p[i] == 1)
                i++;
            p[i] = 1;
            t++;
        }
    }
    int main () {
        freopen("a.in","r",stdin);
        generateData();
        for (int i=1;i<=n;i++) sum[i]=sum[i-1]+(p[i]?1:-1),
        id[sum[i]]+=1-p[i],anw+=(sum[i]>=0)&&(!p[i]);
        now=sum[n];
        for (int i=1;i<=n;i++) {
            if (p[i]) anw-=id[sum[i]-1]; else anw+=id[sum[i]];
            if (!p[i]) px[anw-1]=i;
            now=now+(p[i]?1:-1);
            if (!p[i])  {
             id[sum[i]]--;  anw--;
             id[now]++; if (now>=sum[i]) anw++; }
        }
        printf("%d
    ",px[0]);
        printf("%d
    ",px[S]);
        memset(sum,0,sizeof sum); memset(ppp,0,sizeof ppp); memset(px,0,sizeof px);
        now=anw=0;
        for (int i=1;i<=n;i++) sum[i]=sum[i-1]+(p[i]?-1:1),
        id[sum[i]]+=1-p[i],anw+=(sum[i]>0)&&(!p[i]);
        now=sum[n];
        for (int i=1;i<=n;i++) {
            if (!p[i]) anw-=id[sum[i]]; else anw+=id[sum[i]+1];
            if (!p[i]) px[anw]=i;
            now=now+(p[i]?-1:1);
            if (!p[i])  {
             id[sum[i]]--;  //anw--;
             id[now]++; if (now>sum[i]) anw++; }    
        }
        printf("%d
    ",px[S]);
        return 0;
    }
  • 相关阅读:
    UVALive 7141 BombX
    CodeForces 722D Generating Sets
    CodeForces 722C Destroying Array
    CodeForces 721D Maxim and Array
    CodeForces 721C Journey
    CodeForces 415D Mashmokh and ACM
    CodeForces 718C Sasha and Array
    CodeForces 635C XOR Equation
    CodeForces 631D Messenger
    田忌赛马问题
  • 原文地址:https://www.cnblogs.com/rrsb/p/8711210.html
Copyright © 2011-2022 走看看