B. A Lot of Joy

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100187/problem/A

Description

Two boys Gena and Petya wrote on two strips of paper the same string s that consisted of lowercase Latin letters. Then each boy took one strip, cut it into small pieces so that each piece contained exactly one letter and put all pieces into his pocket. After that Gena and Petya repeated the following procedure until their pockets became empty: they took one piece from their pockets and rejoiced if the letters on these pieces were equal.

Determine the expected number of times the boys rejoiced during this process.

Input

The input contains the only string s which was initially written on Gena's and Petya's strips. The string has length between 1 and 200000, inclusively, and consists of lowercase Latin letters.

Output

Output the only real number — the expected number of times Gena and Petya rejoiced during their business. The absolute or relative error of the answer should not exceed 10 - 9.

Sample Input

abc

Sample Output

1.000000000000000

HINT

题意

每个人都有一组相同的字符串,如果同时拿出一样的字符串的话,愉悦值+1,问你愉悦值的期望是多少

题解:

我也不知道为什么答案是这个,我只是随便猜的……

代码:

#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>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200101
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** double dp;
int a[];
int b[];
int main()
{
string s;
cin>>s;
for(int i=;i<s.size();i++)
{
a[s[i]-'a']++;
}
for(int i=;i<s.size();i++)
{
dp+=a[s[i]-'a']*1.0/s.size()*1.0;
}
printf("%.15f",dp);
}

codeforces Gym 100187B B. A Lot of Joy的更多相关文章

  1. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  2. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  3. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  4. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  5. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  6. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  7. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

  8. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

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

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

随机推荐

  1. JAVA多线程一

    介绍 线程是操作系统的最小单位,一个进程可以创建多个线程. 线程有五种状态,分别是新建.就绪.运行.阻塞.死亡状态. 多线程可以提高执行效率,但是如果单线程可以完成的任务,使用多线程反而会增加不必要的 ...

  2. 用Delphi实现文件关联

      文件关联为我们带来很多的方便.Delphi自带有注册表对象TRegistry,可以通过它取得或改变注册表相关键值的内容. Function GetAssociatedExec(FileExt: S ...

  3. 搭建Eclipse、Resin Web开发环境

    搭建Eclipse.Resin Web开发环境 一.当然是安装java开发环境 参看: Java环境的搭建 http://www.cnblogs.com/ghj1976/archive/2010/04 ...

  4. Linux常用文件管理命令

    Command Description cat filename 查看文件内容. cd dirname 改变所在目录. cp file1 file2 复制文件或目录. file filename 查看 ...

  5. maven(一)初步搭建,项目结构

    一.环境准备 java环境, jdk 1.5 以上 MyEclipse集成工具,我装的是8.5 版本 二.快速安装及配置 1.下载maven: http://maven.apache.org/docs ...

  6. 【转】Linux mount/unmount命令

    转自:http://www.cnblogs.com/xd502djj/p/3809375.html 格式:mount [-参数] [设备名称] [挂载点] 其中常用的参数有:-a 安装在/etc/fs ...

  7. 句柄(handle)

    < Back 句柄,在windows编程中用来标识: *.模块(module) *.任务(task) *.实例(instance) *.文件(file) *.内存块(block of memor ...

  8. Linux中的.emacs文件

    刚开始的时候在Windows下使用emacs,那个时候配置 .emacs文件直接去C盘里\Users\(username)\AppData\Roaming 路径下查找就可以了(最开始的时候可以打开em ...

  9. 网上关于sort结构体排序都不完整,我来写一个完整版的 2014-08-09 16:50 60人阅读 评论(0) 收藏

    主要参考sort函数_百度文库, 但是那篇有错误 2.结构体排序,a升,b降,c降 平板视图 打印? 01 #include <iostream> 02 #include <algo ...

  10. hdu 5510 Bazinga

    http://acm.hdu.edu.cn/showproblem.php?pid=5510 Problem Description: Ladies and gentlemen, please sit ...