【PAT甲级真题】- Count PAT‘s (25)

PointNet++改进策略目录 后续我将如何使用文章中创新点加入的PointNet++中代码实现部分进行更新。 阅读详情

题目来源

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.

输入描述:

Each input file contains one test case. For each case, there is only one line giving a string of no more than 10 5 10^5 105
characters containing only P, A, or T.

输出描述:

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.

输入例子:

APPAPT

输出例子:

2

思路简介

一道经典的 DP 题

推理一遍就是:

  1. 如果当前 “PA” 的数目是 s1,“PAT” 的数目是 s2,那么输入一个 “T” ,它可以和前面所有的 “PA” 组成新的 “PAT” ,总的 “PAT” 就是新的加上旧的,即 s1+s2
  2. 同理如果当前 “P” 的数目是 s0,“PA” 的数目是 s1,那么输入一个 “A” ,它可以和前面所有的 “P” 组成新的 “PA” ,新的加上旧的即 "PA“ 的总数

转移方程就是

if cin==T:
	PAT=PAT+PA
else if cin== A:
	PA=PA+P
else:
	P++

遇到的问题

无,一遍过

代码

/**
 * https://www.nowcoder.com/pat/5/problem/4039
 * dp
 */
#include<bits/stdc++.h>
using namespace std;


