杭电OJ题 1361 Parencodings解题报告

杭电acm试题解析和答案 这是关于杭电的一些acm的解题答案和解析思路 立即下载

Parencodings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 403    Accepted Submission(s): 231



Problem Description
Let S = s1 s2 … s2n be a well-formed string of parentheses. S can be encoded in two different ways:

  • By an integer sequence P = p1 p2 … pn where pi is the number of left parentheses before the ith right parenthesis in S (P-sequence).
  • By an integer sequence W = w1 w2 … wn where for each right parenthesis, say a in S, we associate an integer which is the number of right parentheses counting from the matched left parenthesis of a up to a. (W-sequence).

Following is an example of the above encodings:
  S    (((()()())))
  P-sequence      4 5 6666
  W-sequence      1 1 1456

Write a program to convert P-sequence of a well-formed string to the W-sequence of the same string.
 

Input
The first line of the input file contains a single integer t (1 t 10), the number of test cases, followed by the input data for each test case. The first line of each test case is an integer n (1 n 20), and the second line is the P-sequence of a well-formed string. It contains n positive integers, separated with blanks, representing the P-sequence.
 

Output
The output file consists of exactly t lines corresponding to test cases. For each test case, the output line should contain n integers describing the W-sequence of the string corresponding to its given P-sequence.
 

Sample Input
2 6 4 5 6 6 6 6 9 4 6 6 6 6 8 9 9 9
 

Sample Output
1 1 1 4 5 6 1 1 2 4 5 1 1 3 9
 
————————————————————————————————————————————
我先通过P-sequence找出S表达式,然后转换为W-sequence

/****************************
 *Name:Parencodings.c
 *Tags:ACM water
 ****************************/

#include <stdio.h>

int main()
{
      int t, n, i, p, w[20], j, l, r;
      char sequence[100];
      scanf("%d", &t);
      while(t--) {
	    scanf("%d", &n);
	    j = 0;
	    l = 0;
	    for(i = 0; i < n; i++) {
		  scanf("%d", &p);
		  while(l < p) {
			sequence[j] = '(';
			l++;
			j++;
		  }
		  sequence[j] = ')';
		  j++;
	    }
	    sequence[j] = '\0';
	    /* printf("%s\n", sequence); */
	    for(i = 0; i < 20; i++) {
		  w[i] = 0;
	    }
	    i = 0;
	    j = 0;
	    while(sequence[i] != '\0') {
		  if(sequence[i] == ')') {
			if(sequence[i-1] == '(') {
			      w[j] = 1;
			      sequence[i-1] = '0';
			} else {
			      r = i;
			      while(sequence[r] != '(') {
				    if(sequence[r] == ')') {
					  w[j]++;
				    }
				    r--;
			      }
			      sequence[r] = '0';
			}
			j++;
		  }
		  i++;
	    }
	    printf("%d", w[0]);
	    for(i = 1; i < j; i++) {
		  printf(" %d", w[i]);
	    }
	    printf("\n");
      }
      return 0;
}


POJ1068-Parencodings 北大POJ1068-Parencodings 解题报告+AC代码 立即下载

相关推荐

SystemVerilog实战:AXI Stream协议从零搭建(附完整代码解析)

本文详细介绍了如何使用SystemVerilog从零搭建AXI Stream协议,包括核心信号解析、接口设计、主从设备实现及验证环境构建。通过完整的代码示例和工程实践技巧,帮助开发者掌握AXI Stream在FPGA/ASIC设计中的高效数据传输方法,特别适合视频处理和网络数据传输等应用场景。

weixin_29207439的博客 359

1068:Parencodings

栈,括号匹配 解题思路: 根据P串还原出括号串:第一个数是4,说明第一个右括号前有4个左括号;第二个数是5,说明到一个右括号后,有5-4个左括号,依次类推,还原出括号串。 用栈来匹配括号:很容易发现,中间包含多少个括号对,可以直接用左括号和右括号的下标来计算。因此,碰到左括号时,把其下标压入栈,碰到右括号时,出栈,由两个下标计算出结果。 参考:https://blog.youkuaiyun.com/xp731574722/article/details/76566171 //栈,括号匹配 #include <

weixin_49403900的博客 215

Parencodings

ParencodingsTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 134    Accepted Submission(s): 89Problem DescriptionLet S = s1 s2 … s2n be a w

Rachel Zhang的专栏 2546

【操作系统】实验楼操作系统实验三——系统调用

操作系统实验3——系统调用 环境配置 ​ 首先同样是配置环境 cd /home/shiyanlou/oslab tar -zxvf hit-oslab-linux-20110823.tar.gz -C /home/shiyanlou 实验步骤 添加函数声明 cd ~/oslab/linux-0.11/include/linux gedit sys.h //添加内容: extern int sys_whoami(); extern int sys_iam(); fn_ptr_sys_call_table

qq_46612803的博客 6357

高通Camera IFE时钟配置

高通Camera IFE时钟配置中的minHorizontalBlanking和minVerticalBlanking配置计算方法

一个懒癌的驱动工程师的随笔分享 6167

:Parencodings

Parencodings D1075:Parencodings 时间限制: 1000ms内存限制: 65536kB 描述Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P =

代码全集 637

GNSS接收机性能测试指标详解:TTFF、位置精度、灵敏度等关键参数如何评估

本文详细解析了GNSS接收机性能测试的关键指标,包括首次定位时间(TTFF)、位置精度、灵敏度等,帮助工程师系统评估接收机性能。通过多频段协同定位和载波相位测试等技术,提升定位精度至亚米级。同时,介绍了灵敏度测试的极限挑战和授时精度的专业测试方案,为GNSS接收机的性能优化提供实用指导。

