比赛链接:传送门

题目:

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 ^
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
ac
Sample output Sample input
ca
Sample output Sample input
acmicpc
Sample output

思路:

  一上来就很容易想到用next_premutation枚举顺序暴力打表,于是就打了个表。。。猜了个结论。。。

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

打表代码:

#include <bits/stdc++.h>

using namespace std;
const char vowel[] = {'a', 'e', 'i', 'o', 'u'}; int main()
{
string s;
vector <char> V;
while (cin >> s) {
V.clear();
int cnt = ;
for (int i = ; i < s.size(); i++) {
V.push_back(s[i]);
}
sort(V.begin(), V.end());
do {
string tmp;
for (int i = ; i < V.size(); i++) {
tmp += V[i];
for (int j = ; j < ; j++) {
if (V[i] == vowel[j]) {
reverse(tmp.begin(), tmp.end());
break;
}
}
}
if (tmp == s) {
for (int i = ; i < V.size(); i++) {
cout << V[i];
}
cout << endl;
cnt++;
}
}while (next_permutation(V.begin(), V.end()));
cout << cnt << endl << endl;
}
return ;
}
/*
ac
ca
acmicpc
*/

代码:

#include <bits/stdc++.h>

using namespace std;
const char vowel[] = {'a', 'e', 'i', 'o', 'u'};
const int MAX_N = 1e5 + ; int N;
char T[MAX_N]; int main()
{
scanf("%s", T);
N = strlen(T);
vector <int> ind;
for (int i = ; i < N; i++)
for (int j = ; j < ; j++) {
if (T[i] == vowel[j]) {
ind.push_back(i);
break;
}
} int ans = ;
int pos = -;
if (ind.size() % ) {
pos = ind.size()/;
}
else {
pos = ind.size()/ - ;
} if (pos+ < ind.size()) {
ans = ind[pos+] - ind[pos];
}
if (ind.size() == ) {
ans = N;
}
if (ind.size() == ) {
ans = ;
}
else if (ind[] > ) {
ans = ;
} cout << ans << endl; return ;
}

Gym101889B. Buggy ICPC(打表)的更多相关文章

  1. 2017-2018 ACM-ICPC Latin American Regional Programming Contest Solution

    A - Arranging tiles 留坑. B - Buggy ICPC 题意:给出一个字符串,然后有两条规则,如果打出一个辅音字母,直接接在原字符串后面,如果打出一个元音字母,那么接在原来的字符 ...

  2. 2017-2018 ACM-ICPC Latin American Regional Programming Contest PART (11/13)

    $$2017-2018\ ACM-ICPC\ Latin\ American\ Regional\ Programming\ Contest$$ \(A.Arranging\ tiles\) \(B. ...

  3. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)

    ///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...

  5. ACM/ICPC 之 最短路-SPFA+正逆邻接表(POJ1511(ZOJ2008))

    求单源最短路到其余各点,然后返回源点的总最短路长,以构造邻接表的方法不同分为两种解法. POJ1511(ZOJ2008)-Invitation Cards 改变构造邻接表的方法后,分为两种解法 解法一 ...

  6. ACM/ICPC 之 数据结构-邻接表+BFS(TSH OJ-无线广播Broadcast)

    这道题中若能够构成互不干扰的区域,其构成的图其实就是汉密尔顿路(Hamilton road),因此如果能够观察出来可以直接转化为汉密尔顿路的存在性证明,即便不能观察,我相信ACMer也能转化为BFS问 ...

  7. ACM/ICPC 之 数据结构-邻接表+DP+队列+拓扑排序(TSH OJ-旅行商TSP)

    做这道题感觉异常激动,因为在下第一次接触拓扑排序啊= =,而且看了看解释,猛然发现此题可以用DP优化,然后一次A掉所有样例,整个人激动坏了,哇咔咔咔咔咔咔咔~ 咔咔~哎呀,笑岔了- -|| 旅行商(T ...

  8. ACM/ICPC 之 数论-素数筛选法 与 "打表"思路(POJ 1595)

    何为"打表"呢,说得简单点就是: 有时候与其重复运行同样的算法得出答案,还不如直接用算法把这组数据所有可能的答案都枚举出来存到一个足够大的容器中去-例如数组(打表),然后再输入数据 ...

  9. HDU 5878 I Count Two Three (打表+二分查找) -2016 ICPC 青岛赛区网络赛

    题目链接 题意:给定一个数n,求大于n的第一个只包含2357四个因子的数(但是不能不包含其中任意一种),求这个数. 题解:打表+二分即可. #include <iostream> #inc ...

随机推荐

  1. 剑指offer(54)字符流中第一个不重复的数字

    题目描述 请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字符流中读出 ...

  2. 使用Java或 JavaScript获取 方括号中的内容

    1.使用Java获取方括号中的内容 String str = "[你]们,[我]们,[他]们,都要[好好学习,天天敲代码]"; Pattern p = Pattern.compil ...

  3. Learning-Python【3】:Python中的基本运算符

    一.算数运算 二.比较(关系)运算 比较运算只能在同类型之间进行,其中 int 与 float 同属于数字类型 三.赋值运算 1.增量赋值 2.链式赋值 3.交叉赋值 交换两个数的值,通常要借助第三个 ...

  4. [POI1999][LOJ10112]原始生物

    典型的有向图K笔画的问题 最后答案就是n+1-1+k 1笔画有一点入度比出度少1 k笔画则统计入度比出度少的点中所有少的总和 #include<bits/stdc++.h> using n ...

  5. Docker应用

    1.tomcat容器创建 docker run -d --name Jdd_tomcat  -p 8081:8080 tomcat [root@localhost etc]# docker run - ...

  6. maven 如何使用

    以前没有用过maven管理过项目的依赖,最后使用上了maven,发现通过不能方式建立出来的web应用程序目录结构基本都不一样,既然每次都要到网上搜索如何建立maven管理的Web应用程序,不如自己找百 ...

  7. SpringMVC 拦截器HandlerInterceptor(一)

    HandlerInterceptor 接口: 进入 Handler方法之前执行比如身份认证,如果认证通过表示当前用户没有登陆,需要此方法拦截不再向下执行 boolean preHandle(HttpS ...

  8. 20175317 《Java程序设计》第三周学习总结

    20175317 <Java程序设计>第三周学习总结 教材学习内容总结 第三周我学习了教材第四章的内容,了解了Java中的部分常用语句,学到了以下内容: 明白了什么是类,成员变量有哪些,什 ...

  9. 第K个幸运数字(4、7)

    题目:4和7是两个幸运数字,我们定义,十进制表示中,每一位只有4和7两个数的正整数都是幸运数字,前几个幸运数字为:4,7,44,47,74,77,444,447······输出第K个数字. 思路是:将 ...

  10. 精确率、准确率、召回率和F1值

    当我们训练一个分类模型,总要有一些指标来衡量这个模型的优劣.一般可以用如题的指标来对预测数据做评估,同时对模型进行评估. 首先先理解一下混淆矩阵,混淆矩阵也称误差矩阵,是表示精度评价的一种标准格式,用 ...