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 ...
随机推荐
- VC判断当前用户有无Administrator的权限(用EqualSid API函数判断与Admin是否在一个组的Sid)
/************************************************************************/ /* 函数说明:判断有无Administrator ...
- 第三章 传奇的开始--Delphi(附读书笔记)
第三章 传奇的开始--Delphi "是惊世之作的Delphi让Borland重新站了起来,没有当初的Delphi,就没有今日的Borland!" "是Turbo Pas ...
- HTML Jquery;marquee标签
在<网页制作Dreamweaver(悬浮动态分层导航)>中,运用到了jQuery的技术,轻松实现了菜单的下拉.显示.隐藏的效果,不必再用样式表一点点地修改,省去了很多麻烦,那么jQuery ...
- 子查询解嵌套in改写为exists
SELECT * FROM (SELECT pubformdat0_.id id332_, pubformdat0_.domain_id domain2_332_, pubformdat0_.proc ...
- 【HDOJ】2133 What day is it
需要注意数据有效性. #include <stdio.h> #define isLeapYear(y) (y%4==0&&y%100!=0)||(y%400==0) ][] ...
- [转]CharacterController与Rigidbody
From: http://blog.csdn.net/czlilove/article/details/9139103 今天下午碰到个问题纠结了很久:人物加上了Rigidbody并使用了重力,遇到悬崖 ...
- C# config配置文件 自定义节点读取
主要使用:ConfigurationSection IConfigurationSectionHandler已被否决 http://technet.microsoft.com/zh-cn/librar ...
- bzoj 1069 [SCOI2007]最大土地面积(旋转卡壳)
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2277 Solved: 853[Submit][Stat ...
- c语音中打印参数调用层级即call stack, call trace
http://stackoverflow.com/questions/105659/how-can-one-grab-a-stack-trace-in-c There's backtrace(), a ...
- VirtualBox检查更新失败解决办法
5.0————>5.1的更新: 1.VirtualBox5.0检查更新失败 2.官网下载最新版本 3.安装最新版本到原来旧版本的路径下 关键的地方来了:我可是担心坏了,怕安装新版本,会破坏原来已 ...