UVALive 7275 Dice Cup (水题)

Dice Cup

题目链接:

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面的骰子.
求出现概率最大的顶面数和.


题解:


直接模拟一遍记录所有顶面数之和.
把出现次数最多的数从小到大输出.


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <list>
#define LL long long
#define eps 1e-8
#define maxn 101000
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;

int cnt[100];

int main(int argc, char const *argv[])
{
    //IN;

    int n, m;
    int flag = 0;
    while(scanf("%d %d", &n,&m) != EOF)
    {
        memset(cnt, 0, sizeof(cnt));

        for(int i=1; i<=n; i++) {
            for(int j=1; j<=m; j++) {
                cnt[i+j]++;
            }
        }

        if(flag) printf("\n");
        flag = 1;

        int ma = 0;
        for(int i=0; i<=n+m; i++) ma = max(ma, cnt[i]);
        for(int i=0; i<=n+m; i++) {
            if(cnt[i] == ma)
                printf("%d\n", i);
        }
    }

    return 0;
}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5769070.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值