美團一面

1.交換左右子樹

void SwapChild(Tree T)
{
	Tree Tmp;

	if(T != NULL || T->Left == NULL && T->Right == NULL)
			return;
	SwapChild(T->Left);
	SwapChild(T->Right);
	Tmp = T->Left;
	T->Left = T->Right;
	T->Right = Tmp;
}
2. 梯度計費問題(1T=1000G)

流量 價格
0-200G 0.5
200G-2T 0.45
2T-20T 0.4
20T-200T 0.35
200T以上 0.3
#define N 5
double flow[N] = { 0, 200, 2000, 20000, 200000 };
double price[N+1] = { 0, 0.5, 0.45, 0.4, 0.35, 0.3 };

double totalprice(double n)
{
	double sum = 0.0, tmp;
	int i = 1;

	while(i < N && n >= flow[i])
	{
		tmp = flow[i] - flow[i-1];
		sum += tmp * price[i];
		i++;
	}
	tmp = n - flow[i-1];
	sum += tmp * price[i];
	return sum;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章