[刷题]算法竞赛入门经典(第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 ...
随机推荐
- Tcl与Design Compiler (七)——环境、设计规则和面积约束
本文属于原创手打(有参考文献),如果有错,欢迎留言更正:此外,转载请标明出处 http://www.cnblogs.com/IClearner/ ,作者:IC_learner 本文的主要内容是讲解( ...
- 区分 点操作符+属性名 和 getAttribute()
在用DOM操作控制HTML时,很多初学者会把 点操作符+属性名 与getAttribute("属性名") 混淆,误以为这两种方法是等价的. 实际上, 通过getAttribute( ...
- 原生JS实现弹出窗口的拖拽
上一篇说了一下弹出窗口功能的实现思路,一般情况下紧接着就会需要做到弹窗的移动,当然现在有很插件.库比如hammer可以使用,效率也非常好.但我觉得还是有必要了解一下原生JS的实现思路及方式,如下: 思 ...
- Oracle14~23
14.查询所有学生的Sname.Cno和Degree列. 15.查询所有学生的Sno.Cname和Degree列. 16.查询所有学生的Sname.Cname和Degree列. 17. 查询“9503 ...
- RN 导入原有Xcode项目中,引入Pod依赖出现的问题与解决
RN 导入原有Xcode项目中,引入Pod依赖出现的问题与解决 前言 最近学习React Native技术.将RN引入到原来Xcode项目中有一步:给原来Xcode项目添加所需要的Pod依赖 写好Po ...
- 老李分享:《Linux Shell脚本攻略》 要点(三)
老李分享:<Linux Shell脚本攻略> 要点(三) 1.生产任意大小的文件 [root@localhost dd_test]#[root@localhost dd_test]# ...
- wireshark filter manualpage
NAME wireshark-filter - Wireshark filter syntax and reference SYNOPSIS wireshark [other options] [ - ...
- PID控制算法研究
1.matlab模糊控制工具箱:http://blog.csdn.net/gameboy12615/article/details/6367459 2.书籍:先进PID控制MATLAB仿真/刘金琨著 ...
- 基于Spring开发——自定义标签及其解析
1. XML Schema 1.1 最简单的标签 一个最简单的标签,形式如: <bf:head-routing key="1" value="1" to= ...
- 在IntelliJ IDEA中添加repository模板
可以用于快速新建一个repository类,减少开发时间 在IntelliJ IDEA settings设置中(ctrl+alt+s)--Editor--File and Code Templates ...