[刷题]算法竞赛入门经典(第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 ...
随机推荐
- Hadoop2.7.3分布式集群安装
一.依赖文件安装 1.1 JDK 参见博文:http://www.cnblogs.com/liugh/p/6623530.html 二.文件准备 2.1 文件名称 hadoop-2.7.3.tar.g ...
- 百度cdn资源公共库共享及常用开发接口
CDN公共库是指将常用的JS库存放在CDN节点,以方便广大开发者直接调用 网站:http://cdn.code.baidu.com/ 常用资源: jquery: http://libs.baidu.c ...
- 关于js参数传递矛盾新理解
之前看了很多人的解释,说js中,函数的参数传递都是值传递中不理解. 他们无非举了两个例子 在这两个例子中,第二个例子可以看出参数是由值传递的.因为函数内对象的变化没有影响到函数外对象的变化.但是在第一 ...
- 老李分享:《Linux Shell脚本攻略》 要点(八)
老李分享:<Linux Shell脚本攻略> 要点(八) 1.打印进程 [root@localhost program_test]# ps -e | head PID TTY ...
- 接口测试培训:HTTP协议基础
接口测试培训:HTTP协议基础 引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展. ...
- linux 压缩与解压
tar -cvf test.tar test ----将test文件夹打包成test.tar. # tar -xvf test.tar ----将test.tar 进行拆解,从中抽取文件 # ...
- C语言枚举类型(Enum)深入理解
在实际编程中,有些数据的取值往往是有限的,只能是非常少量的整数,并且最好为每个值都取一个名字,以方便在后续代码中使用,比如一个星期只有七天,一年只有十二个月,一个班每周有六门课程等. 以每周七天为例, ...
- C#各个版本中的新增特性详解
序言 自从2000年初期发布以来,c#编程语言不断的得到改进,使我们能够更加清晰的编写代码,也更加容易维护我们的代码,增强的功能已经从1.0搞到啦7.0甚至7.1,每一次改过都伴随着.NET Fram ...
- zepto.js介绍
是一个阉割版的jQuery zepto不支持jQuery过于复杂的选择器,比如:first :last :eq zepto如果要用动画必须再次引包 zepto能将css3中transition支持的动 ...
- 【转载】stm32之看门口介绍
今天在学习mpu6050的时候,发现程序出现了看门狗的程序,其实这个在学习51的时候就应该了解的,但是我并没有去了解.导致现在学习32,其实就是在补之前的51. 首先,我想把文章最后一句放到开始写出来 ...