码迷,mamicode.com
首页 > 其他好文 > 详细

3.25 模拟赛

时间:2019-03-26 17:03:15      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:namespace   iostream   view   div   using   ring   double   ret   stream   

T1

题目大意:

给出一个数$n$,求有多少个正回文数对$(p,q)$满足$p+q=n$

思路:

 

T2 

题目大意:

给出一个带边权的完全图,定义树上一个点的权值$f(x)$为其到根的路径上边权的最小值,特别的$f(root)=0$,一个树的权值为所有点的权值和

求每个点的最小权值生成树

思路:

 

技术图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<map>
10 #include<set>
11 #define ll long long
12 #define db double
13 #define inf 2139062143
14 #define MAXN 1010
15 #define rep(i,s,t) for(register int i=(s),i##__end=(t);i<=i##__end;++i)
16 #define dwn(i,s,t) for(register int i=(s),i##__end=(t);i>=i##__end;--i)
17 #define ren for(register int i=fst[x];i;i=nxt[i])
18 #define pb(i,x) vec[i].push_back(x)
19 #define pls(a,b) (a+b)%MOD
20 #define mns(a,b) (a-b+MOD)%MOD
21 #define mul(a,b) (1LL*(a)*(b))%MOD
22 using namespace std;
23 inline int read()
24 {
25     int x=0,f=1;char ch=getchar();
26     while(!isdigit(ch)) {if(ch==-) f=-1;ch=getchar();}
27     while(isdigit(ch)) {x=x*10+ch-0;ch=getchar();}
28     return x*f;
29 }
30 int n,mp[MAXN][MAXN],mn=inf,q[MAXN],l=1,r,vis[MAXN];
31 ll dis[MAXN];
32 int main()
33 {
34     n=read();rep(i,1,n) dis[i]=inf;rep(i,1,n) rep(j,i+1,n)
35         mp[i][j]=mp[j][i]=read(),mn=min(mn,mp[i][j]),
36         dis[i]=min(dis[i],(ll)mp[i][j]<<1),dis[j]=min(dis[j],(ll)mp[i][j]<<1);
37     rep(i,1,n) dis[i]-=(mn<<1);rep(i,1,n) rep(j,1,n) if(i^j) mp[i][j]-=mn;
38     rep(i,1,n) q[++r]=i,vis[i]=1;int x;
39     while(l<=r)
40     {
41         x=q[l++],vis[x]=0;rep(i,1,n) if(x^i&&dis[i]>dis[x]+mp[x][i]) 
42             {dis[i]=dis[x]+mp[x][i];if(!vis[i]) vis[i]=1,q[++r]=i;}
43     }
44     rep(i,1,n) printf("%lld ",dis[i]+(ll)mn*(n-1));
45 }
View Code

 

T3 

题目大意:

思路:

 

