1106 Lowest Price in Supply Chain (25point(s)) Easy only once

基本思想:

雷同题目,不再赘述;

 

关键点:

无;

 

#include
#include
#include
#include 
#include
#include
#include
#include
#include
#include
using namespace std;


int n;
double p, r;
double fin=10000000;
int cnt = 0;

struct node {
	vectorchild;
	int layer;
};

vectortree;

void layer_init() {
	if (tree.size() == 0)
		return;
	tree[0].layer = 0;
	queueq;
	q.push(0);
	while (!q.empty()){
		int index = q.front();
		q.pop();
		for (int i = 0; i < tree[index].child.size(); i++) {
			tree[tree[index].child[i]].layer = tree[index].layer + 1;
			q.push(tree[index].child[i]);
		}
	}
}

void layer_find(int n) {
	double k;
	if (tree[n].child.size() == 0) {
		k = p * pow(1 + 0.01*r, tree[n].layer);
		//cout << k << endl;
		if (k < fin) {
			fin = k;
			cnt = 1;
		}
		else if (k == fin) {
			cnt++;
		}
		return;
	}
	for (int i = 0; i < tree[n].child.size(); i++) {
		layer_find(tree[n].child[i]);
	}
}

int main() {
	cin >> n >> p >> r;
	tree.resize(n);
	int a, b;
	for (int i = 0; i < n; i++) {
		cin >> a;
		for (int j = 0; j < a; j++) {
			cin >> b;
			tree[i].child.push_back(b);
		}
	}
	layer_init();
	layer_find(0);
	printf("%.4lf %d", fin, cnt);
	return 0;
}

  

你可能感兴趣的:(1106 Lowest Price in Supply Chain (25point(s)) Easy only once)