“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛
A-hzy 和zsl 的生存挑战
题解:最优策略是A猜B的时候与自己数相同,B猜A的时候与自己数相反。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> using namespace std; int main() { int i; for(i=1;i<=4;i++) printf("1.00\n"); return 0; }
B-人类史上最大最好的希望事件
题解:预处理斐波那契数列暴力求解即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #define mod 192600817 using namespace std; int q,lim,last; int n[10005][2]; long long f[100005],sum[100005]; int main() { int i,a,b,c,d; while(~scanf("%d",&q)) { for(i=1;i<=q;i++) { scanf("%d%d%d%d",&a,&b,&c,&d); n[i][0]=a*4+b+1; n[i][1]=c*4+d+1; if(n[i][0]>n[i][1]) swap(n[i][0],n[i][1]); lim=max(n[i][1],lim); } f[1]=1;f[2]=1; for(i=max(3,last);i<=lim;i++) f[i]=(f[i-1]+f[i-2])%mod; for(i=max(1,last);i<=lim;i++) sum[i]=(sum[i-1]+f[i]*f[i])%mod; for(i=1;i<=q;i++) printf("%lld\n",(sum[n[i][1]]-sum[n[i][0]-1]+mod)%mod); last=lim; } return 0; }
C-超级无敌简单题
题解:对于非鸽子数,发现循环节里的第一个数都是4,其余暴力判断即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> using namespace std; int q,tot,limk; bool v[2500005]; int f[1500005],k[100005]; int solve(int x) { int ret,tmp; ret=0LL; while(x) { tmp=x%10; x/=10; ret+=(tmp*tmp); } return ret; } bool pd(long long x) { while(x!=1&&x!=4) { if(v[x]) return true; x=solve(x); } return x==1; } int main() { int i; v[1]=true; f[tot=1]=1; scanf("%d",&q); for(i=1;i<=q;i++) scanf("%d",&k[i]); limk=k[1]; for(i=2;i<=q;i++) limk=max(limk,k[i]); for(i=2;i<=1200000;i++) if(pd(i)) { v[i]=true; f[++tot]=i; if(tot==limk) break; } for(i=1;i<=q;i++) printf("%d\n",f[k[i]]); return 0; }
G-简单数学题
题解:$i \times \tbinom{n}{i}=n \times \tbinom{n-1}{i-1}$,之后就是差比数列求和了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #define mod 1000000007 using namespace std; long long n; long long quick_pow(long long a,long long b) { long long ret=1,base=a; while(b) { if(b&1) ret=ret*base%mod; base=(base*base)%mod; b>>=1; } return ret; } long long solve() { long long ans; ans=((n-1)%mod*quick_pow(2,n)%mod+1)%mod; return ans; } int main() { while(~scanf("%lld",&n)) printf("%lld\n",solve()); return 0; }
H-zyb的面试
题解:模拟一个十叉树,乱搞即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> using namespace std; int t,n,k; int solve(int n, int k) { int cur,step,l,r; cur=1;k--; while(k>0) { step=0,l=cur,r=cur+1; while(l<=n) { step+=min(n+1,r)-l; l*=10; r*=10; } if(step<=k) cur++,k-=step; else cur*=10,k--; } return cur; } int main() { scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); printf("%d\n",solve(n,k)); } return 0; }
J-Count
题解:矩阵快速幂
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #define mod 123456789 using namespace std; int t; long long n; struct matrix { int n,m; long long a[10][10]; }m1,m2; matrix mul(matrix a,matrix b) { int i,j,k; matrix c; c.m=a.m; c.n=a.n; memset(c.a,0,sizeof(c.a)); for(i=1;i<=c.n;i++) for(j=1;j<=c.m;j++) for(k=1;k<=c.n;k++) c.a[i][j]=(c.a[i][j]+a.a[i][k]*b.a[k][j]%mod)%mod; return c; } matrix qpow(matrix a,long long k) { int i,j; matrix c; c.m=a.m; c.n=a.n; for(i=1;i<=min(c.n,c.m);i++) c.a[i][i]=1; for(i=1;i<=c.n;i++) for(j=1;j<=c.m;j++) if(i!=j) c.a[i][j]=0; while(k) { if(k&1) c=mul(a,c); a=mul(a,a); k>>=1; } return c; } long long solve(long long n) { matrix tmp; tmp=qpow(m1,n-2); tmp=mul(tmp,m2); return tmp.a[1][1]; } int main() { int i,j; m1.n=6;m1.m=6; m1.a[1][1]=m1.a[1][3]=m1.a[2][1]=m1.a[3][3]=m1.a[3][6]=1; m1.a[4][4]=m1.a[4][6]=m1.a[5][5]=m1.a[5][6]=m1.a[6][6]=1; m1.a[1][2]=m1.a[4][5]=2; m1.a[3][4]=m1.a[3][5]=3; m2.n=6;m2.m=1; m2.a[1][1]=2; m2.a[2][1]=1; m2.a[3][1]=27; m2.a[4][1]=9; m2.a[5][1]=3; m2.a[6][1]=1; scanf("%d",&t); while(t--) { scanf("%lld",&n); printf("%lld\n",solve(n)); } return 0; }