BNU29370:Enthusiast
来源:互联网 发布:编程器rt8o9f使用说明 编辑:程序博客网 时间:2024/05/04 08:26
Ryan is an enthusiast of music. For almost all the time, there is a headphone on his ear. In his music player, there are N different songs, and he always plays those songs in random mode, never know what’s going next.
But this morning he finds an incredible fact, the player play one song for three times continuously! He wonders how small the probability this similar things can happen. Given all the song names in the player, and the sequence indicating the song names play successively, calculate the probability it happens.
Input
The first line contains a single integer T, indicating the number of test cases.
Then two integers N and M (1<=N, M<=16) follow, N indicates the number of songs, and M indicated the length of the sequence.
Then N strings follow, indicating the names of the different N songs, and then another M strings, indicating the song names in the sequence Ryan hears. The length of all the string is less than 16, including blanks maybe. You may assume the M names are all from the player list.
Then two integers N and M (1<=N, M<=16) follow, N indicates the number of songs, and M indicated the length of the sequence.
Then N strings follow, indicating the names of the different N songs, and then another M strings, indicating the song names in the sequence Ryan hears. The length of all the string is less than 16, including blanks maybe. You may assume the M names are all from the player list.
Output
For each test case, output the case number first, then the probability rounded to six fractional digits.
Sample Input
2
1 1
Opera
Opera
3 3
The Rainy Day
Hey Jude
Opera
Opera
Opera
Opera
1 1
Opera
Opera
3 3
The Rainy Day
Hey Jude
Opera
Opera
Opera
Opera
Sample Output
Case 1: 1.000000
Case 2: 0.037037
Case 2: 0.037037
题意:给出每首歌的歌名还有唱歌的顺序,求出按给出顺序唱歌的概率
思路:其实很简单,因为每首歌都是独一无二的,所以按照顺序唱,每次唱的那首歌的概率都是一定的
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;char song[100];int main(){ int t,cas = 1,i,n,m; double ans; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(i = 0; i<=n+m; i++) gets(song); ans = 1.0/n; ans = pow(ans,m); printf("Case %d: %.6f\n",cas++,ans); } return 0;}
- BNU29370:Enthusiast
- BNU 29370 Enthusiast
- 十六进制颜色值
- 方法参数传递及方法和构造方法的重载
- Alpha-Beta 剪枝算法
- POJ3252
- hdu1171Big Event in HDU 01背包、多重背包
- BNU29370:Enthusiast
- UVa:200 Rare Order(拓扑排序)
- hdu 4097 简单计算几何
- BNU29373:Key Logger(栈的迭代器使用)
- Dom操作小实例----非常实用,将数据在两个select之间转移
- 深入浅出C++11(6)-- 外部模板
- POJ 3393 Lucky and Good Months by Gregorian Calendar
- 一些常用的短模板
- 在Repeater控件中嵌套Repeater控件(C#)