uva_699_The Falling Leaves
2012-11-07 17:52
225 查看
无需建树,递归写入数组,然后就是答案输出。 #include <cstdio> #include <cstring> #define MAXN 1001 int rst[MAXN], val; void recusion_set_rst(const int &idx) { scanf("%d", &val); if( -1 != val ) { rst[idx-1] += val; recusion_set_rst(idx-1); } scanf("%d", &val); if( -1 != val ) { rst[idx+1] += val; recusion_set_rst(idx+1); } } int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); #endif int cas(1), idx; while( scanf("%d", &val) && (-1 != val) ) { memset(rst, 0, sizeof(rst)); idx = MAXN>>1; rst[idx] += val; recusion_set_rst(idx); printf("Case %d:\n", cas ++); idx = 0; for(int i = 0; i < MAXN; i ++) { if( !rst[i] ) { continue; } if( idx ) { printf(" "); } else { idx = 1; } printf("%d", rst[i]); } printf("\n\n"); } return 0; }
相关文章推荐
- uva 699 The Falling Leaves
- UVa 699 The Falling Leaves
- UVa699-The Falling Leaves(下落的叶子)
- uva-699 The Falling Leaves
- UVA699-例题6-10 下落的树叶(The Falling Leaves,UVa 699)
- 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(二叉树|DFS)
- 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 (递归先序建立二叉树)
- Uva699 The Falling Leaves
- UVA 699 The Falling Leaves
- uva 699 The Falling Leaves