Silly question...
I have always wanted to talk about PAT's question. Data and other things are not very clever. I should not be too casual.
This question can only be performed by double members. Note that f cannot be added after float... the variable is double, but it still cannot be used. It feels strange. It may be a binary expression, big data happens to be 0.5 or 0.25, so I changed it to double, but I didn't change the f result after 0.01...
Simple BFS
1 # include <vector> 2 # include <iostream> 3 # include <queue> 4 # include <iomanip> 5 6 using namespace std; 7 8 double bfs (const vector <int> & graph, const double p, const double r) {9 double p_fac = (double) (1.0 + r * 0.01 ); 10 double cur_price = p; 11 double res = 0.0f; 12 13 queue <int> cur_level; 14 cur_level.push (0); 15 while (! Cur_level.empty () {16 queue <int> next_level; 17 18 while (! Cur_level.empty () {19 int cur_idx = cur_level.front (); 20 cur_level.pop (); 21 22 int size = graph [cur_idx] [0]; 23 if (size = 0) {24 res + = graph [cur_idx] [1] * cur_price; 25} else {26 for (int I = 1; I <size + 1; I ++) {27 next_level.push (graph [cur_idx] [I]); 28} 29} 30} 31 32 cur_price * = p_fac; 33 cur_level = next_level; 34} 35 36 return res; 37} 38 39 int main () {40 int N; 41 double P, r; 42 43 cin >>n> P> r; 44 45 vector <int> graph (N, vector <int> (); 46 for (int I = 0; I <N; I ++) {47 int cnt, num; 48 cin> cnt; 49 graph [I]. push_back (cnt); 50 51 if (cnt = 0) {52 cin> num; 53 graph [I]. push_back (num); 54} else {55 for (int j = 0; j <cnt; j ++) {56 cin> num; 57 graph [I]. push_back (num); 58} 59} 60} 61 62 double res = bfs (graph, P, r); 63 64 cout <fixed <setprecision (1) <res <endl; 65 66 return 0; 67}
PAT 1079