Gym101889B. Buggy ICPC(打表)

Stella981
• 阅读 525

比赛链接:传送门

题目:

Gym101889B. Buggy ICPC(打表) Gym101889B. Buggy ICPC(打表)

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枚举顺序暴力打表,于是就打了个表。。。猜了个结论。。。

面向结论证明应该还蛮容易的。。

打表代码:

Gym101889B. Buggy ICPC(打表) Gym101889B. Buggy ICPC(打表)

#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

代码:

Gym101889B. Buggy ICPC(打表) Gym101889B. Buggy ICPC(打表)

#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

点赞
收藏
评论区
推荐文章
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Stella981 Stella981
3年前
Jenkins+Ansible+Gitlab自动化部署三剑客
JenkinsAnsibleGitlab自动化部署三剑客小中大showerlee2016031113:00Ansible(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.
Stella981 Stella981
3年前
Codeforces Round #479 (Div. 3) F. Consecutive Subsequence
标签:DP题目链接(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fcodeforces.com%2Fcontest%2F977%2Fproblem%2FF)
Wesley13 Wesley13
3年前
UOJ#351. 新年的叶子 概率期望
原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ351.html题目传送门UOJ351(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fuoj.ac%2Fproblem%2F351)
Wesley13 Wesley13
3年前
2019 ACM
题目链接:Lightbulbs(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fnanti.jisuanke.com%2Ft%2F41399)比赛链接:ThePreliminaryContestforICPCAsiaShanghai2019(https://www.
Stella981 Stella981
3年前
Educational Codeforces Round 73 (Rated for Div. 2)
传送门(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fcodeforces.com%2Fcontest%2F1221)A.2048Game乱搞即可。<details<summaryCode</summaryinclude<bits/std
Easter79 Easter79
3年前
The Complete Guide To Rooting Any Android Phone
PhoneWhitsonGordon(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fwww.lifehacker.com.au%2Fauthor%2Fwhitsongordon%2F)7April,20118:00AMShare(https://ww
Stella981 Stella981
3年前
GYM 101755 K.Video Reviews 【贪心】+【二分】
<题目链接(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fcodeforces.com%2Fgym%2F101755%2Fproblem%2FK)\题目大意:一家公司想让n个人给他们的产品评论,所以依次去找这n个人,第i个人会评论当且仅当已经有ai个人评论或他确
Stella981 Stella981
3年前
85D Sum of Medians
传送门(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fcodeforces.com%2Fcontest%2F85%2Fproblem%2FD)题目Inonewellknownalgorithmoffindingthe_k_\thorderst
Stella981 Stella981
3年前
Jenkins 插件开发之旅:两天内从 idea 到发布(上篇)
本文首发于:Jenkins中文社区(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fjenkinszh.cn)!huashan(https://oscimg.oschina.net/oscnet/f499d5b4f76f20cf0bce2a00af236d10265.jpg)