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 ...
随机推荐
- 如何利用”七牛云”在UEditor实现图片的上传和浏览
在学习之前,我参考了朋友些的一篇关于这个功能实现的文章,非常不错.大家可以参考:http://www.cnblogs.com/John-Marnoon/p/5818528.html#3501846 里 ...
- [06] JSTL标准标签库
1.JSTL概述 之前在<[03-01] JSP自定义标签>中已经说明了自定义标签的概况,而JSTL也是一套标签库,不过是厂商已经定义好的标签库,我们不再需要自行进行定制,直接使用即可. ...
- python 知识
def action_cancel_sale_order(self,cr,uid,ids,context=None): self.message_post(cr, uid, ids, body=u&q ...
- Codechef MGCHGYM Misha and Gym 容斥、背包、Splay
VJ传送门 简化题意:给定一个长度为\(N\)的数列,\(Q\)个操作: \(1\,x\,a\).将数列中第\(x\)个元素改为\(a\) \(2\,l\,r\).反转子序列\([l,r]\) \(3 ...
- 在属性property做一些简单的验证
开发C#的程序,写到属性property时,我们可以在Set方法中做一些简单的规则验证: 如下面,Insus.NET写一个Age属性,只允许用户输入10以内的数字: class AA { privat ...
- bitcoin 源码解析 - 交易 Transaction(二) - 原理篇
这篇文章我断断续续写了呃···· 应该快三个星期了? 所以前后的风格可能差别相当大.真是十分的怠惰啊··· 最近实在是不够努力.用python重写bitcoin的项目也卡在网络编程部分(这方面真是我的 ...
- 汇编 指令lodsb,lodsw,lodsd
知识点: 汇编指令 lodsb,lodsw,lodsd 一.汇编指令LODSB //scasb scasw scasd //stosb stosw stosd 1. __asm lodsb //作用 ...
- Linux-C-Program:makefile
注:本文参照博客:https://blog.csdn.net/initphp/article/details/7692923 1. 概述2. 示例说明2.1 无makefile编译2.2 有makef ...
- Ubuntu14.04安装PyMuPDF
最近写的一个东西需要将pdf转成图片然后放在网页上展示,找到了个非常好用的轮子叫做PyMuPDF,在windows上测试的时候跑的666,在ubuntu上安装依赖的时候,简直万脸懵逼.github上给 ...
- Week 2 代码规范
Question 1: 这些规范都是官僚制度下产生的浪费大家的编程时间.影响人们开发效率, 浪费时间的东西. My opinion: 我认为恰恰相反,这个可以提高人们的开发效率. 在团队合作当中,如果 ...