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

用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. HTTP 协议入门

    本文转载自:http://www.ruanyifeng.com/blog/2016/08/http.html HTTP 协议是互联网的基础协议,也是网页开发的必备知识,最新版本 HTTP/2 更是让它 ...

  2. tomcat和jetty区别

    参见:https://www.cnblogs.com/fengli9998/p/7247559.html 1. Jetty更轻量级.这是相对Tomcat而言的. 由于Tomcat除了遵循Java Se ...

  3. Finalize和Dispose的区别

    https://www.cnblogs.com/Jessy/articles/2552839.html

  4. div居中布局

    利用margin属性可以实现div居中布局,把div的左边距和右边距设置为auto即可,代码如下 <!DOCTYPE html> <html> <head> < ...

  5. 开发代码code中变量替换

    除了automake/autoconfig 之外,还有其他的替换方式. 参看vdsm https://github.com/oVirt/vdsm/blob/master/Makefile.am htt ...

  6. inotify工具安装配置

    一.安装 1)  从内核和目录里面查看是否支持inotify [root@nfs01 ~]# uname -r 2.6.32-573.el6.x86_64 [root@nfs01 ~]# ls -l ...

  7. liunx查询进程下的线程

    问题:一个进程下面会启动多个线程,通过top命令可以查出某个进程cpu,内存使用情况等信息,但无法知道是哪个线程. 解决方法: 1. 用jstack打印出给定的java进程ID的Java堆栈信息(js ...

  8. String和int互相转换,String转float

    String-->int int a=Integer.parseIn(str); int-->String String s= a+""; String-->fl ...

  9. 完美解决vim在终端不能复制的问题

    以前 用xshell,或者其他工具ssh到远程服务器,vim不能复制,搜索说是vim的 -xterm_clipboard没有开启. 今天发现,至少鼠标复制是不需要这个东东的! 在stackoverfl ...

  10. Linux命令中:rsync和cp之间的区别

    rsync:只拷贝那些更新的文件: cp -u:也可以实现类似效果: 两者都基本可以满足备份的需求: 只是一般情况下,用rsync做这类备份之类的事情,更多见: 在备份的操作中,拷贝,过期文件的删除是 ...