cuda7parallel的博客 961

Parencodings(简单模拟法)

链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22007#problem/A G - Parencodings Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Description

JHC23的专栏 1821

CocosCreator 面试题(十七)Cocos creator 固定宽度与固定高度的底层原理是什么?Cocos creator是如何做适配的?

通过固定宽度或固定高度的适配方式,可以使游戏在不同屏幕尺寸上保持一定的一致性,确保游戏中的元素的大小和位置相对稳定。具体选择哪种适配方式取决于你的游戏需求和设计考虑。在 Cocos Creator 中,你可以通过设置「设计分辨率」和使用相对坐标和布局方式来实现固定宽度或固定高度的适配。总之,Cocos Creator 提供了多种适配方式和工具,帮助你在不同屏幕尺寸上保持游戏画面的一致性。在 Cocos Creator 中,固定宽度和固定高度是两种常见的适配方式,用于在不同屏幕尺寸上保持游戏画面的一致性。

w风雨无阻w的专栏 1687

Windows 10 本地开发环境:用 ShardingSphere-Proxy 5.4.1 快速搭建 MySQL 分库分表测试环境

本文详细介绍了在Windows 10系统中使用ShardingSphere-Proxy 5.4.1快速搭建MySQL分库分表测试环境的完整教程。从环境准备、MySQL配置到ShardingSphere-Proxy的核心设置,逐步指导开发者完成本地开发环境的搭建,并提供了分片策略详解和常见问题排查方法,帮助开发者高效验证分库分表功能。

weixin_28366053的博客 214

Parencodings--POJ 1068

1、题目类型:模拟题。 2、解题思路:(1)根据输入数据建立Arr[],0表示'(',1表示')';(2)搜索为Arr[]中为 1 的位置,并找到与之相匹配的 0 ,cnt表示对应的匹配间1的个数。 3、注意事项:flag[i]标示Arr[i]是否已完成匹配;flag[]注意及时清空。 4、实现方法: #include<iostream>using namespace st...

weixin_33950035的博客 159

基于STM32与OV7670的嵌入式视频监控系统设计与实现

本文详细介绍了基于STM32单片机与OV7670摄像头的嵌入式视频监控系统设计与实现。从硬件选型、电路设计到软件开发,涵盖了摄像头驱动、TFT显示优化及图像处理等关键技术,提供了实用的调试技巧和性能优化方案,为低成本、高效率的视频监控系统开发提供完整解决方案。

desk3的博客 802

HDU 1361 Parencodings

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1361 ParencodingsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 877 Accepted Submission(s):

=_= 356

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 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")

【瞎搞】 HDU 1361 Parencodings 括号

给出一串括号 右括号的左边分别有多少个左括号  求右括号中

Kewowlo 809

Devexpress16.2.6破解工具

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

Parencodings 模拟

Let S = s1 s2…s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2…pn where pi is the number of left parentheses before the ith right ...

博客标题不能为空我也没办法 329

【C/C++】圆括号编码(Parencodings) 蓝桥杯/ACM备赛

算法考点:字符转换与编码问题题目描述令S=s1 s2 … s2n是一个正则(well-formed)的圆括号串。S可以编码成2种不同的形式:(1) 编码成一个整型序列P = p1 p2 … pn,pi代表在S序列中第i个右圆括号前的左圆括号数量。(记为P-序列)(2) 编码成一个整型序列W=w1 w2 … wn,对每一个右圆括号a,编码成一个整数wi,表示从与之匹配的左圆括号开始到a之间的右圆括号的数目(包括a本身)。

2301_76324845的博客 557

1068 Parencodings

Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28505 Accepted: 16798 ##Description Let S = s1 s2…s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By ...

ov流岚vo的专栏 294

Parencodings(poj模拟法)

Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2...pn where pi is the number of left parentheses bef

jinzk123的博客 751

Parencodings(模拟)

Let S = s1 s2…s2n be a well-formed string of parentheses. S can be encoded in two different ways: q By an integer sequence P = p1 p2…pn where pi is the number of left parentheses before the ith right parenthesis in S (P-sequence). q By an integer sequence

qq_45928501的博客 271

简单模拟|Parencodings

用p形式还原原数组 扫描原数组中的右括号,简单操作最后得出w形式 import java.util.Scanner; public class Parencoding { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { i...

My Blog 356

POJ 1068【Parencodings】

题目链接 思路: 又是一道一题啦,看似比较复杂还是没什么难的,一步步写出来就行了。 我采用的方法是将 P编码 解码成括号串,再计算出 W编码 。 可能重编码时候需要先想好怎么算吧,利用每段匹配括号内左右各半的性质也许v会好解一些。 代码: 660K 0MS ​//660K 0MS #include <iostream> using namespace std; con...

Masker 228

ACM 算法题:Parencodings

对于正常的括号对序列,也就是左括号与右括号的数目是相等的,并且成对。例如(((()()()))),总共有n个括号。 通过两种形式对括号对编码: P序列: P = p1 p2 … pn Pi是第i个右括号之前左括号的数目。 W序列: W = w1 w2 … wn Wi是第i个右括号与之匹配及其包含的左括号的数目。 要求:写一个算法,将括号对的P序列转换成W序列。

vshadow的专栏 924
上一篇: 杭电OJ题 1347 Grandpa is Famous解题报告
下一篇: 杭电OJ题 1379 DNA Sorting解题报告
Rufeng-Blog
码龄14年 18粉丝 82原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值