zoukankan      html  css  js  c++  java
  • 【BZOJ3672】【UOJ#6】【NOI2014】随机数生成器

    暴力出奇迹

    原题:

    2≤N,M≤5000

    0≤Q≤50000

    0≤a≤300

    0≤b,c≤108

    0≤x0<d≤108

    1≤ui,vi≤N×M

    恩首先容易看出来这个棋盘直接模拟搞出来就行了,不用反演矩阵乘之类的奇怪的东西

    然后又容易发现只需要遍历从1~n*m的数尽量答案里塞就是最优答案 = =|||

    然后贪心搞一下,从1~n*m遍历,对于每一个n记录一个top和一个bottom表示第i行能取第bottom[i]到top[i]列的数

    容易发现暴力维护的复杂度是资瓷的 = =|||

    易证不会存在因为之前钦定选择某些数导致后面选不够n+m-1个数的情况

    然后暴力搞就可以辣

    因为2.5e7的数组只能开两个所以有一个要重复使用……

    注意答案的长度是2n…………

    注意一开始递推的姿势,比如两个int和一个longlong相乘要先int乘longlong再乘int之类的

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 using namespace std;
     7 #define ll long long
     8 int rd(){int z=0;  char ch=getchar();
     9     while(ch<'0'||ch>'9')  ch=getchar();
    10     while(ch>='0'&&ch<='9'){z=(z<<3)+(z<<1)+ch-'0';  ch=getchar();}
    11     return z;
    12 }
    13 ll a,b,c,d,n,m,o;  int x[25000001];  int nm;
    14 int T[25000001],tp[5100],bt[5100];
    15 int ans[11000],ast=0;
    16 int main(){//freopen("ddd.in","r",stdin);
    17     int l,r;
    18     cin>>x[0]>>a>>b>>c>>d>>n>>m>>o;  nm=n*m;
    19     for(int i=1;i<=nm;++i)  x[i]=((((x[i-1]*a)%d)*x[i-1])%d+(x[i-1]*b)%d+c)%d;
    20     for(int i=1;i<=nm;++i)  T[i]=i;
    21     for(int i=1;i<=nm;++i)  swap(T[i],T[x[i]%i+1]);
    22     while(o--)  l=rd(),r=rd(),swap(T[l],T[r]);
    23     for(int i=1;i<=nm;++i)  x[T[i]]=i-1;
    24     for(int i=1;i<=n;++i)  tp[i]=m,bt[i]=1;
    25     for(int i=1;i<=nm;++i){
    26         l=x[i]/m+1,r=x[i]%m+1;
    27         if((r>=bt[l])&(r<=tp[l])){
    28             for(int j=1;j<l;++j)if(r<tp[j])  tp[j]=r;
    29             for(int j=l+1;j<=n;++j)if(r>bt[j])  bt[j]=r;
    30             ans[++ast]=i;
    31             if(ast==n+m-1)  break;
    32         }
    33     }
    34     for(int i=1;i<ast;++i)   printf("%d ",ans[i]);
    35     cout<<ans[ast];
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    【HDOJ】2774 Shuffle
    【POJ】2170 Lattice Animals
    【POJ】1084 Square Destroyer
    【POJ】3523 The Morning after Halloween
    【POJ】3134 Power Calculus
    【Latex】如何在Latex中插入伪代码 —— clrscode3e
    【HDOJ】4801 Pocket Cube 的几种解法和优化
    【HDOJ】4080 Stammering Aliens
    【HDOJ】1800 Flying to the Mars
    SQL语法
  • 原文地址:https://www.cnblogs.com/JSL2018/p/6884287.html
Copyright © 2011-2022 走看看