【Codeforces Round #410 (Div. 2) B】暴力

xiaoxiao2021-02-27  200

#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <climits> using namespace std; string s[50], st[50]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { cin >> s[i]; st[i] = s[i]; } int ans = INT_MAX; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < n; j++) { int t = 0; while (s[j] != st[i]) { t++; if (t > s[j].length()) { printf("-1\n"); return 0; } s[j].push_back(s[j][0]); s[j].erase(s[j].begin()); cnt++; } s[j] = st[j]; } ans = min(ans, cnt); } printf("%d\n", ans); return 0; }

就这么一道O(n^4)的大暴力我当时不会写【摊手】愣是连暴力都不会打,都已经开始想dp了我是不是油猫病。

string的一些函数我都不大熟,昨天晚上看了看,惊奇的发现它有find、find_first_of、find_first_not_of等等好多我不知道的函数!我都已经在想啊这个好方便啊是不是kmp都不用写了啊,就被告知“这个太慢了!”“这个比那些所有加起来都要慢!”我。。。。傻得可爱。。。

在判断它能不能变换过去的时候我让它转了一圈,这个时候如果还不相等的话就说明不行了,直接退出输出-1。(这道题有七十多个测试点,妈耶,等得我好紧张)

【最近写什么题什么题调不过,文化课也。。。虽然这是道大水题,但是我一遍过了还是超开心!】

转载请注明原文地址: https://www.6miu.com/read-13807.html

最新回复(0)