拼多多 骰子 可能解法
我太菜了。。。一直做不出来,考完了调试好了
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <vector> #include <iomanip> #include <algorithm> using namespace std; int main(void) { int N; cin >> N; vector<int> data(N+1,0); long long sum = 1; for (int i = 1; i < N+1; ++i) { cin >> data[i]; sum *= data[i]; } sort(data.begin(), data.end()); double expret = 1.0; //cout << expret << endl; for (int i = 2; i <= data[data.size()-1]; ++i) { double iret = 1; double inum = 0, isma=1,ilit=0; for (int j = 1; j <= N; ++j) { if (data[j] >= i) {inum++;} else { isma*=data[j]; } } iret = i*(2 * inum - 1)*isma; expret += iret; } cout <<fixed<< setprecision(2)<<expret / sum << endl; system("pause"); return 0; }#拼多多##笔试题目##题解#