技术图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<map>
10 #include<set>
11 #define ll long long
12 #define db double
13 #define inf 2139092143
14 #define MAXN 200100
15 #define MOD 998244353
16 #define rep(i,s,t) for(register int i=(s),i##end=(t);i<=i##end;++i)
17 #define dwn(i,s,t) for(register int i=(s),i##end=(t);i>=i##end;--i)
18 #define ren for(int i=fst[x];i;i=nxt[i])
19 #define pls(a,b) (a%MOD+b%MOD)%MOD
20 #define mns(a,b) (a%MOD-b%MOD+MOD)%MOD
21 #define mul(a,b) (1LL*(a%MOD)*(b%MOD))%MOD
22 using namespace std;
23 inline int read()
24 {
25     int x=0,f=1;char ch=getchar();
26     while(!isdigit(ch)) {if(ch==-) f=-1;ch=getchar();}
27     while(isdigit(ch)) {x=x*10+ch-0,ch=getchar();}
28     return x*f;
29 }
30 int n,m,rev[MAXN],l2[MAXN],pw[30],ipw[30],A[MAXN],B[MAXN];
31 int g[18][MAXN],f[18][MAXN],h[18][MAXN],iv[MAXN],s[30][30];
32 int ans,p[MAXN],ip[MAXN],tmp[MAXN];
33 int q_pow(int bas,ll t,int res=1)
34 {
35     for(;t;t>>=1,bas=mul(bas,bas))
36         if(t&1) res=mul(res,bas);return res;
37 }
38 void ntt(int *a,int n,int f)
39 {
40     rep(i,0,n-1) if(i<rev[i]) swap(a[i],a[rev[i]]);
41     for(int i=1;i<n;i<<=1)
42     {
43         int wn= f==1?pw[l2[i]+1]:ipw[l2[i]+1];
44         for(int j=0;j<n;j+=(i<<1))
45         {
46             int w=1,x,y;
47             for(int k=0;k<i;k++,w=mul(w,wn))
48                 x=a[j+k],y=mul(a[j+k+i],w),a[j+k]=pls(x,y),a[j+k+i]=mns(x,y);
49         }
50     }
51     if(f==1) return ;int nv=q_pow(n,MOD-2);
52     rep(i,0,n-1) a[i]=mul(a[i],nv);
53 }
54 void solve(int *a,int *b,int lmt)
55 {
56     int t=l2[lmt];rep(i,0,lmt-1) rev[i]=(rev[i>>1]>>1)|((i&1)<<(t-1));
57     ntt(a,lmt,1);ntt(b,lmt,1);rep(i,0,lmt-1) a[i]=mul(mns(2,mul(a[i],b[i])),a[i]);
58     ntt(a,lmt,-1);
59 }
60 int C(int n,int m){int res=ip[m];dwn(i,n,n-m+1) res=mul(res,i);return res;}
61 void inv(int *a,int *f,int lmt)
62 {
63     f[0]=q_pow(a[0],MOD-2);
64     for(int t=2;t<=lmt;t<<=1)
65         {rep(i,0,t-1) tmp[i]=a[i];solve(f,tmp,t<<1);rep(i,t,(t<<1)-1) f[i]=0;}
66 }
67 void mem(int *a,int n,int val) {rep(i,0,n) a[i]=val;}
68 int main()
69 {
70     n=read(),m=read();ll num;rep(i,2,n<<2)
71     {
72         l2[i]=l2[i>>1]+1;
73         if(!pw[l2[i]]) pw[l2[i]]=q_pow(3,(MOD-1)/i),ipw[l2[i]]=q_pow(pw[l2[i]],MOD-2);
74     }
75     int t=l2[n]+2,lmt=1<<t;p[0]=ip[0]=s[0][0]=1;
76     rep(i,1,lmt) p[i]=mul(p[i-1],i);rep(i,1,lmt) ip[i]=q_pow(p[i],MOD-2);
77     rep(i,1,m) rep(j,1,i) s[i][j]=pls(s[i-1][j-1],mul(s[i-1][j],j));
78     rep(j,0,m) rep(i,0,(lmt>>1)-1)
79     {
80         num=1LL*i*(i-1)>>1;g[j][i]=mul(C(num%MOD,j),q_pow(2,(num-j+MOD-1)%(MOD-1)));
81         if(i) h[j][i]=mul(g[j][i],ip[i-1]);g[j][i]=mul(g[j][i],ip[i]);
82     }
83     inv(g[0],iv,lmt>>1);rep(i,0,lmt-1) rev[i]=(rev[i>>1]>>1)|((i&1)<<(t-1));
84     rep(i,0,m) ntt(g[i],lmt,1);ntt(iv,lmt,1);
85     rep(k,0,m)
86     {
87         mem(tmp,lmt,0);rep(j,1,k) rep(i,0,lmt-1)
88             tmp[i]=pls(tmp[i],mul(g[j][i],f[k-j][i]));ntt(tmp,lmt,-1);
89         rep(i,0,(lmt>>1)-1) f[k][i]=mns(h[k][i],tmp[i]);ntt(f[k],lmt,1);
90         rep(i,0,lmt-1) f[k][i]=mul(f[k][i],iv[i]);
91         ntt(f[k],lmt,-1);rep(i,lmt>>1,lmt+5) f[k][i]=0;
92         ans=pls(ans,mul(mul(f[k][n],p[n-1]),mul(s[m][k],p[k])));ntt(f[k],lmt,1);
93     }
94     printf("%d\n",ans);
95 }
View Code

 

3.25 模拟赛

标签:namespace   iostream   view   div   using   ring   double   ret   stream   

原文地址:https://www.cnblogs.com/yyc-jack-0920/p/10600897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!