Codeforces 798B Mike and strings
来源:互联网 发布:淘宝衣服店铺排名查询 编辑:程序博客网 时间:2024/06/07 07:08
题意:
给出 N 个串,问最少能移动几次使 N 个串都相等。
移动的规则是,每次只能将一个串首的字符移到串尾。
N 最大 50,串长最大 50。
思路:
竟然是暴力题。 50^4 并不超时……
代码:
#include <iostream>#include <cstring>#include <map>#include <string>#include <cstdio>using namespace std;string str[51];int n;int tans,ans,fans,len;int judge(int id){ bool flag; for(int i=0;i<len;i++){ flag=1; for(int j=0;j<len&&flag;j++){ if(str[0][j]!=str[id][(i+j)%len]) flag=0; } if(flag) return i; } return -1;}int solve(){ fans=99999999; string temp; temp=str[1]; temp+=str[1]; len=str[1].size(); for(int i=0;i<len;i++){ str[0]=temp.substr(i,len); tans=0; for(int j=1;j<=n;j++){ ans=judge(j); if(ans==-1) return -1; else tans+=ans; } if(fans>tans) fans=tans; } return fans;}int main(){ ios::sync_with_stdio(false); while(cin>>n){ for(int i=1;i<=n;i++) cin>>str[i]; cout<<solve()<<endl; }}
0 0
- Codeforces 798B Mike and strings
- codeforces 798B Mike and strings
- CodeForces 798B Mike and strings
- codeforces B. Mike and strings
- 小白题解 Codeforces 798B Mike and strings
- codeforces B. Mike and strings 暴力+字符串
- B. Mike and strings
- B. Mike and strings
- B. Mike and strings
- B. Mike and strings
- Mike and strings-codeforces-Round 410-Div2-B
- Codeforces #410(div2) B. Mike and strings (暴力枚举
- CF#798 B. Mike and strings(思维)
- 【CodeFores 798B】 Mike and strings(模拟+string)
- Codefroces 410 B.Mike and strings
- Codeforces Round #410 (Div. 2) B. Mike and strings(字符串匹配)
- Codeforces Round #410 (Div. 2)-B. Mike and strings-string的使用和取模
- Codeforces Round #410 (Div. 2)-B. Mike and strings【STL+略贪心】
- HTML移动DIV
- 优秀程序员不得不知道的20个位运算技巧
- LeetCode 118. Pascal's Triangle
- HDU 2215 Maple trees 凸包问题+最小外接圆
- Android(7)消息通信
- Codeforces 798B Mike and strings
- 二.Java关键字
- opencv3.2.XX 配置+windows7(64bit)+VS2015
- 两个多项式相乘和相加的java实现
- RaspberryPI LITE版本默认无SSH及显示屏下连接
- (扩展)欧几里得算法
- 拟牛顿法之L-BFGS算法
- 凸包问题详解(图解)(转载)
- select 语法+别名的使用+连接运算符+distinct+where+like+转义字符+between+in