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


##题解:

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


##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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;

}

UVALive 7275 Dice Cup (水题)的更多相关文章

  1. LightOJ 1248 Dice (III) (水题,期望DP)

    题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...

  2. UVaLive 6608 Cabin Baggage (水题)

    题意:给定四个数代表长宽高和重,问你是不是满足下面条件,长不高于56,宽不宽于45,高不高于25,或者总和不大于125,并且重量不高于7. 析:判断输出就好,注意这个题是或,不要想错了. 代码如下: ...

  3. UVALive 4764 简单dp水题(也可以暴力求解)

    B - Bing it Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status ...

  4. UVaLive 6802 Turtle Graphics (水题,模拟)

    题意:给定一个坐标,和一行命令,按照命令走,问你有多少点会被访问超过一次. 析:很简单么,按命令模拟就好,注意有的点可能走了多次,只能记作一次. 代码如下: #pragma comment(linke ...

  5. UVaLive 6858 Frame (水题)

    题意:给定一个矩形框架,给定一个小矩形,问你能不能正好拼起来. 析:很简单么,就三种情况,如果是1*1的矩形,或者是1*2的一定可以,然后就是上面和下面正好能是小矩形的整数倍,左右是少一,两个就是整数 ...

  6. Argus UVALive - 3135(优先队列 水题一道)

    有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...

  7. UVa 12709 && UVaLive 6650 Falling Ants (水题)

    题意:给定 n 个长方体的长,宽,高,让你求高最大的时候体积最大是多少. 析:排序,用高和体积排序就好. 代码如下: #pragma comment(linker, "/STACK:1024 ...

  8. UVALive 6858——分类讨论&&水题

    题目 链接 题意:对于一个$n \times m$的矩阵的最外一圈,问是否能用$k \times 1$的方块填满 分析 考虑左右两边的情况,分类讨论,切记考虑所有可能的情形. #include< ...

  9. UVALive 6862——结论题&&水题

    题目 链接 题意:求满足$0 \leq x \leq y \leq z \leq m$且$x^j + y^j = z^j, \ j=2 \cdots n$的三元组的对数 分析 由费马大定理:整数$n ...

随机推荐

  1. Android Activity形象描述

    Activity就是形象的说就是一个容器,在里面放置各种控件(按钮,文本,复选框等),就形成了软件的界面~ Activity是可见的,如果不加任何控件的话,那么就像Windows中的空白窗体一样 通过 ...

  2. bzoj2489

    这种题完全可以暴力找规律,暴力打表各种搞法 这里有一篇比较全面的题解:http://acm.uestc.edu.cn/bbs/read.php?tid=3698&page=1&tore ...

  3. UVa 11174 (乘法逆元) Stand in a Line

    题意: 有n个人排队,要求每个人不能排在自己父亲的前面(如果有的话),求所有的排队方案数模1e9+7的值. 分析: <训练指南>上分析得挺清楚的,把公式贴一下吧: 设f(i)为以i为根节点 ...

  4. UVa 11400 Lighting System Design

    题意: 一共有n种灯泡,不同种类的灯泡必须用不同种电源,但同一种灯泡可以用同一种电源.每种灯泡有四个参数: 电压值V.电源费用K.每个灯泡的费用C.所需该种灯泡的数量L 为了省钱,可以用电压高的灯泡来 ...

  5. 获取资源ID

    比如,设置一张gif图片的宽高 gif.setShowDimension((int) CommonUtil.getDimen(R.dimen.gif), (int) CommonUtil.getDim ...

  6. ti processor sdk linux am335x evm /bin/setup-uboot-env.sh hacking

    #!/bin/sh # # ti processor sdk linux am335x evm /bin/setup-uboot-env.sh hacking # 说明: # 本文主要对TI的sdk中 ...

  7. WordPress数据库研究 (转)

    该系列文章将会详细介绍WordPress数据总体的设计思路.详细介绍WordPress10个数据表的设计.并对WordPress系统中涉及的用户信息.分类信息.链接信息.文章信息.文章评论信息.基本设 ...

  8. memcached 最大连接数及其内存大小的设置

    memcached的基本设置: -p 监听的端口-l 连接的IP地址, 默认是本机-d start 启动memcached服务-d restart 重起memcached服务-d stop|shutd ...

  9. Mybatis学习——一对多关联表查询

    1.实体类 public class Student { private int id; private String name; } public class Classes { private i ...

  10. 【应聘】阿里巴巴Java面试题目

    原文地址:http://blog.csdn.net/free0sky/article/details/7927275   一.String,StringBuffer, StringBuilder 的区 ...