zoukankan      html  css  js  c++  java
  • 【UOJ Round #5】

    构造+贪心/数论


      为什么只有两个标题呢……因为第二题我不会……

    怎样提高智商

      构造题……然而一开始半天我都yy不出来……

      后来我想:这题应该不会特别麻烦,而且既然样例只给了1,可能再给大一点就让人发现规律了……(心理战的可怕0.0?)然后yy了一下,发现全部都写0的答案是最多的,是$4*3^{n-1}$,然后就过了……

      唯一用到的是快速幂?

     1 //UOJ Round #5 A
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<iostream>
     6 #include<algorithm>
     7 #define rep(i,n) for(int i=0;i<n;++i)
     8 #define F(i,j,n) for(int i=j;i<=n;++i)
     9 #define D(i,j,n) for(int i=j;i>=n;--i)
    10 using namespace std;
    11 const int MOD=998244353;
    12 
    13 void read(int &v){
    14     v=0; int sign=1; char ch=getchar();
    15     while(ch<'0' || ch>'9') {if (ch=='-') sign=-1; ch=getchar();}
    16     while(ch>='0'&&ch<='9') {v=v*10+ch-'0'; ch=getchar();}
    17     v*=sign;
    18 }
    19 typedef long long LL;
    20 
    21 LL pow_mod(int a,int b){
    22     LL r=1,base=a;
    23     while(b){
    24         if (b&1) r=(r*base)%MOD;
    25         base=base*base%MOD;
    26         b>>=1;
    27     }
    28     return r;
    29 }
    30 
    31 int main(){
    32     int n=0;
    33     read(n);
    34     printf("%lld
    ",pow_mod(3,n-1)*4%MOD);
    35     F(i,1,n) printf("A 0 0 0 0
    ");
    36     return 0;
    37 }
    View Code

    怎样跑得更快

      Orz vfk&trz!

      这题真的是一道非常好的题!

      然而由于我实在太傻逼,直到现在才看懂vfk的题解……vfk的题解写的真的非常好,清晰易懂0.0

      感觉莫比乌斯反演真是好神奇>_<,不过做过这道题以后对莫比乌斯反演又有了些新的感悟?

      小范围枚举倍数or约数进行反演感觉更简单直观……易于理解……(然而大多数题目的数据范围都比较大?QwQ)

     1 //UOJ Round5 C
     2 #include<vector>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<iostream>
     7 #include<algorithm>
     8 #define rep(i,n) for(int i=0;i<n;++i)
     9 #define F(i,j,n) for(int i=j;i<=n;++i)
    10 #define D(i,j,n) for(int i=j;i>=n;--i)
    11 using namespace std;
    12 typedef long long LL;
    13 inline int getint(){
    14     int r=1,v=0; char ch=getchar();
    15     for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-1;
    16     for(; isdigit(ch);ch=getchar()) v=v*10-'0'+ch;
    17     return r*v;
    18 }
    19 const int N=1e5+10,P=998244353;
    20 /*******************template********************/
    21 
    22 int n,c,d,q;
    23 int b[N],f_r[N],f_z[N],hx[N],x[N],g[N];
    24 inline void exgcd(LL a,LL b,LL &d,LL &x,LL &y){
    25     if (!b){d=a;x=1;y=0;}
    26     else {exgcd(b,a%b,d,y,x); y-=(a/b)*x;}
    27 }
    28 inline LL inv(int a){
    29     LL d,x,y;
    30     exgcd(a,P,d,x,y);
    31     return d==1 ? (x+P)%P : -1;
    32 }
    33 inline LL Pow(LL a,int b){
    34     LL r=1;
    35     for(;b;b>>=1,a=a*a%P) if (b&1) r=r*a%P;
    36     return r;
    37 }
    38 
    39 void solve(){
    40     F(i,1,n) f_z[i]=(LL)b[i]*g[i]%P;
    41     F(i,1,n)
    42         for(int j=i+i;j<=n;j+=i){
    43             f_z[j]-=f_z[i];
    44             if (f_z[j]<0) f_z[j]+=P;
    45         }
    46     F(i,1,n){
    47         if (f_r[i]==-1 && f_z[i]!=0){puts("-1");return;}
    48         hx[i]=(LL)f_r[i]*f_z[i]%P;
    49     }
    50     D(i,n,1)
    51         for(int j=i+i;j<=n;j+=i){
    52             hx[i]-=hx[j];
    53             if (hx[i]<0) hx[i]+=P;
    54         }
    55     F(i,1,n) x[i]=(LL)hx[i]*g[i]%P;
    56     F(i,1,n) printf("%d%c",x[i],i==n?'
    ':' ');
    57 }
    58 int main(){
    59 #ifndef ONLINE_JUDGE
    60     freopen("C.in","r",stdin);
    61     freopen("C.out","w",stdout);
    62 #endif 
    63     n=getint(); c=getint(); d=getint(); q=getint();
    64     F(i,1,n){
    65         f_r[i]=Pow(i,abs(c-d));
    66         if (c<d) f_r[i]=inv(f_r[i]);
    67     }
    68     F(i,1,n) g[i]=Pow(Pow(i,d),P-2);
    69     F(i,1,n)
    70         for(int j=i+i;j<=n;j+=i){
    71             f_r[j]-=f_r[i];
    72             if (f_r[j]<0) f_r[j]+=P;
    73         }
    74     F(i,1,n) f_r[i]=inv(f_r[i]);
    75     while(q--){
    76         F(i,1,n) b[i]=getint();
    77         solve();
    78     }
    79     return 0;
    80 }
    View Code
  • 相关阅读:
    cookie和session的区别和用法
    JavaScript深浅拷贝
    前端知识
    typescript -- ts
    vue笔记精华部分
    宜人贷项目里-----正则匹配input输入月份规则
    PHP-Socket-阻塞与非阻塞,同步与异步概念的理解
    PHP socket客户端长连接
    PHP exec/system启动windows应用程序,执行.bat批处理,执行cmd命令
    查看局域网内所有ip
  • 原文地址:https://www.cnblogs.com/Tunix/p/4603342.html
Copyright © 2011-2022 走看看