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 ...
随机推荐
- 在线图标制作,格式转换 ICON
在线图标制作,格式转换 https://www.easyicon.net/covert/
- odoo订餐系统之订单设计
订餐系统的主要功能便是用户下单部分,这里我们分为表头mylunch_order和表体mylunch_order_line两张主要的数据表,表头主要记录订单的一些通用信息,比如下单的操作人员 下单日期 ...
- Luogu T29912 fuck
这是QZEZ的Luogu团队中的一道难得的水题,题面和数据都是CJJ dalao出的,然后我就没有太看懂题意. 也是一道经典的割点好题,但需要一定的思维. 首先对于题意,它只需要得到切断的作用就可以了 ...
- CentOS搭建V~P~N服务,实现虚拟专用网络
什么是V-P-N V-P-N即虚拟专用网络,它的功能是:在公用网络上建立专用网络,进行加密通讯. V-P-N网关通过对数据包的加密和数据包目标地址的转换实现远程访问.V-P-N有多种分类方式,主要是按 ...
- Mvc4_ @RenderBody、@RenderPage、@RenderSection用法
一.@RenderBody 当创建基于_Layout.cshtml布局页面的视图时,视图的内容会和布局页面合并,而新创建视图的内容会通过_Layout.cshtml布局页面的@RenderBody() ...
- 【亲测有效】Centos安装完成docker后启动docker报错docker: unrecognized service的两种解决方案
今天在学习Docker的时候 使用yum install docker安装完后启动不了,报错如下: [root@Sakura ~]# service docker start docker: unre ...
- Tomcat通过Memcached实现session共享的完整部署记录
对于web应用集群的技术实现而言,最大的难点就是:如何能在集群中的多个节点之间保持数据的一致性,会话(Session)信息是这些数据中最重要的一块.要实现这一点, 大体上有两种方式:一种是把所有Ses ...
- 个人github链接及git学习心得总结
个人github链接 https://www.github.com/liangjianming/test git学习心得总结 git是一个快速,开源,分布式的版本控制系统. GitHub是一个基于w ...
- debug网页时小问题The source attachment does not contain the source for the file
第一次debug总是出现下图问题,提示我没加源码... The source attachment does not contain the source for the file ... 解决方法: ...
- sublime text3修改默认配置文件是失败的解决方法
如果你修改sublime text3的默认配置文件Preferences.sublime-settings失败,现实的错误信息如下图: 其实根据提示信息就好找问题出在哪里了:权限 要想成功的修改默认配 ...