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面的骰子.
求出现概率最大的顶面数和.
##题解:
直接模拟一遍记录所有顶面数之和.
把出现次数最多的数从小到大输出.
##代码:
``` 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 (水题)的更多相关文章
- LightOJ 1248 Dice (III) (水题,期望DP)
题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...
- UVaLive 6608 Cabin Baggage (水题)
题意:给定四个数代表长宽高和重,问你是不是满足下面条件,长不高于56,宽不宽于45,高不高于25,或者总和不大于125,并且重量不高于7. 析:判断输出就好,注意这个题是或,不要想错了. 代码如下: ...
- UVALive 4764 简单dp水题(也可以暴力求解)
B - Bing it Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status ...
- UVaLive 6802 Turtle Graphics (水题,模拟)
题意:给定一个坐标,和一行命令,按照命令走,问你有多少点会被访问超过一次. 析:很简单么,按命令模拟就好,注意有的点可能走了多次,只能记作一次. 代码如下: #pragma comment(linke ...
- UVaLive 6858 Frame (水题)
题意:给定一个矩形框架,给定一个小矩形,问你能不能正好拼起来. 析:很简单么,就三种情况,如果是1*1的矩形,或者是1*2的一定可以,然后就是上面和下面正好能是小矩形的整数倍,左右是少一,两个就是整数 ...
- Argus UVALive - 3135(优先队列 水题一道)
有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...
- UVa 12709 && UVaLive 6650 Falling Ants (水题)
题意:给定 n 个长方体的长,宽,高,让你求高最大的时候体积最大是多少. 析:排序,用高和体积排序就好. 代码如下: #pragma comment(linker, "/STACK:1024 ...
- UVALive 6858——分类讨论&&水题
题目 链接 题意:对于一个$n \times m$的矩阵的最外一圈,问是否能用$k \times 1$的方块填满 分析 考虑左右两边的情况,分类讨论,切记考虑所有可能的情形. #include< ...
- UVALive 6862——结论题&&水题
题目 链接 题意:求满足$0 \leq x \leq y \leq z \leq m$且$x^j + y^j = z^j, \ j=2 \cdots n$的三元组的对数 分析 由费马大定理:整数$n ...
随机推荐
- iOS开原项目
http://www.lanrenios.com/ios/project/2013/0729/1433.html http://www.cnblogs.com/xiaobaizhu/archive/2 ...
- BZOJ 3123 森林(函数式线段树)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3123 题意: 思路:总的来说,查询区间第K小利用函数式线段树的减法操作.对于两棵树的合并 ...
- SGU 187 - Twist and whirl -- want to cheat
原题地址:http://acm.sgu.ru/problem.php?contest=0&problem=187 太开心啦!!!!这道题从2013年开始困扰我!!今天晚上第四次下定决心把它写一 ...
- BootStrap弹窗
效果图: 注意引入的文件,js文件要在前面 Bootstrap框架中的模态弹出框,分别运用了“modal”.“modal-dialog”和“modal-content”样式,而弹出窗真正的内容都放置在 ...
- inline-block和text-indent在IE6,IE7下同时使用的兼容问题解决方法
在实际应用中,考虑到seo,很多button,icon都要用到inline-block和text-indent来处理,例如: <a href="#">Button< ...
- js自动判断浏览器类型跳转到手机版
//电脑版头部写法:<script language="javascript"> function is_mobile() { var regex_match = /( ...
- win7/8下VirtualBox虚拟共享文件夹设置
1. 安装增强功能包(VBoxGuestAdditions) 打开虚拟机,运行ubuntu,在菜单栏选择"设备->安装增强功能",根据提示即可安装成功(成功后也可 以实现 ...
- CMake实践(1)
简介: 目录结构t1/main.cpp; t1/CMakeLists.txt 说明: main.cpp: #include <stdio.h> int main(){ printf( ...
- Redis源码分析系列
0.前言 Redis目前热门NoSQL内存数据库,代码量不是很大,本系列是本人阅读Redis源码时记录的笔记,由于时间仓促和水平有限,文中难免会有错误之处,欢迎读者指出,共同学习进步,本文使用的Red ...
- HDU1402 A * B Problem Plus FFT
分析:网上别家的代码都分析的很好,我只是给我自己贴个代码,我是kuangbin的搬运工 一点想法:其实FFT就是快速求卷积罢了,当小数据的时候我们完全可以用母函数来做,比如那种硬币问题 FFT只是用来 ...