AtCoder Beginner Contest 156
A - Beginner(模拟)
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long ll; int main() { ll n,r; cin>>n>>r; if(n>=10) cout<<r<<endl; else{ r=r+100*(10-n); cout<<r<<endl; } return 0; }
B - Digits(模拟)
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; int main() { ll n,k; cin>>n>>k; int cnt=0; while(n){ n/=k; cnt++; } cout<<cnt<<endl; }
C - Rally(枚举)
思路:
由于x很小,所以我们只要枚举1-100看看哪个值最小就行了
#include<iostream> #include<algorithm> #define inf 0x3f3f3f3f using namespace std; const int maxn=105; int a[maxn],flag[maxn]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int ans=inf,pos=-1,sum=0; for(int i=1;i<=100;i++){ sum=0; for(int j=1;j<=n;j++){ sum+=(a[j]-i)*(a[j]-i); } if(sum<ans){ ans=sum; pos=i; } } cout<<ans<<endl; return 0; }
D - Bouquet(容斥,逆元求组合数)
思路:
通过容斥定理很明显 ans = 2n - 1 - Can -Cbn ,注意求逆元的取模问题
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int mod=1e9+7; ll quick_mod(ll a,ll b) { ll ans = 1; while(b){ if(b&1){ ans = (ans*a)%mod; --b; } a = (a*a)%mod; b >>= 1; } return ans%mod; } ll Inv(ll x){ return quick_mod(x,mod-2); } ll C(ll n,ll m){ if (m>n) return 0; ll ans = 1; for (int i = 1; i <= m; ++i) ans=ans*Inv(i)%mod*(n-i+1)%mod; return ans%mod; } int main() { ll n,a,b; cin>>n>>a>>b; ll ans=quick_mod(2,n)-1; ans-=C(n,a)+C(n,b); ans=(ans%mod+mod)%mod; cout<<ans<<endl; }