Educational Codeforces Round 13
678A - Johny Likes Numbers 20171130
简单数学题,注意是严格大于就好了
#include<stdlib.h> #include<stdio.h> #include<math.h> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,k,ans; int main() { scanf("%d%d",&n,&k); ans=(n/k)*k; while(ans<=n)ans+=k; return printf("%d\n",ans),0; }
678B - The Same Calendar 20171130
直接把每一年带来的偏差一个个加上去就好,可以用蔡勒公式,但没必要
#include<stdlib.h> #include<stdio.h> #include<math.h> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int ans,y,s; bool check(int k){return (k%4==0 && k%100) || k%400==0;} int main() { scanf("%d",&y),ans=y; while(!s || s%7 || check(y)!=check(ans)) ans++,s+=365+check(ans); printf("%d\n",ans); }
678C - Joty and Chocolate 20171130
显然只需要考虑一个数同时为\(a\)和\(b\)的倍数时候该涂哪边(肯定是涂收益大的颜色啊!)
#include<stdlib.h> #include<stdio.h> #include<math.h> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define LL long long LL n,a,b,p,q,ans; LL gcd(LL x,LL y) { return y?gcd(y,x%y):x; } int main() { scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q); if(p<q)swap(a,b),swap(p,q); ans=(n/a)*p+((n/b)-(n/(a*b/gcd(a,b))))*q; return printf("%I64d\n",ans),0; }
678D - Iterated Linear Function 20171130
相当于求\(f_n=A\cdot f_{n-1}+B\)的第\(n\)项,可以用待定系数法直接求出其通项公式,注意特判\(A=1\)的特殊情况(这题放我天朝不就是个高考数学傻逼题吗←_←)
#include<stdlib.h> #include<stdio.h> #include<math.h> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define LL long long #define MOD 1000000007 LL a,b,n,x,ans; LL qow(LL x,LL y){return y?(y&1?x*qow(x,y-1)%MOD:qow(x*x%MOD,y/2)):1;} int main() { scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&x); ans=qow(a,n)*x%MOD; if(a==1)ans+=n%MOD*b%MOD; else ans+=b*(qow(a,n)+MOD-1)%MOD*qow(a-1,MOD-2)%MOD; printf("%I64d\n",ans%MOD); return 0; }
678E - Another Sith Tournament 20171130
看到数据范围就知道是道状压DP题,考虑倒推把式子搞出来就好了
#include<stdlib.h> #include<stdio.h> #include<math.h> #define N 1<<20 #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n; double p[20][20],f[N][20],ans; int main() { scanf("%d",&n); for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%lf",&p[i][j]); f[1][0]=1; for(int _=0;_<(1<<n);_++) for(int i=0;i<n;i++)if((1<<i)&_) for(int j=0;j<n;j++)if((1<<j)&_) if(i!=j)f[_][i]=max(f[_][i],f[_^(1<<i)][j]*p[j][i]+f[_^(1<<j)][i]*p[i][j]); for(int i=0;i<n;i++)ans=max(ans,f[(1<<n)-1][i]); printf("%.6lf\n",ans); return 0; }
678F - Lena and Queries 20190408