WHUST 2016 Summer Contest #4 D-Dice Cup

时间:2023-01-18 12:19:12

链接

http://acm.hust.edu.cn/vjudge/contest/127406#problem/D

Description

In many table-top games it is common to use different dice to simulate random events. A “d” or “D”
is used to indicate a die with a specific number of faces, d4 indicating a four-sided die, for example.
If several dice of the same type are to be rolled, this is indicated by a leading number specifying the
number of dice. Hence, 2d6 means the player should roll two six-sided dice and sum the result face
values.
Write a program to compute the most likely outcomes for the sum of two dice rolls. Assume each
die has numbered faces starting at 1 and that each face has equal roll probability.


Input

The input file contains several test cases, each of them as described below.
The input consists of a single line with two integer numbers, N, M, specifying the number of faces
of the two dice.
Constraints:
4 ≤ N, M ≤ 20 Number of faces.


Output

For each test case, a line with the most likely outcome for the sum; in case of several outcomes with
the same probability, they must be listed from lowest to highest value in separate lines.
The outputs of two consecutive cases will be separated by a blank line.


Sample Input

6 6
6 4
12 20

Sample Output

7


5
6
7


13
14
15
16
17
18
19
20
21

题目大意

分别投一个有N面的骰子和一个有M面的的骰子,求出现概率最大的点数之和

解题思路

思路一:由于数据范围不大,所以可以直接记录所有的点数之和出现的次数,然后输出出现次数最多的点数和
思路二:打表找规律,通过打表,我们发现,点数和出现的最多次数不会超过N和M的最小值,所以,只用输出出现次数大于min(N,M)的点                   数和即可
思路三:观察样例,我们发现6+1<=7<=6+1;4+1<=5,6,7<=6+1;……所以,输出的数其实就是N+1到M+1间的所有数(N+1和M+1也要输出)


注意事项

只有两个连续的cases之间才要用空行隔开,所以最后一个case结束之后不需要空行

【代码】

#include <iostream>
using namespace std;
int main()
{
	int n,m,f=1;
	while(cin>>n>>m)
	{
		if(f) 
		   f=0;
		else 
		   cout<<endl;
		for(int i=min(n,m)+1;i<=max(n,m)+1;i++)
		    cout<<i<<endl;
	}
	return 0;
}