[刷题]算法竞赛入门经典(第2版) 6-1/UVa673 6-2/UVa712 6-3/UVa536
这三题比较简单,只放代码了。
题目:6-1 UVa673 - Parentheses Balance
//UVa673 - Parentheses Balance
//Accepted 0.000s
//#define _XIENAOBAN_
#include<iostream>
using namespace std;
int N;
char line[130];
bool st[130];
bool cal() {
if (*line == '\0') return true;
auto *p = line;
auto *top = st;
do {
switch (*p)
{
case '(': *++top = false;break;
case '[': *++top = true;break;
case ')':
if (top == st || *top) return false;
--top;
break;
default:
if (top == st || !*top) return false;
--top;
break;
}
} while (*++p != '\0');
return top == st;
}
int main()
{
#ifdef _XIENAOBAN_
#define gets(T) gets_s(T, 129)
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
scanf("%d",&N);
getchar();
while (N--) {
gets(line);
cout << (cal() ? "Yes" : "No") << '\n';
}
return 0;
}
题目:6-3 UVa712 - S-Trees
//UVa712 - S-Trees
//Accepted 0.000s
//#define _XIENAOBAN_
#include<iostream>
using namespace std;
int N(0);
int n, m, ord[10], run[10], val[130];
int main()
{
#ifdef _XIENAOBAN_
#define gets(T) gets_s(T, 129)
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
while (scanf("%d", &n) != EOF && n != 0) {
printf("S-Tree #%d:\n", ++N);
int num(1 << n);
for (int i(1);i <= n;++i) {
while (getchar() != 'x');
ord[i] = getchar() - 48;
}
while (getchar() != '\n');
for (int i(0);i < num;++i)
val[i] = getchar() - 48;
scanf("%d", &m);
for (int i(0);i < m;++i) {
while (getchar() != '\n');
for (int j(1);j <= n;++j)
run[j] = getchar() - 48;
int ans(1);
for (int j(1);j <= n;++j)
ans = (ans << 1) + run[ord[j]];
printf("%d", val[ans - num]);
}
printf("\n\n");
}
return 0;
}
题目:6-3 UVa536 - Tree Recovery
//UVa536 - Tree Recovery
//Accepted 0.000s
//#define _XIENAOBAN_
#include<iostream>
#include<cstring>
using namespace std;
char pre[30], in[30];
void cal(char *pre, char *in, int len) {
int root(0);
while (*(in + root) != *pre) ++root;
if (root) cal(pre + 1, in, root);
if (len - root - 1) cal(pre + root + 1, in + root + 1, len - root - 1);
printf("%c", *pre);
}
int main()
{
#ifdef _XIENAOBAN_
#define gets(T) gets_s(T, 129)
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
while (scanf("%s%s", pre, in) != EOF) {
cal(pre, in, strlen(in));
puts("");
}
return 0;
}
[刷题]算法竞赛入门经典(第2版) 6-1/UVa673 6-2/UVa712 6-3/UVa536的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 4-6/UVa508 - Morse Mismatches
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,10 ms) //UVa508 - Morse Mismatches #include< ...
- [刷题]算法竞赛入门经典(第2版) 5-15/UVa12333 - Revenge of Fibonacci
题意:在前100000个Fibonacci(以下简称F)数字里,能否在这100000个F里找出以某些数字作为开头的F.要求找出下标最小的.没找到输出-1. 代码:(Accepted,0.250s) / ...
- [刷题]算法竞赛入门经典(第2版) 5-13/UVa822 - Queue and A
题意:模拟客服MM,一共有N种话题,每个客服MM支持处理其中的i个(i < N),处理的话题还有优先级.为了简化流程方便出题,设每个话题都是每隔m分钟来咨询一次.现知道每个话题前来咨询的时间.间 ...
- [刷题]算法竞赛入门经典(第2版) 4-5/UVa1590 - IP Networks
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa1590 - IP Networks #include<iost ...
- [刷题]算法竞赛入门经典(第2版) 6-7/UVa804 - Petri Net Simulation
题意:模拟Petri网的执行.虽然没听说过Petri网,但是题目描述的很清晰. 代码:(Accepted,0.210s) //UVa804 - Petri Net Simulation //Accep ...
- [刷题]算法竞赛入门经典(第2版) 6-6/UVa12166 - Equilibrium Mobile
题意:二叉树代表使得平衡天平,修改最少值使之平衡. 代码:(Accepted,0.030s) //UVa12166 - Equilibrium Mobile //Accepted 0.030s //# ...
- [刷题]算法竞赛入门经典(第2版) 5-16/UVa212 - Use of Hospital Facilities
题意:模拟患者做手术. 其条件为:医院有Nop个手术室.准备手术室要Mop分钟,另有Nre个恢复用的床.准备每张床要Mre分钟,早上Ts点整医院开张,从手术室手术完毕转移到回复床要Mtr分钟.现在医院 ...
- [刷题]算法竞赛入门经典(第2版) 5-11/UVa12504 - Updating a Dictionary
题意:对比新老字典的区别:内容多了.少了还是修改了. 代码:(Accepted,0.000s) //UVa12504 - Updating a Dictionary //#define _XieNao ...
- [刷题]算法竞赛入门经典(第2版) 5-10/UVa1597 - Searching the Web
题意:不难理解,照搬题意的解法. 代码:(Accepted,0.190s) //UVa1597 - Searching the Web //#define _XIENAOBAN_ #include&l ...
随机推荐
- Python快速入门(1)
FROM:实验楼 http://python.usyiyi.cn/python_278/tutorial/index.html http://woodpecker.org.cn/abyteofpyth ...
- Grafana关键表结构分析
Grafana默认使用SQLite存储数据表,默认数据库文件存储在/var/lib/grafana/grafana.db中,可以将文件拷贝到Widnows中,使用Navicat for SQLite进 ...
- 【转】JavaScript中使用ActiveXObject操作本地文件夹的方法
原文链接:http://www.jb51.net/article/48538.htm
- 在centOS7.2里安装virtualenv和flask
1) 安装pip工具 #wget https://bootstrap.pypa.io/get-pip.py #python get-pip.py 2) 安装virtualenv,并创建一个开发环境 # ...
- 手机交互应用服务(状态栏提示信息Notifications)
官方的一个简单的例子: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon ...
- Mybatis基础学习(四)—关系映射
一.模型分析 user和orders user---->orders 一个用户可以创建多个订单,一对多. orders--->user 一个订单只由一个用户创建,一对一. orders ...
- codevs2019 Uva10029 递变阶梯
提交地址:[codevs][Uva] 题目描述 递变是指通过增加.减少或改变单词x中的一个字母,使它变成字典中的另一个单词y.比如将dig变成dog,将dog变成do都是递变.递变阶梯是一个按字典序 ...
- 爬楼梯问题-斐波那契序列的应用.md
N 阶楼梯,一次可以爬1.2.3...n步,求爬楼梯的种类数 /** * 斐波那契序列 */ public class ClimbingStairs { // Sol 1: 递归 // 递归 公式:F ...
- HTTP协议介绍
一.什么是HTTP协议呢? 维基百科 写道 超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是互联网上应用最为广泛的一种网络协议.HTTP是一个客户端终端 ...
- 在github上搭建免费的博客
github好多年前,大家都开始玩啦,我这个菜鸟近几年才开始.github不仅可以管理项目,还可以搭建博客.技术人员,一般用的博客为博客园,CSDN多一些.看到朋友们都弄一个,我也开始弄起来,先找点资 ...