题意:给一个字符串,将每个字符分开放进两个口袋,每次从两个口袋分别拿出一个字符,如果相同则开心,问开心的次数期望是多少。

分析:数学期望题,然而这是我最不拿手的。。。最后答案是每个字符在字符串出现的次数/字符串长度的和。

 #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的更多相关文章

  1. CF Gym 100187B A Lot of Joy (古典概型)

    题意:给两个一样的只含有26个小写字母的字符串,然后两个分别做一下排列,问如果对应位置的字母相等那么就愉悦值就加一,问愉悦值的期望是多少? 题解:只考虑两个序列相对的位置,那么就相当于固定一个位置,另 ...

  2. 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 ...

  3. Codeforces Gym 100531J Joy of Flight 变换坐标系

    Joy of Flight 题目连接: http://codeforces.com/gym/100531/attachments Description Jacob likes to play wit ...

  4. Gym 100531J Joy of Flight (几何)

    题意:你从开始坐标到末尾坐标,要经过 k 秒,然后给你每秒的风向,和飞机的最大速度,问能不能从开始到末尾. 析:首先这个风向是不确定的,所以我们先排除风向的影响,然后算出,静风是的最小速度,如果这都大 ...

  5. 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 ...

  6. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  7. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  8. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  9. 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 ...

随机推荐

  1. 【HDOJ】1695 GCD

    莫比乌斯反演简单题目. /* 1695 */ #include <iostream> #include <string> #include <map> #inclu ...

  2. how to uninstall devkit

    http://www.uninstallapp.com/article/How-to-uninstall-Perl-Dev-Kit-PDK-8.0.1.289861.html PerfectUnins ...

  3. 【转】 Android快速开发系列 10个常用工具类 -- 不错

    原文网址:http://blog.csdn.net/lmj623565791/article/details/38965311 转载请标明出处:http://blog.csdn.net/lmj6235 ...

  4. [资源共享]C#+AE构建GIS桌面端应用系统框架-全代码

    转自:http://www.cnblogs.com/gispeng/archive/2008/10/06/1304534.html    [资源共享]C#+AE构建GIS桌面端应用系统框架-全代码 ( ...

  5. CG&Game资源(转)

    cg教程下载: http://cgpeers.com http://cgpersia.com http://bbs.ideasr.com/forum-328-1.html http://bbs.ide ...

  6. 城市连动纯js代码DEMO

    前台代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" co ...

  7. C语言 处理文件

    刚学习C语言不久,运用C语言处理各种文件.这里列出,处理文件所需的大部分函数,已经整理的笔记,使用的注意事项.

  8. 【转】Mac OS X 中 Zsh 下 PATH 环境变量的正确设置

    在 Mac OS X 中使用 zsh,环境变量 PATH 一不小心就会变得很紊乱,表现为自己设置的路径总是被放到系统路径之后,部分路径还会有重复.这是我们不太了解 zsh 启动时加载文件的顺序和 Ma ...

  9. 341. Flatten Nested List Iterator

    List里可以有int或者List,然后里面的List里面可以再有List. 用Stack来做比较直观 Iterator无非是next()或者hasNext()这2个方程 一开始我想的是hasNext ...

  10. 升级cocoapods到1.2 beta版本的方法

    最近写Swfit3.0, 要用到一些框架, 然后就用cocoapods嘛, 结果说要cocoapods1.1.0版本才行, 而自己的是cocoapods1.0.1版本的, 所以就想着升级嘛, 结果就遇 ...