• UVA699-落叶-二叉树


    1:用一根数轴,根结点是坐标index,左结点-1,右结点+1

    还有一个0ms的不知道怎么过的

    #include<stdio.h>
    #include<iostream>
    #include <strstream>
    #include<string>
    #include<memory.h>
    #include<sstream>
    using namespace std;
    void caculate(int* tree, int index, int* min, int*max)
    {
    	int s;
    	cin >> s;
    	if (s != -1)
    	{
    		tree[index - 1] += s;
    		if ((index - 1) < *min)
    		{
    			*min = index-1;
    		}
    		caculate(tree, index - 1, min, max);
    	}
    	cin >> s;
    	if (s != -1)
    	{
    		tree[index + 1] += s;
    		if ((index +1) > *max)
    			{
    				*max = index+1;
    			}
    		caculate(tree, index + 1, min, max);
    	}
    }
    int main()
    {
    	freopen("d:\1.txt", "r", stdin);
    	int MAXN = 10000;
    	int number = 1;
    	while (cin)
    	{
    		int MIDDLE = 5000;
    		int total[MAXN];
    		memset(total, 0, sizeof(int) * MAXN);
    		int s;
    		cin >> s;
    		if (s == -1)
    			return 0;
    		else
    		{
    			int max = MIDDLE;
    			int min = MIDDLE;
    			total[MIDDLE] += s;
    			caculate(total, MIDDLE, &min, &max);
    			cout << "Case " << number << ":" << endl;
    			for (int i = min; i <= max; i++)
    				if (i == min)
    					cout << total[i];
    				else
    					cout << " " << total[i];
    			cout << endl<<endl;
    		}
    		number++;
    	}
    }
    

      

  • 相关阅读:
    使用RF(robotframework)要安装哪些库
    MYSQL题目练习专用
    MySQL字段拼接
    WPF样式
    WPF数据模板
    WPF控件模板
    WPF布局
    面向对象程序设计原则
    设计模式之策略模式
    设计模式之简单工厂模式
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/6836673.html
Copyright © 2020-2023  润新知