HDU 2020 Multi-University Training Contest 6
Little rabbit's equation
直接枚举即可。
#include <iostream> #include <cstdio> #include <string> #include <algorithm> using namespace std; string a,a1,a2,a3; int u=2,num=1; char s; long long int cal(string t,int k) { long long int ans=0; for(int i=0;i<t.size();i++) { if(isdigit(t[i])) ans=ans*k+t[i]-'0'; else ans=ans*k+t[i]-'A'+10; } return ans; } int main() { int flag=1; while(cin>>a) { a1.clear(); a2.clear(); a3.clear(); u=2; flag=1; num=1; for(int i=0;i<a.size();i++){ if(!isdigit(a[i])&&!isalpha(a[i])) { if(a[i]=='=') num++; else { s=a[i]; num++; } } else if(isdigit(a[i])){ u=max(u,a[i]-'0'+1); if(num==1) a1+=a[i]; else if(num==2) a2+=a[i]; else a3+=a[i]; } else { u=max(u,a[i]-'A'+11); if(num==1) a1+=a[i]; else if(num==2) a2+=a[i]; else a3+=a[i]; } } // cout<<a1<<endl<<a2<<endl<<a3<<endl; for(int i=u;i<=16;i++) { long long int c1=cal(a1,i),c2=cal(a2,i),c3=cal(a3,i); //cout<<c1<<" "<<c2<<" "<<c3<<" "<<endl; if(s=='+') { if(c1+c2==c3) { cout<<i<<endl; flag=0; break; } } else if(s=='-') { if(c1-c2==c3) { cout<<i<<endl; flag=0; break; } } else if(s=='*') { if(c1*c2==c3) { cout<<i<<endl; flag=0; break; } } else { if(c2==0) continue; else if(c1%c2!=0) continue; else if(c1/c2==c3) { cout<<i<<endl; flag=0; break; } } } if(flag) cout<<-1<<endl; } getchar(); getchar(); return 0; }
Divisibility
只要b%x==1即可成立
#include<iostream> using namespace std; int main() { int t; cin>>t; for(int i=0;i<t;i++) { long long int b,x; cin>>b>>x; if(b%x==1) cout<<'T'<<endl; else cout<<'F'<<endl; } }
Road To The 3rd Building
题目就是求
写出一部分分母相同的式子,可以发现规律:k和n−k+1的式子是相同的,且两边对称,由两边向中间 的系数逐渐增加,当k在一定范围内增加时 的最大系数逐渐增加。
#include <bits/stdc++.h> #define MAXN 200005 using namespace std; const long long M=1000000007; int T,n,a[MAXN]; long long inv[MAXN],sinv[MAXN],ans,C; inline long long fpow(long long a,long long b) { a%=M;long long r=1; for (;b;b>>=1,(a*=a)%=M) if (b&1) (r*=a)%=M; return r; } void init(int n) { inv[1]=1; for (int i=2;i<=n;i++) inv[i]=(M-M/i)*inv[M%i]%M; for (int i=1;i<=n;i++) sinv[i]=(sinv[i-1]+inv[i])%M; return ; } inline void Solve() { scanf("%d",&n);C=ans=0; for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1,p=n>>1;i<=p;i++) { long long cov=i; cov+=i*(sinv[n-i]-sinv[i]+M)%M;cov%=M; (C+=i*inv[n-i+1]%M)%=M;(cov+=C)%=M; (ans+=a[i]*cov%M)%=M;(ans+=a[n+1-i]*cov%M)%=M; } if (n&1) { long long cov=0; for (int i=1;i<=n;i++) (cov+=min(i,n+1-i)*inv[i]%M)%=M; (ans+=cov*a[(n>>1)+1]%M)%=M; } printf("%lld\n",ans*fpow(1LL*n*(n+1)/2,M-2)%M); return ; } int main() { init(200000); scanf("%d",&T); while (T--) Solve(); return 0; }