poj 1068 Parencodings(模拟)
来源:互联网 发布:mac系统如何剪切文件 编辑:程序博客网 时间:2024/06/08 08:11
题目链接:POJ 1068-Parencodings
题目大意:对与一个全为括号的序列,定义两种表示方法,P-sequence,表示第i个右括号左边有几个左括号。W-sequence表示第i个右括号与它左边的第j个左括号配对,现在给出P-sequence,求W-sequence。
解题思路:简单的模拟,因为总数不会大于20,所以不用考虑的太复杂。
#include <stdio.h>#include <string.h>const int N = 50;int n, f[N], w[N], s[N];int search(int x) {for (int i = x - 1, cnt = 1; i >= 0; i--) {if (s[i]) {if (s[i] == 1) {s[i] = 2;return cnt;}cnt++;}}return -1;}void solve() {int rec = 0, p = 0;memset(s, 0, sizeof(s));for (int i = 0; i < n; i++) {// draw;int cnt = f[i] - rec;rec = f[i];for (int j = 0; j < cnt; j++)s[p++] = 1;w[i] = search(p++);}}int main () {int cas;scanf("%d", &cas);while (cas--) {// read;scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%d", &f[i]);// solve;solve();// printf;printf("%d", w[0]);for (int i = 1; i < n; i++)printf(" %d", w[i]);printf("\n");}}
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- POJ 1068 Parencodings (模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- POJ 1068 Parencodings(模拟)
- POJ 1068 Parencodings(模拟)
- POJ 1068:Parencodings(模拟)
- POJ 1068 Parencodings 模拟
- poj 1068 Parencodings (模拟)
- poj 1068 Parencodings 模拟
- POJ 1068-Parencodings(模拟)
- poj 1068 Parencodings(模拟)
- poj 1068 Parencodings 模拟
- POJ - 1068 Parencodings 模拟
- POJ 1068 Parencodings <模拟>
- javascript中负数算术右移、逻辑右移的奥秘探索
- iOS学习:UILabel和sizeWithFont方法,可用于动态调整UILabel大小
- Java对象序列化
- 第二代I3/I5/I7核显(HD3000/HD2000)支持最大分辨率的探讨
- 第一章 cocos2d简介
- poj 1068 Parencodings(模拟)
- java.math.Math类整理 常用的常量和方法
- .net服务器控件使用总结之TreeView
- Cortex_a7_mpcore_r0p5_trm.pdf阅读总结
- js 使FORM表单的所有元素不可编辑的示例代码
- 使用字节码asm将pojo转换成Map,直接构造mongodb bsonobject
- 第八周作业---求函数的值
- C语言学习笔记——scanf("%c",&ch) 读取字符
- include <stdio.h>