Game with String

题意:有一个字符串,可以选择从第K位开始,将[K,len(s)-1]的字符都移到前面去,现在给你一个首字母,你可以再选择一位进行观察,然后猜测这个K的值是多少, 现在要求求出能猜对K的概率是多少。

题解:处理出每一个字母开头的第K位是什么字符, 如果这个字符在这个字母中出现的次数为1,那么表示可以通过这一个位置来区分字符串,cnt++,不为一就说明不能区分,那就将上次的计数删除。

代码:

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define max3(a,b,c) max(a,max(b,c))
const int INF = 0x3f3f3f3f;
const LL mod = 1e9+;
typedef pair<int,int> pll;
const int N = 1e5+;
char str[N];
int vis[][];
int Max[N][];
int main(){
scanf("%s", str);
int ans = ;
int len = strlen(str);
for(int to = ; to < len; to++){
memset(vis,,sizeof(vis));
int cnt = ;
for(int i = ; i < len; i++){
int p = str[i]-'a';
int j = i+to;
if(j >= len) j -= len;
if(vis[p][str[j]-'a'] == ) Max[to][p]++, vis[p][str[j]-'a'] = ;
else if(vis[p][str[j]-'a'] == ) {Max[to][p]--, vis[p][str[j]-'a'] = ;}
}
}
for(int j = ; j < ; j++){
int cnt = ;
for(int i = ; i < len; i++){
if(Max[i][j] > cnt) cnt = Max[i][j];
}
ans += cnt;
}
printf("%f",1.0*ans/len);
return ;
}

最新文章

  1. HTTP请求与响应
  2. linux内核升级图文攻略(转)
  3. apache 开启zgip 压缩模式
  4. UDP程序设计
  5. BIP_开发案例10_BI Publisher报表国际化多语言的实现(案例)
  6. paip.mysql备份慢的解决
  7. c#简体繁体转换
  8. linux脚本: makefile以及链接库
  9. 非常不错 Hadoop 的HDFS (Hadoop集群(第8期)_HDFS初探之旅)
  10. composer安装及使用说明和相关原理文档
  11. LABjs、RequireJS、SeaJS 哪个最好用?为什么?- 玉伯的回答
  12. Centos常用命令之:文件操作
  13. ROS_Kinetic_05 ROS基础内容(二)
  14. 只用最适合的!全面对比主流 .NET 报表控件
  15. mysql容灾备份脚本
  16. python实现加密
  17. centos 网卡自动连接
  18. (网页)Angular.js 中 copy 赋值与 = 赋值 区别
  19. MongoDB基础教程系列--目录结构
  20. easyui---表单验证

热门文章

  1. 【MySQL】服务无法启动(Mac)
  2. 【iOS】file not found: .../Build/Products/Debug-iphonesimulator file not found
  3. Golang Context 包详解
  4. 关于Unity 中对UGUI制作任务系统的编程
  5. 在 树莓派(Raspberry PI) 中使用 Docker 运行 aspnetcore/dotnetcore 应用
  6. 本地NTP服务器与客户端配置
  7. tensorflow学习笔记——图像识别与卷积神经网络
  8. Missing artifact XXXXX:jar:1.9.1 解决错误问题
  9. 什么时候使用redis?什么时候使用memcache?
  10. ABP 配置全局数据过滤器 II