ZOJ1015 Parencodings

Holy Grail 布局的范式升级:从 Flex 拼凑到 Grid 声明式布局 Holy Grail 布局是前端响应式开发中的经典三栏结构问题,本质是解决 header/footer 固定、main 自适应撑满、sidebar 与 main 等高、DOM 语义顺序合规四大刚性约束。传统 float 和 Flexbox 方案依赖 hack(如负 margin、嵌套容器、order 属性),易引发兼容性、可访问性和维护性问题;而 CSS Grid 通过 grid-template-areas、fr 单位和 minmax() 等原生能力,将布局从‘行为拼凑’升维为‘意图声明’。其技术价值在于 阅读详情

Parencodings

Time Limit: 2000 msMemory Limit: 65536 KB

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

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
 
using namespace std;
const int N = 59;
int main()
{
    freopen("in.txt","r",stdin);
    char ch[N];
    int n,p[N],ans[N],pp[N],cas;
    scanf("%d",&cas);
    while(cas--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&p[i]);
        }
        int cnt = 0;
        for(int i=0,j=0;i<(n<<1);i++)
        {
            if(cnt<p[j])
            {
                ch[i] = '(';
                cnt++;
            }else
            {
                j++;
                ch[i] = ')';
            }
        }

        cnt = 1 ;
        memset(ans,-1,sizeof(ans));
        for(int i=0;i<(n<<1);i++)
        {
            if(ch[i]=='(')
            {
                pp[cnt++] = i;
            }else
            {
                ans[i] = pp[--cnt];
            }
        }
        int ou = 0;
        for(int i=0;i<(n<<1);i++)
        if(ans[i]>=0)
        {
            if(ou) printf(" ");
            else ou = 1;
            printf("%d",(i - ans[i]+1)/2);
        }
        printf("\n");
    }
    return 0;
}

弦图ZOJ 1015 Fishing Net 判定方法 弦图,算法完全按照CDQ的PPT上给的最大势算法(MCS)完美消除序列..需要的朋友可以参考下 立即下载

相关推荐

S32DS使用完整指南:S32K CAN通信模块配置步骤

深入讲解S32DS使用过程中S32K芯片的CAN通信模块配置步骤,涵盖关键设置与常见问题。掌握s32ds使用技巧,提升开发效率,实现稳定可靠的车载网络通信。

weixin_42592399的博客 982

1068:Parencodings

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

weixin_49403900的博客 215

shader多图叠加变换

shader Shader "Paint3D/AddTexture" { Properties { _MainTex ("Main Texture", 2D) = "white" {} _MainColor("Main Color", Color)=(1,1,1,1) _AddTex0 ("Texture0", 2D) = "white" {} _AddTex1 ("Texture1", 2D) = "white" {} .

李长江的博客 909

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

C51:PWM+舵机角度控制

PWM,英文名Pulse Width Modulation,是脉冲宽度调制缩写,它是通过对一系列脉冲的宽度进行调制,等效出所需要的波形(包含形状以及幅值),对模拟信号电平进行数字编码,也就是说通过调节占空比的变化来调节信号、能量等的变化,占空比就是指在一个周期内,信号处于高电平的时间占据整个信号周期的百分比,例如方波的占空比就是50%.脉冲宽度调制通过占空比编码模拟信号一个周期内,高电平占据时长的百分比如下图所示,最便宜的舵机sg90,常用三根或者四根接线,黄色为PWM信号控制。

qq_73379310的博客 3392

Vue3项目实战:用vue-print-nb搞定多页表格打印(附样式不丢失解决方案)

本文详细介绍了在Vue3项目中,如何利用vue-print-nb插件解决Element Plus多页表格打印的样式丢失与分页错乱等核心难题。通过分离打印视图、编写专用CSS控制分页行为、以及深入理解浏览器打印原理,提供了一套从基础配置到高级技巧的完整企业级打印解决方案,确保打印输出专业可靠。

linux的博客 1233

: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

不只是CPU主频:深入解析英飞凌Aurix TC3xx各外设时钟树(CAN、以太网、Flash时序如何配置)

本文深入解析英飞凌Aurix TC3xx系列微控制器的外设时钟树配置,涵盖CAN、以太网和Flash时序的优化方法。通过详细分析时钟系统架构、关键外设配置及多外设协同设计策略,帮助工程师实现高性能汽车电子控制单元(ECU)开发。特别关注系统时钟的灵活配置与EMC优化技巧,提升系统实时性和可靠性。

weixin_29189373的博客 401

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

20240128 C#与SCPI协议实战:轻量级仪器控制库ScpiNet应用指南

本文详细介绍了轻量级C#库ScpiNet在仪器控制中的应用。相较于传统的NI-VISA,ScpiNet无需安装庞大运行时,通过纯C#实现直接与USB或以太网设备通信,支持跨厂商SCPI仪器。文章提供了从快速连接到实战封装、错误处理的完整指南,帮助开发者构建简洁高效的自动化测试系统。

h9j8k7l6m5n的博客 549

DLMS/COSEM协议的理解体会

DLMS是通信协议,COSEM是电表建模规范。HDLC帧基本格式为0x7e......

一个bug是bug,多个bug能work 8317

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

Linux ARM平台开发系列讲解(网络篇)1.3 MDIO总线设备device和设备driver匹配

在设备和驱动都载入内核后,设备和驱动是如何匹配起来的呢?其实他们就是通过的唯一标识phyID进行匹配phy_dev和phy_drv是通过phy_bus_match函数进行匹配,匹配成功后会建立链表链接,具体流程如下图: 返回总目录......

DSMGUOGUO的博客 1099

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

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

【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

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

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 357

POJ 1068【Parencodings】

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

Masker 229

zoj 1064--Parencoding

 ParencodingsTime Limit: 1 Second      Memory Limit: 32768 KBLet S = s1 s2 ... s2n be a well-formed string of parentheses. S can be encoded in two different ways:By an integer sequ

林榆耿的专栏 1533

ZZULIOJ 1010~1019(oj入门题)

ZZULIOJ 1010~1019ZZULIOJ 1010: 求圆的周长和面积题目描述输入输出代码:ZZULIOJ 1011: 圆柱体表面积题目描述输入输出代码:ZZULIOJ1012: 求绝对值题目描述输入输出代码:ZZULIOJ 1013: 求两点间距离题目描述输入输出代码:ZZULIOJ 1014: 求三角形的面积题目描述输入输出代码:ZZULIOJ 1015: 计算时间间隔题目描述输入输出代码:ZZULIOJ 1016: 银行利率题目描述输入输出代码:ZZULIOJ 1017: 判断正整数位数题目描

觞雪无痕的博客 4112

zoj 1015(玹图的判定)

知道了个新概念:玹图https://wenku.baidu.com/view/6f9f2223dd36a32d73758126.html?from=rec&pos=0&weight=9&lastweight=2&count=5##。 这个题就是有关玹图的判断。 算法看了http://www.cnblogs.com/jianglangcaijin/p/3799696.html这里的 完美消

constbh的博客 370
上一篇: ZOJ1008 Gnome Tetravex
下一篇: ZOJ1002 Fire Net
Lycodeboy
博客等级 码龄11年 1170粉丝 142原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值