Codeforces Round #410 (Div. 2) B
B. Mike and strings
Input
Output
input
#include<bits/stdc++.h> using namespace std;
typedef long long LL; const int N = 55;
const int INF = 0x3f3f3f3f; int n;
string S[N]; int Compute(string T,string S)
{
for(int i=0;i<S.size();i++)
{
string W = "";
for(int j = i;j < S.size();++j)
W += S[j];
for(int j = 0; j<=i-1 ;++j)
W += S[j];
if(W == T)
return i;
}
return INF;
} int Check(string T)
{
LL ans = 0;
for(int i = 2;i <= n;++i)
ans += (LL)Compute(T,S[i]);
return ans >= INF ? INF : ans;
} int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
cin>>S[i];
int ans = INF;
for(int i=0;i<S[1].size();++i)
{
string T = "";
for(int j = i;j < S[1].size();++j)
T += S[1][j];
for(int j = 0;j <= i-1;++j)
T += S[1][j];
ans = min(ans,Check(T)+i);
}
printf("%d", ans >= INF ? -1 : ans);
return 0;
}
新发现了个黑科技解法,巨tm简洁,简直不讲道理
#include<iostream>
#include<cstring>
using namespace std; int miner(int x,int y){return x<y?x:y;
} int main()
{
int n,i,j,ans,t;
string a[],temp;
cin>>n;
for(i=;i<=n;i++)
cin>>a[i];
ans=;
for(i=;i<=n;i++)
{
t=;
for(j=;j<=n;j++)
{
temp=a[j]+a[j];
if(temp.find(a[i])==string::npos)
{
cout<<-<<endl;
return ;
}
t+=temp.find(a[i]);
}
ans=miner(ans,t);
}
cout<<ans<<endl;
}
Codeforces Round #410 (Div. 2) B的更多相关文章
- Codeforces Round #410 (Div. 2)
Codeforces Round #410 (Div. 2) A B略..A没判本来就是回文WA了一次gg C.Mike and gcd problem 题意:一个序列每次可以把\(a_i, a_{i ...
- Codeforces Round #410 (Div. 2)C. Mike and gcd problem
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...
- Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #410 (Div. 2)A B C D 暴力 暴力 思路 姿势/随机
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2) A. Mike and palindrome
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2) A
Description Mike has a string s consisting of only lowercase English letters. He wants to change exa ...
- Codeforces Round #410 (Div. 2) A. Mike and palindrome【判断能否只修改一个字符使其变成回文串】
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2)D题
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #410 (Div. 2)C题
C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- 通过chrome浏览器分析网页加载时间
今天趁着下班的时间看了下chrome浏览器的网页加载时间分析工具和相关文档,简单写点儿东西记录一下. 以百度首页加载为例,分析下一张图片1.jgp(就是背景图)的加载时间 看右侧的Timing标签,从 ...
- WPF 滚动文字控件MarqueeControl
原文:WPF 滚动文字控件MarqueeControl WPF使用的滚动文字控件,支持上下左右滚动方式,支持设置滚动速度 XAML部分: <UserControl x:Class="U ...
- Oracle 社区动态、中文讲座,最佳实践
https://community.oracle.com/thread/3789691https://community.oracle.com/community/support/%E4%B8%AD% ...
- python 常见矩阵运算
python 的 numpy 库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入 numpy 的包. 1.numpy 的导入和使用 from numpy import *;#导入numpy的 ...
- Quartz_配置
quartz_jobs.xml job 任务 其实就是1.x版本中的<job-detail>,这个节点是用来定义每个具体的任务的,多个任务请创建多个job节点即可 name(必填) 任务名 ...
- 常见 Bash 内置变量介绍
目录 $0$1, $2 等等$#$* 与 "$*"$@ 与 "$@"$!$_$$$PPID$?$BASH$BASH_VERSION$EUID 与 $UID$GR ...
- 《Linux内核分析》第七周学习笔记
<Linux内核分析>第七周学习笔记 可执行程序的装载 郭垚 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/co ...
- 安装tesserocr错误(未解决)
在win10下使用pip install tesserocr安装时,始终报错,未解决问题 解压tesserocr-2.2.2.tar.gz该文件夹后,查看setup.py文件,发现似乎model只能再 ...
- 第三次Sprint-最后冲刺
由于一些原因,导致我和汝婷被退队了.因此我们是从上星期重新开始做系统. 陈汝婷单独负责: 1.用户输入题目数: 2.限制题数: 3.自动生成用户需要题目数的题目: 4.计时 练丽云单独: 1.异常处理 ...
- github更新,发布地址,燃尽图,总结
github地址:https://github.com/Lingchaoyang 网盘发布地址:http://pan.baidu.com/s/1qXgHiyC 燃尽图: 团队得分(100分制): 杨灵 ...