Bessie loves board games and role-playing games so she persuaded Farmer John to drive her to the hobby shop where she purchased three dice for rolling. These fair dice have S1, S2, and S3 sides
respectively (2 <= S1 <= 20; 2 <= S2 <= 20; 2 <= S3 <= 40).
Bessie rolls and rolls and rolls trying to figure out which three-dice sum appears most often.
Given the number of sides on each of the three dice, determine which three-dice sum appears most frequently. If more than one sum can appear most frequently, report the smallest such sum.
POINTS: 70
* Line 1: Three space-separated integers: S1, S2, and S3
* Line 1: The smallest integer sum that appears most frequently when the dice are rolled in every possible combination.
贝茜喜欢玩棋盘游戏和角色扮演游戏,所以她说服了约翰开车带她去小商店.在那里她买了三个骰子。这三个不同的骰子的面数分别为 s_1,s_2,s_3s1,s2,s3。
对于一个有 SS 个面的骰子每个面上的数字是 1,2,3,\ldots,S1,2,3,…,S。每个面(上的数字)出现的概率均等。贝茜希望找出在所有“三个面上的数字的和”中,哪个和的值出现的概率最大。
现在给出每个骰子的面数,需要求出哪个所有“三个面上的数字的和”出现得最频繁。如果有很多个和出现的概率相同,那么只需要输出最小的那个。
数据范围: 2\le s_1\leq 202≤s1≤20,2 \leq s_2\leq 202≤s2≤20,2 \leq s_3\leq 402≤s3≤40。
输入 #1复制
3 2 3
输出 #1复制
5
#include<iostream>
using namespace std;
int main()
{
int a1, a2, a3;
cin >> a1 >> a2 >> a3;
int i, j, k,m;
int num[100][2], sum = 0, answer;
for (i = 0; i < 100; i++)
{
for (j = 0; j < 2; j++)
{
num[i][j] = 0;
}
}
for (i = 1; i <= a1; i++)
{
for (j = 1; j <= a2; j++)
{
for (k = 1; k <= a3; k++)
{
int plus = i + j + k;
for (m = 0; num[m][0] != 0; m++)
{
if (plus == num[m][0])
{
num[m][1]++;
plus = 0;
break;
}
}
if (plus != 0)
{
num[m][0] = plus;
num[m][1]++;
}
}
}
}
for (i = 0; num[i][0] != 0; i++)
{
if (num[i][1] > sum)
{
sum = num[i][1];
answer = num[i][0];
}
else if (num[i][1] > sum && answer < num[i][0])
{
answer = num[i][0];
}
}
cout << answer;
return 0;
}