Buggy ICPC (+ thought to play table)

A - Buggy ICPC
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 programming competitions: the Integrated Computer for Programming Contests (ICPC). This computer
has a specialized operating system with commands for submitting code and testing executables on sample 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 a
sequence 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 to T, considering ICPC’s known
bug. Two ways are considered different if they are encoded by different strings. The letters 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 105
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
meaning of the questions: When you have a string type vowel (aeiou), the string will be reversed after entering the vowel. For example, you enter eca, the string will become ace. Now give you a string s, so that you seek the input of how many ways can make final changes to the string s.
Problem-solving ideas: playing table to find the law, classification discussion.
Obviously, the number s is set cnt vowels so

  • cnt = 0. At this way = 1
  • cnt = 1. If s not the first vowel of the word does not hold, way = 0. s, then the first vowel, the vowel corresponding to the first string is inserted into the other consisting of consonants. At this way = strlen (len)
  • cnt> 1 when. It is more difficult to think of a situation. Looking law (hit list) can be found, in addition to the number in the middle of two vowels will affect the way in, others are not affected. way = number + 1 intermediate between two vowels consonants.

Wrong because: Finally, as of the time too nervous, did not discuss the impact of the number of vowels parity intermediate position of two vowels


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define LL long long
#define MT(a,b) memset(a,b,sizeof(a))
const int maxn=2E5+5;
const int ONF=-0x3f3f3f3f;
const int INF=0x3f3f3f3f;
char str[maxn];
int pos[maxn];
int main (){
    scanf("%s",str);
    int ans=0;
    int cnt=0;
    int len=strlen(str);
    for (int i=0;i<len;i++){
        if (str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
            pos[++cnt]=i;
    }
    if (cnt==0) ans=1;
    if (cnt!=0){
        if (str[0]!='a'&&str[0]!='e'&&str[0]!='i'&&str[0]!='o'&&str[0]!='u')
            ans=0;
        else{
            if (cnt==1) ans=len;
            else{
                if (cnt&1) ans=pos[cnt/2+2]-pos[cnt/2+1];
                else ans=pos[cnt/2+1]-pos[cnt/2];
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}
Published 33 original articles · won praise 15 · views 895

Guess you like

Origin blog.csdn.net/weixin_43925900/article/details/103948937