[刷题]算法竞赛入门经典(第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 ...
随机推荐
- 深入理解Stream流水线
前面我们已经学会如何使用Stream API,用起来真的很爽,但简洁的方法下面似乎隐藏着无尽的秘密,如此强大的API是如何实现的呢?Pipeline是怎么执行的,每次方法调用都会导致一次迭代吗?自动并 ...
- 【Electron】Electron开发入门(一):开发环境搭建
刚接触Electron+js开发PC端桌面应用程序的时候,简直一头雾水,搜了网上很多教程,有的要么讲的零零碎碎,要么就是版本太低,很多API语法都不能用了:现在我把一些有用的教程归纳一下,并把目前最新 ...
- 老李分享:Android -自动化埋点 2
除了上述的事件,Android提供了一个OnTouchListener的监听器,当事件传递到控件的时候,如果控件注册了这个监听器,则会执行监听器中的onTouch方法.同时,如果它返回true,则事件 ...
- 深入学习 DUBBO
1.什么是 RPC 协议? RPC 的全称是 Remote Procedure Call 是一种进程间通信方式.它允许程序调用另一个地址空间(通常是共享网络的另一台机器上)的过程或函数,而不用程序员显 ...
- body全屏
html, body { min-height: 100%; }
- a标签传值乱码问题怎么解?
- 跟着刚哥梳理java知识点——HelloWorld和常见问题(一)
1.按照国际惯例,写一段输出HelloWorld的java语句: public class HelloWorld { //这是main方法,程序的主入口 public static void main ...
- JS中的函数、Bom、DOM及JS事件
本期博主给大家带来JS的函数.Bom.DOM操作,以及JS各种常用的数据类型的相关知识,同时,这也是JavaScript极其重要的部分,博主将详细介绍各种属性的用法和方法. 一.JS中的函数 [函数的 ...
- MTK elian(smartlink)在WIN32下的实现
先说明一下调试技巧:该程序需无线网卡实现功能,由于PC端有可能是多网卡的(有线网卡.无线网卡.虚拟网卡),所以在发包的时候数据包不一定会从无线网卡出,lib库应该也没处理多网卡的选择吧.所以在调试的时 ...
- js原型二
function Box(name,age){ this.name = name; this.age = age; this.family = ['哥哥',‘姐姐’,‘妹妹’]: } Box.prot ...