zoukankan      html  css  js  c++  java
  • 1093 Count PAT's

    1093 Count PAT's

    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 PA, 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.

    思路:对于每个A,记录它的前面有几个P,后面有几个T;然后对于每个A,PAT的组合有(前P)*(后T)种

     1 #include <iostream>
     2 #include <string>
     3 #include <vector>
     4 #include <queue>
     5 using namespace std;
     6 const int maxn = 100005;
     7 
     8 int main(){
     9     string s; cin >> s;
    10     int pre[maxn], back[maxn];
    11     fill(pre,pre+maxn,0); fill(back, back+maxn, 0);
    12     int preP=0;
    13     for(int i=0;i<s.length();i++){
    14         pre[i] = preP;
    15         if(s[i]=='P') preP++;
    16     }
    17     int backT=0;
    18     for(int i=s.length()-1;i>=0;i--){
    19         back[i] = backT;
    20         if(s[i]=='T') backT++;
    21     }
    22     long long cnt;
    23     for(int i=0;i<s.length();i++){
    24         if(s[i]=='A'){
    25             cnt += pre[i]*back[i];
    26         }
    27         if(cnt>1000000007) cnt%=1000000007;
    28     }
    29     printf("%lld
    ",cnt);
    30 }
  • 相关阅读:
    平面切圆柱面的椭圆绘制
    抛物面倾斜体积积分
    计算误差函数的积分--erf(x)
    三棱椎的体积
    Mac平台上OpenCV开发环境搭建
    仿新浪右下角视频弹窗(视频弹出广告)播放器
    python爬虫之Scrapy 使用代理配置
    ip地址定位库
    python 使用 redis expire属性设置访问时间间隔
    如何做将两张图片合二为一
  • 原文地址:https://www.cnblogs.com/lokwongho/p/9940857.html
Copyright © 2011-2022 走看看