Acwing.第128场周赛

发布时间 2023-11-05 19:54:55作者: du463

Acwing.第128场周赛

比赛地址

A长方体

题目

思路:

知道长方体的体积计算公式即可,就是一个比较简单的模拟

代码:

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a*b*c<<endl;
	return ;
	
}
int main(){
	int t=1;
	while(t--){
		solve();
	}
	return 0;
}

翻倍

题目

思路:

\[cbrt(a*b)一定是整数 \]

如果不是整数就不行,而且如果要想能凑出a和b,那还得同时是a和b的因子

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
	int a,b;
	cin>>a>>b;
	int x=cbrt((ll)a*b)+1e-8;
	if(x*(ll)x*x==(ll)a*b&&a%x==0&&b%x==0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
		
	}
	
}
int main(){
	int t=1;
	cin>>t;

	while(t--){
		solve();
	}
	return 0;
}

B数量

题目

思路:

这个题不算是很难,用到了排列组合的东西,而且0<=k<=4,所以直接分情况讨论就可以了

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=10;
bool st[N];

typedef long long ll;
ll C(int x,int y){
    ll res=1;
    for(int i=x,j=1;j<=y;i--,j++){
        res=res*i/j;
    }
    return res;

}
int dfs(int x,int y){//最经典的排列问题
    if(x>y){
        return 1;
    }
    int res=0;
    for(int i=1;i<=y;i++){
        if(i!=x&&!st[i]){
            st[i]=true;
            res+=dfs(x+1,y);
            st[i]=false;
        }
  
    }
    return res;

}
void solve(){
    int n,k;
    cin>>n>>k;
    if(k==0){
        cout<<1<<endl;
        return ;
    }
    else if(k==1){
        cout<<1<<endl;
        return ;
    }
    ll ans=1;
    for(int i=2;i<=k;i++){
        // cout<<dfs(1,i)<<endl;
        // cout<<C(n,i)<<endl;//6
        
        ans+=C(n,i)*dfs(1,i);
    }
    cout<<ans<<endl;
    return ;
}
int main(){
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}