比赛链接:传送门
题目:
Problem B – Buggy ICPC
Author
: Gabriel Poesia, Brasil
Alan Curing is a famous sports programmer. He is the creator of the theoretical model of computation
known as the Alan Curing Machine (ACM). He’s most famous for creating his own computer for pro-
gramming competitions: the Integrated Computer for Programming Contests (ICPC). This computer
has a specialized operating system with commands for submitting code and testing executables on sam-
ple inputs, an input generator, a wide display for debugging, and a very soft keyboard. However, as it
happens even to the best, Alan’s creation has a nasty bug. Every time Alan types a vowel on the ICPC,
the content of the current line is reversed.
The bug has been extremely hard to track down, so Alan has decided to accept the challenge and
use the computer as it is. He is currently training touch typing on the ICPC. For now, he is only typing
strings using lowercase letters, and no spaces. When Alan types a consonant, it is appended to the end
of the current line, as one would expect. When he types a vowel, however, the typed character is first
added to the end of the line, but right after that the whole line is reversed. For example, if the current
line has “imc” and Alan types “a” (a vowel), for a brief moment the line will become “imca”, but then the bug kicks in and turns the line into “acmi”. If after that he types the consonants “c”, “p” and “c”,in that order, the line becomes “acmicpc”.
When practicing, Alan first thinks of the text he wants to type, and then tries to come up with asequence of characters he can type in order to obtain that text. He is having trouble, however, since he realized that he cannot obtain some texts at all (such as “ca”), and there are multiple ways of obtaining other texts (as “ac”, which is obtained whether he types “
ac” or “ca”). Help Alan in his training by telling him in how many ways he can type each text he wishes to type. A way of typing a text T can
be encoded by a string W with |T| characters such that if the characters are typed on the ICPC in the order they appear in W (i.e.W1, W2, . . . , W|
T|) the final result is equal toT, considering ICPC’s known bug. Two ways are considered different if they are encoded by different strings. The ltters that trigger the bug in the ICPC when typed are “a”, “e”, “i”, “o” and “u”.
Input
The input consists of a single line that contains a non-empty string
T
of at most 10^5
lowercase
letters, representing the text Alan wants to type on the ICPC.
Output
Output a single line with an integer representing the number of distinct ways Alan can type the
desired text
T
considering ICPC’s known bug.
Sample input 1
ac
Sample output 1
2
Sample input 2
ca
Sample output 2
0
Sample input 3
acmicpc
Sample output 3
3
View Code
思路:
一上来就很容易想到用next_premutation枚举顺序暴力打表,于是就打了个表。。。猜了个结论。。。
面向结论证明应该还蛮容易的。。
打表代码:
#include <bits/stdc++.h>
using namespace std;
const char vowel[5] = {'a', 'e', 'i', 'o', 'u'};
int main()
{
string s;
vector <char> V;
while (cin >> s) {
V.clear();
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
V.push_back(s[i]);
}
sort(V.begin(), V.end());
do {
string tmp;
for (int i = 0; i < V.size(); i++) {
tmp += V[i];
for (int j = 0; j < 5; j++) {
if (V[i] == vowel[j]) {
reverse(tmp.begin(), tmp.end());
break;
}
}
}
if (tmp == s) {
for (int i = 0; i < V.size(); i++) {
cout << V[i];
}
cout << endl;
cnt++;
}
}while (next_permutation(V.begin(), V.end()));
cout << cnt << endl << endl;
}
return 0;
}
/*
ac
ca
acmicpc
*/
View Code
代码:
#include <bits/stdc++.h>
using namespace std;
const char vowel[5] = {'a', 'e', 'i', 'o', 'u'};
const int MAX_N = 1e5 + 5;
int N;
char T[MAX_N];
int main()
{
scanf("%s", T);
N = strlen(T);
vector <int> ind;
for (int i = 0; i < N; i++)
for (int j = 0; j < 5; j++) {
if (T[i] == vowel[j]) {
ind.push_back(i);
break;
}
}
int ans = 0;
int pos = -1;
if (ind.size() % 2) {
pos = ind.size()/2;
}
else {
pos = ind.size()/2 - 1;
}
if (pos+1 < ind.size()) {
ans = ind[pos+1] - ind[pos];
}
if (ind.size() == 1) {
ans = N;
}
if (ind.size() == 0) {
ans = 1;
}
else if (ind[0] > 0) {
ans = 0;
}
cout << ans << endl;
return 0;
}
View Code