A-小天的金银铜铁_牛客小白月赛83 (nowcoder.com)
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
int a,b,c,d,e;
int A,B,C,D;
void solve() {
cin>>a>>b>>c>>d>>e;
cin>>A>>B>>C>>D;
if(A*a+B*b+C*c-D*d>e) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
return 0;
}
B-小天的魔法_牛客小白月赛83 (nowcoder.com)
一开始题目没看明白,题目的意思是一共n+m个魔法,每个魔法都可以用一次,那么肯定是贪心,均从大到小排序
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
const int N=110;
int a[N],b[N];
int n,m,x;
void solve() {
cin>>n>>m>>x;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++) cin>>b[i];
sort(a+1,a+1+n,greater<int>());
sort(b+1,b+1+m,greater<int>());
int ans=0;
for(int i=1;i<=min(n,m);i++){
if(x-b[i]<=0){
cout<<ans+1<<endl;
return;
}
if(a[i]==1){
x-=b[i];
ans++;
}
else{
x-=b[i]*a[i];
ans+=2;
if(x<=0){
cout<<ans<<endl;
return;
}
}
}
if(n<m){
for(int i=m+1;i<=n;i++){
x-=b[i];
ans++;
if(x<=0){
cout<<ans<<endl;
return;
}
}
}
cout<<-1<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
return 0;
}
C-小天的 Minecraft_牛客小白月赛83 (nowcoder.com)
12铜粒合成一个铜镐
还需要一个工作台:4个铜粒或4个银粒或4个金粒
一共3种情况:
16铜粒 (a/16)^16
12铜粒+4银粒 C(16,12)*(a/16)^12*(b/16)^4
12铜粒+4金粒 C(16,12)*(a/16)^12*(c/16)^4
#include<bits/stdc++.h>
#include<cstdio>
#define endl '\n'
#define int long long
using namespace std;
double a,b,c;
int fac[25];
void solve() {
cin>>a>>b>>c;
fac[0]=1;
for(int i=1;i<20;i++) fac[i]=1ll*fac[i-1]*i;//预处理阶乘
double ans=pow(a/16,16)+(double)fac[16]/fac[4]/fac[12]*pow(a/16,12)*(pow(b/16,4)+pow(c/16,4));
printf("%.10f\n",ans);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--) {
solve();
}
return 0;
}