长脖子鹿省选模拟赛 [LnOI2019SP]快速多项式变换(FPT)
生活随笔
收集整理的這篇文章主要介紹了
长脖子鹿省选模拟赛 [LnOI2019SP]快速多项式变换(FPT)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本片題解設(shè)計(jì)兩種解法
果然是簽到題...
因?yàn)榉祷刂祮?wèn)題T了好久...
第一眼:搜索大水題?
?然后...竟然A了
1 #include<cstdio> 2 #include<queue> 3 #include<iostream> 4 #include<cstring> 5 #define int long long 6 using namespace std; 7 inline int read(){ 8 int ans=0,f=1;char chr=getchar(); 9 while(!isdigit(chr)){if(chr=='-') f=-1;chr=getchar();} 10 while(isdigit(chr)){ans=(ans<<3)+(ans<<1)+chr-48;chr=getchar();} 11 return ans*f; 12 }int fm,m,tot,a[105],x,ff,p[105],q[105]; 13 void dfs(int x,int now){ 14 if(ff) return; 15 if(x==0&&now>=m) return; 16 if(now<m){ 17 ff=1; 18 int t=100; 19 while(p[t]==0) t--; 20 cout<<t+1<<endl<<now<<" "; 21 for(int i=1;i<=t;i++) cout<<p[i]<<" "; 22 return; 23 } 24 int t=now/a[x]; 25 for(int i=t;i>=0;i--) p[x]=i,dfs(x-1,now-a[x]*i); 26 } 27 signed main(){ 28 m=read(),fm=read(); 29 x=1;a[0]=1; 30 while(x<fm&&tot<=101){a[++tot]=x*m;x=x*m;} 31 dfs(tot,fm); 32 return 0; 33 }?但其實(shí)只要分析一下,就發(fā)現(xiàn)式子跟進(jìn)制轉(zhuǎn)換有很大關(guān)系啊,我們只要把fm當(dāng)做m進(jìn)制數(shù)來(lái)處理即可
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<cstdlib> 7 #include<ctime> 8 #define int long long 9 using namespace std; 10 inline int read(){ 11 int ans=0,f=1;char chr=getchar(); 12 while(!isdigit(chr)){if(chr=='-') f=-1;chr=getchar();} 13 while(isdigit(chr)){ans=(ans<<3)+(ans<<1)+chr-48;chr=getchar();} 14 return ans*f; 15 }void write(long long x){ 16 if(x < 0) putchar('-'),x = -x; 17 if(x > 9) write(x / 10); 18 putchar(x % 10 + '0'); 19 }int n,m,a[505],tot; 20 signed main(){ 21 m=read(),n=read(); 22 while(n){a[++tot]=n%m;n/=m;} 23 printf("%d\n",tot); 24 for(int i=1;i<=tot;i++)write(a[i]),putchar(' '); 25 return 0; 26 }?
轉(zhuǎn)載于:https://www.cnblogs.com/zhenglw/p/10505881.html
總結(jié)
以上是生活随笔為你收集整理的长脖子鹿省选模拟赛 [LnOI2019SP]快速多项式变换(FPT)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: netty 为什么用nio 不用 aio
- 下一篇: 腾讯云搭建个人博客