题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率。

用map记录每个字母出现的位置。对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数。对每个j数arr[j]中arr[j][k]等于1的个数,取最大,说明k取这个时区分该字母的概率最大。统计所有字母的该值除以字符串长度即为结果。

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
bool vst[];
set<int> st[];
short cnt[SZ][]; double work(int n,const string &str)
{
int res=;
for(int i=;i<;++i)
{
if(st[i].size()==)continue;
memset(cnt,,sizeof(cnt));
for(auto it=st[i].begin();it!=st[i].end();++it)
{
int pos=*it;
for(int j=;j<n;++j)
{
++cnt[j][str[(pos+j)%n]-'a'];
}
}
int maxv=;
for(int j=;j<n;++j)
{
maxv=max(maxv,(int)count(cnt[j],cnt[j]+,));
}
res+=maxv;
}
//cout<<res<<" "<<str.size()<<endl;
return (double)res/str.size();
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
//for(;scanf("%d",&n)!=EOF;)
{
string str;
cin>>str;
for(int i=;i<str.size();++i)
{
st[str[i]-'a'].insert(i);
}
cout<<fixed<<setprecision()<<work(str.size(),str)<<endl;
}
return ;
}

codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)的更多相关文章

  1. Codeforces Round #468 Div. 2题解

    A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup

    The last stage of Football World Cup is played using the play-off system. There are n teams left in ...

  3. 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)

    因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...

  4. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)D. Peculiar apple-tree

    In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity ...

  5. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work

    Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some v ...

  6. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. Friends Meeting

    Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the ...

  7. Codeforces Round #468 Div. 1

    D:首先考虑如果给定白棋位置,如何判断胜负.黑棋获胜需要四个方向都有能贴上白棋的棋子.由于每一轮都必须移动,显然先对平面黑白染色一下,只有与白棋所在格异色的黑棋才需要考虑.考虑让一个黑棋去贴上白棋某个 ...

  8. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)

    A.B都是暴力搞一搞. A: #include<bits/stdc++.h> #define fi first #define se second #define mk make_pair ...

  9. Codeforces Round #468 (Div. 2 )D. Peculiar apple-tree_BFS

    题目简单,不多解释. Code: #include<cstdio> #include<queue> using namespace std; const int maxn = ...

随机推荐

  1. Python: ord()函数

    ch() , unichr() , ord() ①chr()函数用一个范围在range(256)内的整数作参数,返回一个对应的字符. >>>chr(65) 'A' ②unichr() ...

  2. troubleshooting-windows 在 CDH集群环境读取 Hive 表 KrbException: Cannot locate default realm

    KrbException: Cannot locate default realm 解决办法 1)拷贝需要组件的配置文件到项目中的 /resources/目录.如hadoop,目录/etc/hadoo ...

  3. win10 nodejs指定ionic版本安装(npm方式)

    步骤1 node-v6.11.3-x64.msi 下载安装node-v6.11.3-x64.msi, 安装完成后利用cmd通过npm安装 ionic cordova cmd npm install - ...

  4. 20145122《JAVA开发环境的熟悉》实验报告

    package fib; public class fibonaci { public static void main(String[] args) { Fibonaci(20); } public ...

  5. JQuery插件模板

    (function($){ $.fn.插件名 = function(settings){ var defaultSettings = { } /* 合并默认参数和用户自定义参数 */settings ...

  6. Python3基础 list 索引查看元素

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. 安装Qt5.9

    目前,作为一个重量级编程开发工具,Qt 已经正式发布了 5.9.0 版本.相比之前的 5.7,5.8 版本,新版本在性能和功能上有了大幅改善和提高,并由此获得了官方的明确表态:这将是继 5.6 之后的 ...

  8. PHP Extension

    新手搞PHP ,之前用过 PERL, BASH: 所以开始用PHP 写程序上手比较快, 几天之后对PHP 的内部实现机制产生了兴趣,所以自己尝试着写写简单的PHP 扩展,以增加对PHP 的理解.   ...

  9. 将DevExpress.Utils.ImageCollection变量的image导出

    private void tspBtnExportExcel_Click(object sender, EventArgs e) { //暂时用来导出图片 string filePath = Syst ...

  10. 【第二十四章】 springboot注入servlet

    问:有了springMVC,为什么还要用servlet?有了servlet3的注解,为什么还要使用ServletRegistrationBean注入的方式? 使用场景:在有些场景下,比如我们要使用hy ...