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 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

先从两个元音字母的情况入手:acmicpc(a,i),因为只有两个元音字母(只会进行两次反转,那么在前面的元音字母一定后出现),所以要想符合原串,在加上a之前的字符串一定是:icm。此时问题就转换成了:有多少种添加i, c, m的方式,得到icm(cpc则不需处理,因为无法进行翻转)。当i的位置确定后,剩下的位置也就必定确定,所以i有几个摆放位置,就有几种方式。当多个元音字母时可以将问题分解成“1+(n -1)”的形式,仿照处理两个元音字母的方式计算即可。

按上述方法分析,可以找出如下规律:
1.全为辅音:1种
2.只有一个元音,且在开头:n种
3.只有一个元音或多个,开头为辅音:0种
4.多个元音:中间两个元音字符的距离

#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;string s;
set<char> book{ 'a', 'e', 'i', 'o', 'u'};
vector<int> pos;int main()
{int cnt = 0;cin >> s;for (int i = 0; i < s.size(); i++)if (book.find(s[i]) != book.end()){cnt++;pos.push_back(i);}if (cnt == 0) cout << 1 << endl;else if (cnt == 1 && book.find(s[0]) != book.end()) cout << s.size();else if (book.find(s[0]) == book.end()) cout << 0 << endl;else{int p = (pos.size() + 1) / 2;cout <<  pos[p] - pos[p - 1];}return 0;
}

Problem B – Buggy ICPC——思维,找规律相关推荐

  1. CodeForces - 1245C Constanze's Machine(思维+找规律)

    题目链接:点击查看 题目大意:给出一个字符串s,该字符串是由一台坏掉的打字机生成的,坏掉的打字机会将m打成nn,将w打成uu,问现在给出字符串s,其原本的字符串有多少种可能性 题目分析:因为m会变成n ...

  2. Grid game CodeForces - 1104C 放格子|思维|找规律

    题意:4*4的格子中输入0放 2*1的图案输入1放1*2的图案 当摆满一行或一列后此行列图案清空 就想毛熊方块一样 分析:开始感觉很唬人 要搜索还是要dp啥的 后来发现原来2*1就放左下 1*2就放左 ...

  3. 第十五届北京师范大学程序设计竞赛决赛(网络同步赛) B lca水 D 思维,找规律...

    第十五届北京师范大学程序设计竞赛决赛(网络同步赛) B. Borrow Classroom 题意:一棵树,点 1为根,一个人从点 b到 点 c再到点 1,第二个人从点 a出发,问第二个人能否截住第一个 ...

  4. C - Sweets Eating 前缀和 + 思维找规律

    传送门 思路:1.找出最优策略 2.优化代码 最主要的是如何优化代码,我们发现m是一个周期,在m周期类的元素不会受到影响,一旦到达一个周期,那么此时的数值就要整体移一位,这个可以用前缀和来实现. 设d ...

  5. 思维--找规律--Codeforces Round #645 (Div. 2) c题

    C. Celex Update 题目大意:给出两点的坐标,找出不同的路径的总数(路径数字总和不同) 思路:根据观察向下走比向右走的增加幅度加1,所以在第i步 向下 对sum的影响是 n-i+1 所以最 ...

  6. CodeForces - Insertion Sort(打表找规律)

    题目链接:http://codeforces.com/gym/101955/problem/C Time limit:6.0 s Memory limit:1024 MB Problem Descri ...

  7. ACM-ICPC Jiaozuo Onsite 2018 Resistors in Parallel (思维+java大数+找规律)

    题目来源 ACM-ICPC Jiaozuo Onsite 2018 题目粘贴过来有点变化,既然来了肯定见过原题~~嘻嘻~~ In this physics problem, what we are c ...

  8. 翻翻棋(找规律问题)(FZU Problem 2230)

    题目是这样的: FZU Problem 2230 象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将.根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃 ...

  9. codeforces:C. Another Array Problem【分类讨论 + 找规律】

    目录 题目截图 题目分析 ac code 总结 题目截图 题目分析 做cf题目别老想着套算法模版 找规律才是正道,这就是所谓的「思维」 n = 2很简单 n >= 4: # 肯定有一个最大值,不 ...

最新文章

  1. 带你测试对比深度学习框架!TensorFlow,Keras,PyTorch...哪家强?(附数据集)
  2. ionic 项目中添加modal的步骤流程
  3. LOJ#6281. 数列分块入门 5
  4. 【文件系统】删除文件名中含有空格的文件
  5. LeetCode 637 二叉树的层平均值-简单
  6. Freescale i.mx28 Boot-stream分析
  7. android打印机驱动4521,三星scx4521f驱动下载
  8. python学习:包导入教程
  9. [C++]<numeric>头文件介绍
  10. ShaderJoy —— “圆点消散” 的实现 【GLSL】
  11. 国际主流商业BI产品对比分析报告
  12. 如何安装 OneNote for Windows 10 的离线安装包
  13. php 分割验证码,动态验证码字符完美分割(附算法)
  14. html rfftq15.gif,stm32F4固件库
  15. fastJson深拷贝
  16. OpenSSL生成PKCS#8私钥和公钥
  17. 基于ik分词器和布隆过滤器实现敏感词过滤
  18. 【JokerのKCU105】SGMII。
  19. ARM标准汇编与GNU汇编
  20. 这里神一样的重庆,有神一样的建筑

热门文章

  1. 仿微信录制视频和拍照并发送留言
  2. 2018 android最新版本,2008年至2018年,Android系统10年进化史
  3. 51、基于51单片机的GPS定位系统(GSM短信)
  4. L1-057 PTA使我精神焕发 (5 分) 天梯赛 详解
  5. 计算机用户名名称和全民,修改电脑名字_修改电脑用户名
  6. 01-K3S 课程介绍及K3s介绍
  7. PyCharm中安装库失败 ERROR: Could not find a version that satisfies the requirement (from version None)
  8. java arraylist 无序_关于Java:按字母顺序排序arraylist(不区分大小写)
  9. vue.js电商项目--美丽购物街day01首页制作
  10. 谷歌浏览器提示:您要访问的网站包含恶意软件(解决方案)