void solve(){
    string s;
    cin>>s;
    int len=s.size();
    int p=0,pa=0,pat=0;
    for(int i=0;i<len;++i){
        if(s[i]=='P')p++;
        if(s[i]=='A')pa=pa+p;
        if(s[i]=='T')pat=(pa+pat)%1000000007;
    }
    cout<<pat;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //fstream in("in.txt",ios::in);cin.rdbuf(in.rdbuf());
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
WPF高级 | WPF 与数据库交互:连接、查询与数据更新 WPF高级 | WPF 与数据库交互:连接、查询与数据更新,在现代应用程序开发中,数据的存储和管理至关重要。Windows Presentation Foundation(WPF)作为一款强大的图形界面开发框架,常常需要与数据库进行交互,以实现数据的持久化存储、读取和更新。本文将深入探讨 WPF 与数据库交互的各个方面,包括数据库连接的建立、数据查询的执行以及数据更新的操作,并通过丰富的代码示例和详细的概念解释,帮助读者掌握这一关键技术。 阅读详情

相关推荐

FortiGate-60E防火墙忘记密码?用Console线+TFTP重装固件v7.0.9全流程

本文详细介绍了当FortiGate-60E防火墙忘记密码且物理重置无效时,如何通过Console线连接并利用TFTP服务器重装固件(如v7.0.9)的全流程。从恢复原理、工具准备、网络配置到逐步执行命令,提供了完整的实战指南,帮助管理员彻底恢复设备出厂设置并重置密码。

snow3的博客 333

1093. Count PAT’s (25)-PAT甲级真题

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

柳婼 の blog 1930

手把手教你用DCA1000EVM解析IWR6843毫米波雷达数据(附MATLAB代码)

本文提供了一份详尽的实战指南,手把手教你使用DCA1000EVM采集并解析TI毫米波雷达IWR6843的原始数据。内容涵盖硬件连接配置、mmWave Studio参数设置、LVDS数据流结构解析,并附有核心MATLAB代码,详细演示了从原始二进制文件到距离-速度谱的信号处理全链路,帮助开发者快速掌握数据解析与处理的关键步骤。

terraform7cloud的博客 227

PAT甲级真题 1093 Count PAT‘s (25分) C++实现(同PAT乙级真题 1040)

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

zhang35的博客 202

从硬件到软件:深度解析D435i USB SCP overflow错误的根源与解决方案

本文深入解析Intel RealSense D435i相机在ROS环境下常见的'USB SCP overflow'错误,特别是与`control_transfer`相关的错误提示。从硬件配置到软件优化,详细介绍了如何通过调整USB接口、优化`rs_camera.launch`参数、更新固件驱动等方法解决数据传输溢出问题,提升设备稳定性和性能。

yy01234的博客 771

Ubuntu24.04LTS上Ollama GPU加速配置指南:从驱动安装到多卡均衡负载

本文详细介绍了在Ubuntu24.04LTS系统上配置Ollama GPU加速的完整指南,包括NVIDIA驱动安装、CUDA Toolkit配置、Ollama在线与离线安装方法,以及多GPU负载均衡优化策略。通过实战案例和性能调优建议,帮助开发者充分利用硬件资源提升大型语言模型的运行效率。

weixin_29255731的博客 760

PAT甲级 1093 Count PAT's (25 分)

\quad这是一个数学问题,容易想到对于字符串中每个A而言,若其前面有m个P,后面有n个T,可以得到对于当前的A,能够组成m*n种情况的PAT。我们可以先统计出T的总个数,依次遍历字符串,遇到P则统计P的个数++,遇到T则T个数--,遇到A则令结果加上当前P数量和T数量的乘积。最后将结果模给定的数输出即可。这里若数太大在中间计算过程中就爆long long的话可以每一步都模那个大数,不过PAT数据...

qq_40438165的博客 1766

SECS/GEM EAP 设备自动化功能原理和设计方案

半导体SECS GEMEAP实现了对生产线上机台的实时监控,是工厂自动化不可缺少的控制系统。EAP系统与FAB中的机台紧密相关,系统的设计与开发必须与生产线的机台实际生产流程相一致,才能达到控制机台生产的目的。 EAP SECS/GEM是MES与设备的桥梁,EAP通过SECS国际标准协议与机台进行数据传输。SECS是半导体设备(半导体行业称设备为机台)必须遵循的一种国际通信协议。EAP就是通过SECS与设备通信、传输数据、发送指令控制设备按照预先定义........

semisecs 17万+

【PAT甲级 - C++题解】1093 Count PAT‘s

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 550

Windows本地部署Qwen3-14B实战指南:Ollama+Open WebUI零Docker方案

大语言模型本地部署是AI工程化落地的关键环节,其核心在于推理框架兼容性、硬件加速适配性与端到端稳定性。Ollama作为轻量级模型运行时,原生支持Windows DirectML与CUDA,规避了Docker/WSL2虚拟化开销和llama.cpp编译风险;Qwen3-14B则凭借128K上下文、Tool Calling原生支持及中文长文本结构化能力,成为政务、金融等场景首选。本文聚焦Windows平台真实约束——显存阈值、驱动版本匹配、路径编码兼容、离线知识库集成(RAG)等工程细节,提供经63台Windo

weixin_32136203的博客 412

高速PCB设计中的一些常用规则

目前,高速PCB产品设计中,高速接口的应用日益普及,对于复杂的设计而言,高速走线就如同“蜘蛛网”一样密布在PCB各处,因此,在进行PCB检查及评审时,必要的高速PCB设计经验法则及规则是工程师开展工作必不可少的知识储备。

一只豌豆象的博客 3414

PAT甲级字符串相关题目题解(C/C++)

其中,(a) 和 (b) 是大于0的实数,(c) 是正实数且 (c \neq 1)。我们想要计算的是 (2^{31}) 用 (10) 的次方来表示,即求 (10) 的多少次方等于 (2^{31})。要证明 (2^{31}) 约等于 (10^{9.33}) 的推理正确性,我们可以使用对数的换底公式来进行计算。c - '0’可以得到字符对应的int值,如果直接输出c,输出的是这个数字字符的ASCII码值,易错点。因此,我们可以得出结论,(2^{31}) 约等于 (10^{9.33}),证明了推理的正确性。

qq_37397652的博客 1460

08 RK3568 MAC TO MAC直连 RTL8367S mdio

本文:采用rk3568 gamc0 通过rgmii直连 交换芯片的mac口 通信方法为mdio。

qq_39451352的博客 3475

PAT——1093 Count PAT‘s 甲级

1093 Count PAT's题目题意代码解析AC代码本人代码参考代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805373582557184 题意 求出给定的字符串还有多少个“PAT”子串 代码解析 两段代码都是一个意思,就是每一个A前后的P和T的数量相乘就是这个A对应的PAT子串数量,遍历每一个A并加和就是最终的结果 我自己的思路就是通过upper_bound函数寻找A前后的P、T数量,但第二段代码明显更简洁

ljhsq的博客 279

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

1093 Count PAT‘s-PAT甲级真题

分析:计算每个A左边的P数量和右边的T数量,相乘累加得到答案。先遍历一遍字符串,计算每个A右边的T数量,再遍历一遍计算左边P的数量;

balabbla的博客 100

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

【个人代码及思路】PAT甲级:1093 Count PAT‘s (25分)

PAT (Advanced Level) Practice 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 give

一只小杰鸽的博客 158

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

【PAT甲级A1093】Count PAT‘s (25分)(c++)

1093 Count PAT’s (25分) 作者:CAO, Peng 单位:Google 代码长度限制:16 KB 时间限制:150 ms 内存限制:64 MB 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

小庄同学的博客 191

1093 Count PAT‘s (25point(s)) - C语言 PAT 甲级

* 加法实现: 每个 A 组成 PA 的个数,对应当前 P 的累加数 每个 T 组成 PAT 的个数,对应当前 PA 的累加数 PAT 总数为所有 T 对应 PAT 的累加 * 乘法实现: 一个 A,前面 P 的个数为 p,后面 T 的个数为 t,则组成 p \* t 个 PAT PAT 总数为所有 A 对应 p \* t 的累加

有三只土豆 192

PAT甲级 1093 Count PAT‘s (25 分) 状态机解法

题目 原题链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805373582557184 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,

weixin_38346279的博客 187

PAT甲级1093 Count PAT‘s :[C++题解]DP、状态机模型dp

刷题

阿正的梦工坊 440

PAT 甲级 1093 Count PAT's(25分)

PAT 甲级 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, an...

努力不脱发的程序媛 280

PTA甲级 1093 Count PAT (25分)

文章目录题目原文Input Specification:Output Specification:Sample Input:Sample Output:思路如下:代码如下:下面是我(划去)柳神的代码思路: 首先,先贴柳神的博客 https://www.liuchuo.net/ 这是地址 想要刷好PTA,强烈推荐柳神的博客,和算法笔记 题目原文 The string APPAPT contains two PAT's as substrings. The first one is formed by the

Huangpengyu123的博客 412

PAT甲级 1093 Count PAT‘s

T的结果就是当前这个A可以构成的PAT子串,因为字符串中可以有多个A,所以需要把结果加起来。可以先遍历数组有几个T,遍历A的时候前面有一个T我们就将存储T出现次数的变量-1就是A后面有几个T。题目的意思就是输入一串字符串,输出这一串字符串中有几个PAT子串。T的结果取余一次然后再对相加的结果取余一次,不然可能会数据溢出。我们只需要判断字符A前面有几个P,后面有几个T,用P。取余的时候一定要将P。

weixin_50371163的博客 478

PAT 甲级 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 numbe

qq_45478482的博客 145

【PAT甲级、C++】1093 Count PAT‘s (25分)

从左开始统计P的个数,从右开始统计T的个数 然后找到在字符串中找到字符A,其所能组成的PAT串的个数就是该字符左边的P的个数*右边T的个数 # include <iostream> # include <vector> using namespace std; int main() { string str; cin >> str; int sz = str.size(); vector<int> P(sz, 0

MYMarcoreus的博客 130

PAT甲级1093Count PAT's (25point(s))

1093 Count PAT’s (25point(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, ...

qq_43323834的博客 158
上一篇: 【PAT甲级真题】- Insert or Merge (25)
下一篇: 【PAT甲级真题】- All Roads Lead to Rome (30)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值