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

基本思想:

雷同题目,不再赘述;

关键点:

无;

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;


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

struct node {
	vector<int>child;
	int layer;
};

vector<node>tree;

void layer_init() {
	if (tree.size() == 0)
		return;
	tree[0].layer = 0;
	queue<int>q;
	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;
}

  

猜你喜欢

转载自www.cnblogs.com/songlinxuan/p/12307364.html