P2911 [USACO08OCT]Bovine Bones G (数学期望,枚举)

题意:

P2911 [USACO08OCT]Bovine Bones G (数学期望,枚举)_第1张图片

解法:

由于数据范围较小,直接暴力枚举所有方案,找出出现次数最多的即可.

code:

#include
typedef long long ll;
#define int long long
using namespace std;
void solve(){
     
    map<int,int>mp;
    int a,b,c;cin>>a>>b>>c;
    for(int i=1;i<=a;i++){
     
        for(int j=1;j<=b;j++){
     
            for(int k=1;k<=c;k++){
     
                mp[i+k+j]++;
            }
        }
    }
    int ma=-1;
    for(auto i:mp){
     
        ma=max(ma,i.second);
    }
    for(auto i:mp){
     
        if(i.second==ma){
     
            cout<<i.first<<endl;
            return ;
        }
    }
}
signed main(){
     
    ios::sync_with_stdio(0);
    int T=1;
    while(T--){
     
        solve();
    }
    return 0;
}

你可能感兴趣的:(P2911 [USACO08OCT]Bovine Bones G (数学期望,枚举))