codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)
题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率。
用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)的更多相关文章
- Codeforces Round #468 Div. 2题解
		
A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...
 - 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 ...
 - 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)
		
因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...
 - 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 ...
 - 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 ...
 - 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 ...
 - Codeforces Round #468 Div. 1
		
D:首先考虑如果给定白棋位置,如何判断胜负.黑棋获胜需要四个方向都有能贴上白棋的棋子.由于每一轮都必须移动,显然先对平面黑白染色一下,只有与白棋所在格异色的黑棋才需要考虑.考虑让一个黑棋去贴上白棋某个 ...
 - 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 ...
 - Codeforces Round #468 (Div. 2 )D. Peculiar apple-tree_BFS
		
题目简单,不多解释. Code: #include<cstdio> #include<queue> using namespace std; const int maxn = ...
 
随机推荐
- 小试---EF5.0简介
			
简介 实体框架Entity Framework 是 ADO.NET 中的一组支持开发面向数据的软件应用程序的技术.是微软的一个ORM框架.简单的说就是把关系型数据库映射成面向对象模型. 一篇更加详细的 ...
 - Winform 出现“Win已停止工作”解决方法
			
一.错误描述 错误名称如上.整体错误如下: Win已停止工作 二.解决方法: 1.请以管理员身份运行命令:“netsh winsock reset”,重启电脑后再次尝试运行本工具. 2.使用360安全 ...
 - STM32硬件IIC
			
/** * @brief 写一个字节到I2C设备中 * @param * @arg pBuffer:缓冲区指针 * @arg WriteAddr:写地址 * @retval 正常返回1,异常返回0 * ...
 - 各种语言中的可变参数(java、python、c++、javascript)
			
索引: java python c++ js 1.Java public class Animal { // 接受可变参数的方法 void eat(String... Objects) { for ( ...
 - JS四舍五入保留两位小数
			
//四舍五入保留2位小数(若第二位小数为0,则保留一位小数) function keepTwoDecimal(num) { var result = parseFloat(num); if (isNa ...
 - linux内核分析 第五周
			
一.实验相关 1.下载老师最新的menu文件,并在其中添加上周所编写的代码,并运行 下载 添加 运行 2.gdb调试跟踪 gdb设置跟踪文件(先进入linux-3.18.6所在的文件) gdb设置断点 ...
 - VC++ 实现修改文件创建、访问、修改时间属性(转载)
			
转载:http://sunnysab.blog.163.com/blog/static/18037500920134221295425/ struct _FILETIME { //结构体定义 DWOR ...
 - linux如何删除行首的空格
			
答: sed 's/^ *//' jello.txt > hello.txt
 - BZOJ1398: Vijos1382寻找主人 Necklace  字符串最小表示法
			
Description 给定两个项链的表示,判断他们是否可能是一条项链. Input 输入文件只有两行,每行一个由0至9组成的字符串,描述一个项链的表示(保证项链的长度是相等的). Output 如果 ...
 - BZOJ3297: [USACO2011 Open]forgot  DP+字符串
			
Description 发生了这么多,贝茜已经忘记了她cowtube密码.然而,她记得一些有用的信息.首先,她记得她的密码(记为变 量P)长度为L(1 <= L<=1,000)字符串,并可 ...