【题目链接】:http://codeforces.com/contest/798/problem/B

【题意】

给你n个字符串;
每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去了)
问你最少经过多少次操作可以使得所有字符串都相同;

【题解】

枚举最后每个字符串都变成了哪一个字符串;
然后每个字符串都模拟一下左移的过程;直到相等记录总的移动次数;
或者左移超过了长度的次数;输出不可能能和目标串一样;
记录最小的移动次数就好;

【Number Of WA】

0

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)typedef pair<int,int> pii;
typedef pair<LL,LL> pll;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
const int INF = 21e8;int n,ans=INF;
string s[N],s1[N];int ok(string t)
{rep1(i,1,n)s1[i]=s[i];int temp = 0,len = s1[1].size();rep1(i,1,n){int cnt = 0;while (s1[i]!=t){char t = s1[i][0];s1[i].erase(0,1);s1[i]+=t;cnt++;if (cnt>len+2) return INF;}temp+=cnt;}return temp;
}int main()
{//freopen("F:\\rush.txt","r",stdin);ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf�ͱ�����!cin >> n;rep1(i,1,n) cin >> s[i];rep1(i,1,n){int ju = ok(s[i]);ans = min(ans,ju);}if (ans>=INF)cout <<-1<<endl,0;elsecout << ans << endl;return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626396.html

【codeforces 798B】Mike and strings相关推荐

  1. 【codeforces 798A】Mike and palindrome

    [题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...

  2. 【CodeForces - 798A】Mike and palindrome (回文串,水题,字符串问题)

    题干: Mike has a string s consisting of only lowercase English letters. He wants to change exactly one ...

  3. 【Codeforces - 798C】 Mike and gcd problem(思维,贪心)

    题干: Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, .. ...

  4. 【CodeForces - 798D】Mike and distribution (思维构造,贪心,黑科技)

    题干: Mike has always been thinking about the harshness of social inequality. He's so obsessed with it ...

  5. 【CodeForces - 151D】Quantity of Strings (字符串问题,思维推导,有坑)

    题干: Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one g ...

  6. 【CodeForces - 689B】Mike and Shortcuts(Dijkstra最短路,或者bfs跑状态类似spfa)

    题干: Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bi ...

  7. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  8. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  9. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

最新文章

  1. vant 做表格_Vant List 列表
  2. PHP的各种参数设置ini_set:内存 错误等级 session
  3. codis集群部署实战
  4. 【C++ 学习笔记】 MFC CEdit
  5. ubuntu12 04下django安装略谈
  6. python私有属性怎么定义_Python中定义私有属性的方法是()。
  7. mariadb使用mysql驱动_MariaDB安装与使用
  8. Java中lastValue_在Logstash中为sql_last_value使用表的ID?
  9. 更换 PVE7 软件仓库源和 CT 模板(LXC)源为国内源
  10. shiro将session认证改成token认证_初步学习Shiro框架 第一集
  11. (18)FPGA面试题查找表的原理与结构
  12. 12. GD32F103C8T6入门教程-定时器-3路pwm输出
  13. matlab显示中文乱码的解决办法
  14. 从5.56*45mm NATO弹看塔科夫的数据严谨性
  15. leetcode884. 两句话中的不常见单词(你肯定会被惊呆了)
  16. 销售管理思维是什么 有哪些销售管理思维
  17. 每周一看:16份文档资料,程序员软硬实力全概览,总有一个适合你
  18. 将语雀文档迁移到飞书
  19. php 备份手机通讯录,怎么把手机上的号码复制到SIM卡上
  20. MATLAB获取屏幕分辨率

热门文章

  1. linux logrotate进行日志分割
  2. ORA-27300错误
  3. SharePoint 2010 沙盒开发
  4. 架构师必须补充的能力
  5. 百度飞桨开源Open Images Dataset V5目标检测比赛最好单模型MSF-DET
  6. 视频理解新方向:时域语言定位 综述
  7. 谷歌Auto-DeepLab:自动搜索图像语义分割架构算法开源实现
  8. 奇点汽车黄浴:SLAM的动态地图和语义问题
  9. Java——枚举:优雅而干净的enum
  10. 南邮linux期末考试试题,南邮操作系统试卷及答案.doc