1093. Count PAT's (25)

时间限制
120 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CAO, Peng

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的更多相关文章

  1. pat1093. Count PAT's (25)

    1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...

  2. PAT 1093 Count PAT's[比较]

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

  3. PAT甲级——1093 Count PAT's (逻辑类型的题目)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93389073 1093 Count PAT's (25 分)   ...

  4. PAT_A1093#Count PAT's

    Source: PAT A1093 Count PAT's (25 分) Description: The string APPAPT contains two PAT's as substrings ...

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

  6. 1093. Count PAT's

    The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and ...

  7. 1093. Count PAT’s (25)-统计字符串中PAT出现的个数

    如题,统计PAT出现的个数,注意PAT不一定要相邻,看题目给的例子就知道了. num1代表目前为止P出现的个数,num12代表目前为止PA出现的个数,num123代表目前为止PAT出现的个数. 遇到P ...

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

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

随机推荐

  1. [前端]Emmet 基本语法快查

    Emmet 是一种快速写html的语法,通过几个简单的缩写,就可以拓展成html标签,工作中写html多多少少会有一些,使用的语法都是基础语法,这里总结下最常用的几个,备查. 这个插件支持非常多的ID ...

  2. SpriteBuilder中关于大量CCB文件的数字命名建议

    开发者总是频繁的填充文件名字使用额外的0,以此来对抗长久以来的长痘:数字排序.如果你觉得在数字名字前添加额外的0是一个好主意,比如说Level0001,因为可能你会创建数以千记的关卡--请不要这样做! ...

  3. C语言之将无符号字符型转化为ascii码值

    这个宏是在linux内核中获取的,主要的功能是能够将一个无符号字符型的参数转化为ASCII码值. ASCII : ASCII 编码里包括了128个字符.用 十进制 0  到 127 来表示 .那就对了 ...

  4. 有引用外部jar包时(J2SE)生成jar文件

    一.工程没有引用外部jar包时(J2SE) 选中工程---->右键,Export...--->Java--->选择JAR file--->next-->选择jar fil ...

  5. OpenCV——PS 图层混合算法 (二)

    具体的算法原理可以参考 PS图层混合算法之二(线性加深,线性减淡,变亮,变暗) // PS_Algorithm.h #ifndef PS_ALGORITHM_H_INCLUDED #define PS ...

  6. nasm预处理器(2)

    多行宏 %macro: %macro foo 2 push rax push rbx mov rax,%1 mov rbx,%2 pop rbx pop rax %endmacro 宏名称后的数字代表 ...

  7. 解决 RabbitMQ 集群 Channel shutdown: connection error 错误(HAProxy 负载均衡)

    相关文章:搭建 RabbitMQ Server 高可用集群 具体错误信息: 2018-05-04 11:21:48.116 ERROR 60848 --- [.168.0.202:8001] o.s. ...

  8. Mac环境svn的使用

    在Windows环境中,我们一般使用TortoiseSVN来搭建svn环境.在Mac环境下,由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装任何第三方软件的前提下使用svn功能,不过还 ...

  9. centos下 redmind2.6安装

    1.下载安装redmind有关软件 cd /tmp wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz wget http:/ ...

  10. Validate Binary Search Tree(一定掌握的方法)

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...