UVa 699 Falling Leaves
来源:互联网 发布:模拟基金软件有哪些 编辑:程序博客网 时间:2024/06/05 14:53
#include<stdio.h>#define HASHSIZE 20000typedef struct TreeNode{ int val; int pos; struct TreeNode* left; struct TreeNode* right;}Node;int arr[HASHSIZE];int hashmap[HASHSIZE];int ans[HASHSIZE];void preorder(Node* rt){ if(rt == NULL) return; printf("%d ", rt->pos); preorder(rt->left); preorder(rt->right);}Node* buildtree(int* cur, int p){ if(arr[*cur] == -1) { (*cur)++; return NULL; } Node* newnode = (Node*)malloc(sizeof(Node)); newnode->val = arr[*cur]; newnode->pos = p; hashmap[newnode->pos] += newnode->val; (*cur)++; newnode->left = buildtree(cur, p-1); newnode->right = buildtree(cur, p+1); return newnode;}void ReadInput(){ int i, leaf, nonleaf; int num = 1; while(1) { i = 0, leaf = 0, nonleaf = 0; memset(ans, 0, sizeof(ans)); memset(hashmap, 0, sizeof(hashmap)); do { scanf("%d", &arr[i]); if(arr[i] == -1) leaf++; else nonleaf++; i++; }while((nonleaf+1) != leaf); if(leaf == 1) break; int c = 0; Node* root = buildtree(&c, HASHSIZE/2); int j = 0, k = 0; for(j = 0; j < HASHSIZE; j++) if(hashmap[j]) ans[k++] = hashmap[j]; printf("Case %d:\n", num++); for(j = 0; j < k; j++) { if(j != k - 1) printf("%d ", ans[j]); else printf("%d", ans[j]); } printf("\n\n"); }}int main(){ ReadInput(); return 0;}
0 0
- UVa 699 Falling Leaves
- uva 699 - The Falling Leaves
- uva 699 The Falling Leaves
- uva 699 - The Falling Leaves
- UVa 699 - The Falling Leaves
- UVA 699 - The Falling Leaves
- UVa 699 - The Falling Leaves
- uva 699 The Falling Leaves
- uva-699 The Falling Leaves
- UVA 699 The Falling Leaves
- uva 699 The Falling Leaves
- UVA 699 - The Falling Leaves
- uva 699 The Falling Leaves
- uva 699 - The Falling Leaves
- UVa 699 - The Falling Leaves
- UVA 699 The Falling Leaves
- UVA - 699 The Falling Leaves
- UVA 699 The Falling Leaves
- Androidpn 消息推送总结(转)
- 关于A*寻路算法的实现
- 电脑在 Parallels Access 中显示离线该怎么办?
- 一位职业程序员的进化过程
- MyBatis 入门01
- UVa 699 Falling Leaves
- +與array_merge合併數組的區別
- web项目java EE Module Dependencies
- mac下安装lxml
- mkdir-无法创建目录-过多的连接
- java题目
- matlab求解-a(发展系数)的方法。
- 如何查询oracle中sql操作的记录
- android新版本中如何解决厂商应用的su权限