Tips:
- 真是no zuo no die.说好的尽量用C来写,脑子一抽,又用Java来写了,最直接的方法,结果来了个超时.好吧,以为是算法问题,继续改,各种思路,仍得不到解决.换C++吧,还是各种思路,没能AC.最后想试试看用C++来写最开始的最直接的方法,呵呵,AC了…再说一遍,没什么事别用Java!!!
- 这题没什么技巧,也没什么陷阱,无非就先把输入的数据用二维数组保存起来,然后用到了队列.其它没什么好说的了.虽然是个25分的题,但我认为难度不大.
#include "iostream"
using namespace std;
int main(int argc, const char * argv[]) {
int n,i,j,m,len,index;
double p,r,amount;
int **chain,*tree;
double *price;
while (scanf("%d %lf %lf",&n,&p,&r) != EOF) {
chain = new int*[n];
tree = new int[n];
price = new double[n];
price[0] = p;
amount = 0.0;
for(i = 0;i < n;i++){
scanf("%d",&m);
if(m == 0)
len = 2;
else
len = m + 1;
chain[i] = new int[len];
chain[i][0] = m;
for(j = 1;j < len;j++)
scanf("%d",&chain[i][j]);
}
tree[0] = 0;
for(i = 0,index = 1;i < n;i++){
if(chain[tree[i]][0] == 0)
amount += price[tree[i]] * chain[tree[i]][1];
else{
for(j = 1;j <= chain[tree[i]][0];j++){
tree[index++] = chain[tree[i]][j];
price[chain[tree[i]][j]] = price[tree[i]] * (1 + r / 100);
}
}
}
printf("%.1lf\n",amount);
}
return 0;
}