PAT1093: Count PAT's
1093. Count PAT's (25)
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.
Now given any string, you are supposed to tell the number of PAT's contained in the string.
Input Specification:
Each input file contains one test case. For each case, there is only one line giving a string of no more than 105 characters containing only P, A, or T.
Output Specification:
For each test case, print in one line the number of PAT's contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007.
Sample Input:
- APPAPT
Sample Output:
- 2
- 思路
- 试了下直接暴搜,果然最后几个测试点超时,看来还是得用dp。
这道题DP的思路就是用两个int数组P[n],T[n]保存第i个字符的左边字母'P'的个数P[i]和右边字母'T'的个数T[i],当遍历到的字符是'A'时,那么以这个A为基础的"PAT"字符串个数就是它左侧P字母个数乘以右侧T字母个数。即P[i]*T[i]
- 代码
- #include<iostream>
- #include<vector>
- using namespace std;
- int main()
- {
- string s;
- while(cin >> s)
- {
- vector<int> P(,);
- vector<int> T(,);
- for(int i = ,j = s.size() - ;i < s.size() && j >= ;i++,j--)
- {
- if(s[i - ] == 'P')
- {
- P[i]++;
- }
- if(s[j + ] == 'T')
- {
- T[j]++;
- }
- P[i] += P[i - ];
- T[j] += T[j + ];
- }
- int sum = ;
- for(int i = ;i < s.size();i++)
- {
- if(s[i] == 'A')
- {
- sum += P[i] * T[i];
- sum %= ;
- }
- }
- cout << sum << endl;
- }
- }
PAT1093: Count PAT's的更多相关文章
- pat1093. Count PAT's (25)
1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...
- PAT 1093 Count PAT's[比较]
1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...
- PAT甲级——1093 Count PAT's (逻辑类型的题目)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分) ...
- PAT_A1093#Count PAT's
Source: PAT A1093 Count PAT's (25 分) Description: The string APPAPT contains two PAT's as substrings ...
- 1093. Count PAT's (25)
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...
- 1093. Count PAT's
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...
- 1093. Count PAT’s (25)-统计字符串中PAT出现的个数
如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...
- 1093 Count PAT's(25 分)
The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...
- PAT (Advanced Level) Practise - 1093. Count PAT's (25)
http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...
随机推荐
- 【Android 应用开发】Ubuntu 下 Android Studio 开发工具使用详解 (旧版本 | 仅作参考)
. 基本上可以导入项目开始使用了 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21035637 ...
- nginx 的编译参数详解
内容有些多,一眼看来难免头昏脑胀,但坚持看完,相信你一定会有所收获. nginx参数: --prefix= 指向安装目录 --sbin-path 指向(执行)程序文件(nginx) --conf-pa ...
- 如何让你的传输更安全--基于SSL协议的通信模式
之前发表在另一个平台的文章http://www.jointforce.com/jfperiodical/article/1218,现在发表到自己的博客上. 对于SSL/TLS协议,如果要每个开发者都自 ...
- 《java入门第一季》二维数组三个案例详解
案例一:遍历二维数组 /* 需求:二维数组遍历 外循环控制的是二维数组的长度,其实就是一维数组的个数行数. 内循环控制的是一维数组的长度,每一行,一维数组元素分别的个数. */ class Array ...
- SpriteBuilder中如何固定两个互不接触的物理物体?
如下图: 这个弹簧装置由3部分组成(从上到下): 弹板 弹簧 弹簧金属底座 其中弹板将固定在弹簧上(但并没有接触,如上图),这就引出一个有趣的问题:怎么样才能将两个独立的物理物体(注意:是物理物体)固 ...
- php opcode缓存
本文移至:http://www.phpgay.com/Article/detail/classid/2/id/61.html 1.什么是opcode 解释器分析代码之后,生成可以直接运行的中间代码,就 ...
- Android UI技巧(一)——Android中伸缩自如的9patch图片切法,没有美工自给自足
Android UI技巧(一)--Android中伸缩自如的点9图片切法,没有美工自给自足 相信大家对.9 图片应该都很熟悉吧,有些人可能自己都会了,此篇献给那些不会的同学,咱们一起来聊聊.9图片的切 ...
- HBase Master启动过程
master启动过程: -->首先初始化HMaster -->创建一个rpcServer,其中并启动 -->启动一个Listener线程,功能是监听client的请求,将请求放入ni ...
- linux下64位汇编的系统调用(1)
现在基本上系统都是64位了,而64位系统下的汇编和32位有了较大的变化,无论是系统调用的接口还是C标准库的接口都和32位汇编有所不同:下面简单谈一下在64位linux下如何利用汇编直接调用系统调用. ...
- Angular v6 正式发布
Angular 6 正式发布 Angular 6 已经正式发布了!这个主要版本并不关注于底层的框架,更多地关注于工具链,以及使 Angular 在未来更容易快速推进. 作为发布的一部分,我们同步了主要 ...