poj 1068
来源:互联网 发布:巨牌一搜网络一搜同志 编辑:程序博客网 时间:2024/06/02 19:59
题目大意:
给出p密码串,p的定义为,找到p字串的每一个')',然后往右数统计'('的个数
求w字串,w的定义为,找到')',然后统计与之匹配的'(',统计这个
分析:
根据w直接模拟就可以了,用了队列和vector容器来实现这个过程。
其实估计足够大的数组就可以了,但还是试着用一下vector。
#include <cstdio>#include <queue>#include <vector>#include <iostream>#include <cstring>#include <iostream>using namespace std;typedef long long ll;ll arr[25], ans[25], number, wal, point;int main(void){int t;cin >> t;while (t--){cin>>number;for (ll i = 1; i <= number; i++) scanf("%lld", &arr[i]);queue <char> q;ll point = 0;for (ll i = 1; i <= number; i++){if (point < arr[i]){for (ll j = point; j < arr[i]; j++){q.push('(');}point = arr[i];q.push(')');}else if (point == arr[i]){q.push(')');}}vector<char> c;vector<int> vis;wal = 1;while (q.size()){char temp = q.front();q.pop();c.push_back(temp);vis.push_back(0);}for (ll i = 0; i <= c.size(); i++){//printf("i:%lld ", i);if (c[i] == ')'){ll cnt = 1;for (ll j = i-1; j >= 0; j--){//printf("j:%lld\n", j);if (c[j] == ')') cnt++;else if (c[j] == '('&&vis[j]==0){//cout << cnt << endl;ans[wal] = cnt;vis[j] = 1;wal++;break;}}}}for (ll i = 1; i < wal; i++){cout << ans[i];i == wal-1 ? cout << endl : cout << ' ';}}}
0 0
- POJ 1068
- POJ-1068
- poj 1068
- POJ 1068
- poj 1068
- POJ 1068
- POJ 1068
- poj 1068
- poj-1068
- poj 1068
- poj 1068
- poj 1068
- poj 1068
- poj 1068
- poj 1068
- POJ-1068
- poj 1068
- poj 1068
- Michael的Python笔记(一)
- EditText中英文混输限制长度
- Smobiler如何开启日志功能
- 聚集索引和非聚集索引(整理)
- javascript中的string与其他语言string的一些不同
- poj 1068
- Android设置透明、半透明等效果
- 编写高效的 C 和 C 代码优化
- Windows下设置MySql数据库名、表名是否区分大小写
- 【转】mysql重连,连接丢失:The last packet successfully received
- FlowLayout及背包算法
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- java的Arrays类的应用
- 一些简单而又不失个性的css3片段(持续更新)