题目是今天中午我在车站写的,纪念一下~
前三题很水就不说了。
A
#include<bits/stdc++.h>
using namespace std;
int main(){
int c, r; cin>>c>>r;
r= c>=10? r: (10-c)*100+r;
cout<<r;
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, b; cin>>n>>b;
int cnt=0;
while(n) n/=b, cnt++;
cout<<cnt;
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int w[N], n;
int main(){
cin>>n;
for(int i=1; i<=n; i++) cin>>w[i];
int res=1e9;
for(int p=1; p<=100; p++){
int d=0;
for(int i=1; i<=n; i++) d+=(w[i]-p)*(w[i]-p);
res=min(res, d);
}
cout<<res;
return 0;
}
D
容斥。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl ‘\n‘
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define int long long
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<‘0‘||ch>‘9‘) {if(ch==‘-‘)x=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘) s=(s<<3)+(s<<1)+ch-‘0‘,ch=getchar();
x*=s;
}
const int N=2e5+5, mod=1e9+7;
int n, a, b;
int fpow(int x, int p){
int res=1;
for(; p; p>>=1, x=x*x%mod)
if(p&1) res=res*x%mod;
return res;
}
int fac[N];
void init(){
fac[0]=1;
rep(i,1,N-1) fac[i]=fac[i-1]*i%mod;
}
int inv(int x){
return fpow(x, mod-2);
}
int C(int a, int b){
int res=1;
dwn(i,a,a-b+1) res=res*i%mod;
res=res*inv(fac[b])%mod;
return res;
}
signed main(){
init();
read(n), read(a), read(b);
int res=((fpow(2, n)-1-C(n, a)-C(n, b))%mod+mod)%mod;
cout<<res<<endl;
return 0;
}
E
组合数知识+容斥
当 \(k\geq n\) 时,我们可以构造出所有情况,转变为 \(n\) 个不同的盒子放 \(n\) 个相同的球,\(n\) 个盒子都可为空的问题,答案自然是 \(C_{2n-1}^{n-1}\)
否则,必然至少有 \(n-k\) 个盒子非空,我们考虑统计反面:枚举一下 \([1,n-k-1]\) 个盒子为空的贡献。
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define endl ‘\n‘
#define debug(x) cerr << #x << ": " << x << endl
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define ceil(a,b) (a+(b-1))/b
#define INF 0x3f3f3f3f
#define ll_INF 0x7f7f7f7f7f7f7f7f
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define int long long
inline void read(int &x) {
int s=0;x=1;
char ch=getchar();
while(ch<‘0‘||ch>‘9‘) {if(ch==‘-‘)x=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘) s=(s<<3)+(s<<1)+ch-‘0‘,ch=getchar();
x*=s;
}
const int N=4e5+5, mod=1e9+7;
int n, k;
int fpow(int x, int p){
int res=1;
for(; p; p>>=1, x=x*x%mod)
if(p&1) res=res*x%mod;
return res;
}
int fac[N];
void init(){
fac[0]=1;
rep(i,1,N-1) fac[i]=fac[i-1]*i%mod;
}
int inv(int x){
return fpow(x, mod-2);
}
int C(int a, int b){
return fac[a]*inv(fac[a-b])%mod*inv(fac[b])%mod;
}
signed main(){
init();
read(n), read(k);
int res;
res=C(2*n-1, n-1);
if(k<n){ // must be a least n-k bits more than 0
rep(i,1,n-k-1) res=((res-C(n, i)*C(n-1, i-1))%mod+mod)%mod;
}
cout<<res;
return 0;
}
F很怪qwq,会补的