Gym 100187B-A Lot of Joy
题意:给一个字符串,将每个字符分开放进两个口袋,每次从两个口袋分别拿出一个字符,如果相同则开心,问开心的次数期望是多少。
分析:数学期望题,然而这是我最不拿手的。。。最后答案是每个字符在字符串出现的次数/字符串长度的和。
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
const int maxn=;
char s[maxn];
int h[maxn];
int main()
{
scanf("%s",s);
int len=strlen(s);
memset(h,,sizeof(h));
for(int i=;i<len;i++){
h[s[i]]+=;
}
double ans=;
for(int i=;i<len;i++){
ans+=h[s[i]]*1.0/(len*1.0);
}
printf("%.9f\n",ans);
return ;
}
Gym 100187B-A Lot of Joy的更多相关文章
- CF Gym 100187B A Lot of Joy (古典概型)
题意:给两个一样的只含有26个小写字母的字符串,然后两个分别做一下排列,问如果对应位置的字母相等那么就愉悦值就加一,问愉悦值的期望是多少? 题解:只考虑两个序列相对的位置,那么就相当于固定一个位置,另 ...
- codeforces Gym 100187B B. A Lot of Joy
B. A Lot of Joy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/proble ...
- Codeforces Gym 100531J Joy of Flight 变换坐标系
Joy of Flight 题目连接: http://codeforces.com/gym/100531/attachments Description Jacob likes to play wit ...
- Gym 100531J Joy of Flight (几何)
题意:你从开始坐标到末尾坐标,要经过 k 秒,然后给你每秒的风向,和飞机的最大速度,问能不能从开始到末尾. 析:首先这个风向是不确定的,所以我们先排除风向的影响,然后算出,静风是的最小速度,如果这都大 ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you are Angry.Think Twice.Act Wise.
Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you ...
随机推荐
- linux使用crontab -e 遇到No space left on device
今天用linux的crontab -e编辑定时脚本的时候.遇到No space left on device的错误. 网上找了半天终于知道原因了,昨天晚上我的一个任务因为路径没写对,到时crontab ...
- POJ_3181_Dollar_Dayz_(动态规划,完全部分和,完全背包)
描述 http://poj.org/problem?id=3181 FJ有n元钱,有k种商品,各为1,2,...,k-1,k元,问有多少种花掉这n元钱的方法. Dollar Dayz Time L ...
- 动态规划(DP计数):HDU 5116 Everlasting L
Matt loves letter L.A point set P is (a, b)-L if and only if there exists x, y satisfying:P = {(x, y ...
- C# Sending data using GET or POST ZZ
In this short article, I'll show you how to send data to a website from a C# application using GET o ...
- PowerDesigner使用总结 转
PowerDesigner使用总结 (友情提示:本博文章欢迎转载,但请注明出处:陈新汉,http://www.blogjava.net/hankchen)一.使用PowerDesigner生成HTML ...
- LRU 缓冲池 (不考虑多线程)
lru:(转)LRU算法的实现 什么是LRU算法? LRU是Least Recently Used的缩写,即最近最少使用页面置换算法,是为虚拟页式存储管理服务的.关于操作系统的内存管理,如何节省利用容 ...
- 一些简单的css和js知识
这几天主要做的是前端网页的调整和页面UI的优化方面的内容.这中间主要是学习了一些基本的HTML和css样式的基本元素的属性.设置行高的line-heght属性,设置窗口的浮动用position属性,设 ...
- HDOJ/HDU 2564 词组缩写(单词缩写)
Problem Description 定义:一个词组中每个单词的首字母的大写组合称为该词组的缩写. 比如,C语言里常用的EOF就是end of file的缩写. Input 输入的第一行是一个整数T ...
- BWT(Burrows-Wheeler Transformation)的讲解及java实现
BWT(Burrows-Wheeler Transformation) 1.什么是BWT 压缩技术主要的工作方式就是找到重复的模式,进行紧密的编码. BWT(Burrows–Wheeler_trans ...
- Hadoop 中 Eclipse 的配置
先启动Hadoop守护进程,进入hadoop安装目录,执行bin/start-all.sh 主要是为了之后能正确测试 Ubuntu中下载安装Eclipse,执行sudo apt-get install ...