UVa 712
来源:互联网 发布:https的默认端口 编辑:程序博客网 时间:2024/06/16 21:17
1.用完全二叉树
#include <stdio.h>int order[10];int fulltree[2000];int ans[10];char str[2000];int calculate(char* str, int n){ int i; int p = 0; for(i = 0; i < n; i++) { if( str[order[i]-1] == '0') p = p * 2 + 1; else p = p * 2 + 2; } return fulltree[p];}int main(){ int cas = 0; while(1) { cas++; int n, m, i; char temp; char vva[10]; memset(ans, 0, sizeof(ans)); scanf("%d", &n); memset(order, 0, sizeof(order)); memset(fulltree, 0, sizeof(fulltree)); getchar(); if(!n) break; for(i = 0; i < n; i++) { scanf("%c%d",&temp, &order[i]); getchar(); } scanf("%s", str); for(i = (1<<n) - 1; i < (2<<n); i++) fulltree[i] = str[i-(1<<n) + 1] - '0'; scanf("%d", &m); for(i = 0; i < m; i++) { scanf("%s", vva); ans[i] = calculate(vva, n); } printf("S-Tree #%d:\n",cas); for(i = 0; i < m; i++) printf("%d", ans[i]); printf("\n\n"); } return 0;}
另一种是用二进制的思想,即为:把目标数列按照数的处理顺序排好形成的二进制串对应的十进制即为相应的答案的下标
主要函数如下:
void f(string s, string s1, vector<int> floor) { int t = 1, k = 0; for(int i = floor.size()-1; i >= 0; --i) { k += (s1[floor[i]-1] - '0') * t; t *= 2; } cout << s[k];}
0 0
- uva 712
- uva 712
- uva 712
- uva 712
- uva - 712
- UVa 712
- uva 712
- uva 712
- UVA 712
- UVa 712 S-Trees
- UVa 712 - S-Trees
- Uva 712 S-Trees
- uva 712 - S-Trees
- uva 712 - S-Trees
- UVa 712 - S-Trees
- UVA 712 S-Trees
- uva-712 S-Trees
- uva 712-S-Trees
- java篇 【5】运算符优先级
- 十一第三题Binary Tree Level Order Traversal II
- C++基础编程---1.3模糊概念
- 碎屑
- Cube Stacking
- UVa 712
- iOS开发实用技术之换肤和静态库
- 权限管理命令-其他权限管理命令
- Android Api Demos登顶之路(八十四)Graphics-->PolyToPoly
- hihoCoder#1090
- Remove Duplicates from Sorted List II
- 1688配置信息
- 之字形打印二叉树
- AppleTV 不显示 Store 的问题