1090. Highest Price in Supply Chain (25)
2016-05-07 16:53
447 查看
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.
Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. It is assumed that each member in the supply chain has exactly one supplier except the root
supplier, and there is no supply cycle.
Now given a supply chain, you are supposed to tell the highest price we can expect from some retailers.
Input Specification:
Each input file contains one test case. For each case, The first line contains three positive numbers: N (<=105), the total number of the members in the supply chain (and hence they are numbered from 0 to N-1); P, the price given by the root supplier; and r,
the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number Si is the index of the supplier for the i-th member. Sroot for the root supplier is defined to be -1. All the numbers in a line are
separated by a space.
Output Specification:
For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the
price will not exceed 1010.
Sample Input:
9 1.80 1.00
1 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2
IDEA
1.树形结构的存储;
2.树的层序遍历,并统计其level和最后一层的节点数
CODE
Starting from one root supplier, everyone on the chain buys products from one's supplier in a price P and sell or distribute them in a price that is r% higher than P. It is assumed that each member in the supply chain has exactly one supplier except the root
supplier, and there is no supply cycle.
Now given a supply chain, you are supposed to tell the highest price we can expect from some retailers.
Input Specification:
Each input file contains one test case. For each case, The first line contains three positive numbers: N (<=105), the total number of the members in the supply chain (and hence they are numbered from 0 to N-1); P, the price given by the root supplier; and r,
the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number Si is the index of the supplier for the i-th member. Sroot for the root supplier is defined to be -1. All the numbers in a line are
separated by a space.
Output Specification:
For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the
price will not exceed 1010.
Sample Input:
9 1.80 1.00
1 5 4 4 -1 4 5 3 6
Sample Output:
1.85 2
IDEA
1.树形结构的存储;
2.树的层序遍历,并统计其level和最后一层的节点数
CODE
#include<iostream> #include<cstdio> #include<vector> #include<queue> #include<iomanip> #include<fstream> using namespace std; #define MAX 100001 int main(){ vector< vector<int> > s(MAX); int n; double p,r; //freopen("input.txt","r",stdin); cin>>n>>p>>r; int root; for(int i=0;i<n;i++){ int sup; cin>>sup; if(sup==-1){ root=i; }else{ s[sup].push_back(i); } } int level=-1,count1=1,count2=0,tmp_count; queue<int> q; q.push(root); while(!q.empty()){ for(int i=0;i<count1;i++){ int head=q.front(); q.pop(); for(int j=0;j<s[head].size();j++){ q.push(s[head][j]); count2++; } } level++; tmp_count=count1; count1=count2; count2=0; } //cout<<level<<" "<<tmp_count<<endl; double price=p; for(int i=0;i<level;i++){ price*=(1+r/100); //cout<<fixed<<setprecision(2)<<price<<endl; } cout<<fixed<<setprecision(2)<<price<<" "<<tmp_count; //fclose(stdin); return 0; }
相关文章推荐
- keychain service钥匙串服务
- HDU 4251-The Famous ICPC Team Again(划分树-区间中位数)
- 理解notify()/notifyall()/interupt()对于线程里面wait方法的影响
- 服务器TIME_WAIT和CLOSE_WAIT详解
- 11周1--2以Point为基类,派生出一个Circle(圆)类,增加数据成员r(半径),以及求面积的成员函数area,实现其他需要的成员函数,设计main函数完成测试;
- 进入BrowsermainRunner::Run处理消息
- windows安装Apache,注册服务出现“(OS 5)拒绝访问。 : AH00369: Failed to open the WinNT service manager..."错误
- 【模拟】HDU1302The Snail
- Too many classes in --main-dex-list
- saiku安装方法总结
- 无障碍开发系列之WAI-ARIA
- Mongodb无法创建用户:MongoDB AuthenticationFailed with mechanism MONGODB-CR
- Aidl
- 为iPhone6设计自适应布局(二)
- 为iPhone 6设计自适应布局(一)
- Geoserver的ImageMosaic数据源添加以及服务发布
- Geoserver的ImageMosaic数据源添加以及服务发布
- 关于int main( int argc, char *argv[] )
- AIDL完全学习手册
- int main()还是void main()