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 ...
随机推荐
- Linux系列教程(七)——Linux常用命令之帮助和用户管理命令
上篇博客我们介绍了Linux文件搜索命令,其中find是用的最多的也是功能最强大的文件或目录搜索命令,和另一个搜索命令locate的区别是,find命令是全盘搜索,刚创建的文件也能搜索的到,而loca ...
- 腾讯云COS体验
其实这篇文章本来是推荐COS的,写了一半发现COS的免费额度取消了,2019年之后的开通的用户免费6个月,老用户不受影响,这还让我怎么推荐啊?!写都写了,删掉岂不是白浪费时间? 都怪你!腾讯云! 起因 ...
- CentOS7下安装Docker-Compose操作记录
Docker-Compose是一个部署多个容器的简单但是非常必要的工具.安装Docker-Compose之前,请先安装 python-pip 一.安装 python-pip [root@workben ...
- 《Linux内核分析》第七周笔记 可执行程序的装载
20135132陈雨鑫 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ...
- C++高质量编程笔记
/* * 函数介绍: * 输入参数: * 输出参数: * 返回值 : */ void Function(float x, float y, float z) { - } if (-) { - whil ...
- Daily Scrum 12-25
Meeting Minutes 针对设计师提出的问题完成了layout的微调: 讨论alpha测试反馈反映出的一些问题: 完成了代码的merge(与bing词典 1.5版本): Progress ...
- Redis持久化的两种方式和区别
该文转载自:http://www.cnblogs.com/swyi/p/6093763.html Redis持久化的两种方式和区别 Redis是一种高级key-value数据库.它跟memcached ...
- Vue.directive注册指令
指令定义函数提供了几个钩子函数(可选): vue指令的生命周期 bind: 只调用一次,指令第一次绑定到元素时调用,用这个钩子函数可以定义一个在绑定时执行一次的初始化动作. inserted: 被绑定 ...
- Mybatis源码分析
MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以对配置和原生Map使用简 ...
- [转帖]UML各种图总结-精华
UML各种图总结-精华 https://www.cnblogs.com/jiangds/p/6596595.html 之前自己以为画图很简单 不需要用心学 现在发现自己一直没有学会一些基础的知识 能力 ...