题目

Vasya and Kolya play a game with a string, using the following rules. Initially, Kolya creates a string s, consisting of small English letters, and uniformly at random chooses an integer k from a segment [0, len(s) - 1]. He tells Vasya this string s, and then shifts it k letters to the left, i. e. creates a new string t = sk + 1sk + 2... sns1s2... sk. Vasya does not know the integer k nor the string t, but he wants to guess the integer k. To do this, he asks Kolya to tell him the first letter of the new string, and then, after he sees it, open one more letter on some position, which Vasya can choose.

Vasya understands, that he can't guarantee that he will win, but he wants to know the probability of winning, if he plays optimally. He wants you to compute this probability.

Note that Vasya wants to know the value of k uniquely, it means, that if there are at least two cyclic shifts of s that fit the information Vasya knowns, Vasya loses. Of course, at any moment of the game Vasya wants to maximize the probability of his win. 

分析

题目中说,告诉Vasya新串的第一个字符,然后Vasya再找一个字符,来判断这个新串。那么我们把相同字母开头的串全部找出来,然后在这些串中找一个位置i,使得在i位置字符不同的串最多。代码写得很烂,有空得学习一下cf上大佬们的代码习惯了

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std;
const int maxn=+;
char s[maxn];
int n;
int num[];
int vis[maxn][];
char code[maxn][maxn];
int main(){
scanf("%s",s);
n=strlen(s);
for(int i=;i<n;i++)
num[s[i]-'a']++;
int ans=;
for(int k=;k<;k++){
if(num[k]){
int c=k;
int all=;
memset(code,,sizeof(code));
memset(vis,,sizeof(vis));
for(int i=;i<n;i++){
if(s[i]-'a'==c){
all++; for(int j=i;j<n;j++){
vis[j-i][s[j]-'a']++;
code[all][j-i]=s[j];
}
for(int j=;j<i;j++){
vis[j+n-i][s[j]-'a']++;
code[all][j+n-i]=s[j];
}
}
}
int sum=;
for(int i=;i<n;i++){
int tem=;
for(int j=;j<=all;j++){
if(vis[i][code[j][i]-'a']==)
tem++;
}
sum=max(sum,tem);
}
ans+=sum;
}
}
printf("%.15f\n",(double)ans/n); return ;
}

codeforce468DIV2——E. Game with String的更多相关文章

  1. 透过WinDBG的视角看String

    摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...

  2. JavaScript String对象

    本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...

  3. ElasticSearch 5学习(9)——映射和分析(string类型废弃)

    在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...

  4. [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密

    string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...

  5. js报错: Uncaught RangeError: Invalid string length

    在ajax请求后得到的json数据,遍历的时候chrome控制台报这个错误:Uncaught RangeError: Invalid string length,在stackoverflow查找答案时 ...

  6. c# 字符串连接使用“+”和string.format格式化两种方式

    参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...

  7. 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed

    之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...

  8. JavaScript中String对象的方法介绍

    1.字符方法 1.1 charAt() 方法,返回字符串中指定位置的字符. var question = "Do you like JavaScript?"; alert(ques ...

  9. 在多线程编程中lock(string){...}隐藏的机关

    常见误用场景:在订单支付环节中,为了防止用户不小心多次点击支付按钮而导致的订单重复支付问题,我们用 lock(订单号) 来保证对该订单的操作同时只允许一个线程执行. 这样的想法很好,至少比 lock( ...

随机推荐

  1. [置顶] Android 关于ToolBar分分钟玩死自己?

    场景一: 今天早上十点高高兴兴的跟平时早上一样买一杯粥然后一边喝着一边去上班,步行了15分钟到了公司,然后打指纹开门,然后就愉快的写代码了,我擦,好想电脑没开机,我晕好像没带眼镜,发现最近记性不是很好 ...

  2. Android 进阶9:进程通信之 AIDL 解析

    读完本文你将了解: AIDL AIDL 生成文件分析 Stub Proxy AIDL 生成的内容小结 AIDL 的使用回顾 服务端 客户端 小结 手动写个 Binder 首先是定义跨进程接口实现 II ...

  3. Android 蓝牙 socket通信

    Android中蓝牙模块的使用 使用蓝牙API,Android应用程序能够执行以下功能: 扫描其他蓝牙设备查询本地已经配对的蓝牙适配器建立RFCOMM通道通过服务发现来连接其他设备在设备间传输数据管理 ...

  4. laravel 框架给数组分页

    //Get current page form url e.g. &page=6        $currentPage = LengthAwarePaginator::resolveCurr ...

  5. CVS winCVS配置讲解及用户管理

    首先 用到工具包包括 CVSNT ,WinCvs及相关python 2.2.3和TCL832 可点此链接下载 http://files.cnblogs.com/lppblogs/%E6%96%87%E ...

  6. bzoj 4448 情报传递

    Written with StackEdit. Description 奈特公司是一个巨大的情报公司,它有着庞大的情报网络.情报网络中共有\(n\)名情报员.每名情报员能有若干名(可能没有)下线,除\ ...

  7. HBase错误大全

    1. stopping hbasecat: /tmp/hbase-root-master.pid: No such file or directory 原因:hadoop的pid文件丢失,hadoop ...

  8. 有状态与无状态 cookie session

    服务器所维护的与客户交互活动的信息称为状态信息.不保存任何状态信息的服务器称为无状态服务器(stateless server),反之则称为有状态服务器(stateful server). 面向连接对应 ...

  9. Mapreduce shuffle和排序

    Mapreduce为了确保每个reducer的输入都按键排序.系统执行排序的过程-----将map的输出作为输入传给reducer 称为shuffle.学习shuffle是如何工作的有助于我们理解ma ...

  10. laravel 中config的使用

    在laravel的config中添加配置文件(比如:alipay.php)文件内容为return数组的形式 在方法中使用config()函数获取数据 $config = config('alipay. ...