zoukankan      html  css  js  c++  java
  • [CTSC2017]密钥

    传送门:http://uoj.ac/problem/297

    “无论哪场比赛,都要相信题目是水的”

    这不仅是HNOI2018D2T3的教训,也是这题的教训,思维定势真的很可怕。

    普及组水题,真是愧对CTSC的头衔。

    A当作1,B当作-1,开个桶计数即可。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define rep(i,l,r) for (int i=(l); i<=(r); i++)
     5 using namespace std;
     6 
     7 const int M=40000005;
     8 bool p[M];
     9 int cnt[M],A[M],B[M],seed,n,k,T,S,ans1,ans2,ans3;
    10 
    11 int getrand(){
    12     seed = ((seed * 12321) ^ 9999) % 32768;
    13     return seed;
    14 }
    15 
    16 void generateData(){
    17     scanf("%d%d%d",&k,&seed,&S);
    18     int t = 0;
    19     n = k * 2 + 1;
    20     memset(p, 0, sizeof(p));
    21     for (int i = 1; i <= n; i++)
    22     {
    23         p[i] = (getrand() / 128) % 2;
    24         t += p[i];
    25     }
    26     int i = 1;
    27     while (t > k)
    28     {
    29         while (p[i] == 0)
    30             i++;
    31         p[i] = 0;
    32         t--;
    33     }
    34     while (t < k)
    35     {
    36         while (p[i] == 1)
    37             i++;
    38         p[i] = 1;
    39         t++;
    40     }
    41 }
    42 
    43 int main(){
    44     freopen("cipher.in","r",stdin);
    45     freopen("cipher.out","w",stdout);
    46     generateData();
    47     rep(i,1,n) p[i+n]=p[i];
    48     A[0]=n+1; rep(i,1,n<<1) A[i]=A[i-1]+(p[i]?1:-1);
    49     rep(i,1,n) if(p[i]) cnt[A[i]]++,T+=A[i]>A[0];
    50     rep(i,1,n){
    51         if(p[i]) T-=cnt[A[i]],cnt[A[i]]--; else T+=cnt[A[i]+1];
    52         if(!p[i]){
    53             if(T==0) ans1=i;
    54             if(T==S) ans2=i;
    55             if(T==k-S) ans3=i;
    56         }
    57         if (p[i]) cnt[A[i+n]]++,T+=A[i+n]>A[i];    
    58     }
    59     printf("%d
    %d
    %d
    ",ans1,ans2,ans3);
    60     return 0;
    61 }
  • 相关阅读:
    变量,基本数据类型
    编程语言分类,Python介绍、IDE集成开发环境,注释
    Django之Cookie,Session
    第三章
    第二章
    第一章
    php面向对象(文件操作)
    php面向对象(目录操作)
    php有关类和对象的相关知识2
    php有关类和对象的相关知识1
  • 原文地址:https://www.cnblogs.com/HocRiser/p/8868727.html
Copyright © 2011-2022 走看看