1090. Highest Price in Supply Chain (25)
来源:互联网 发布:上海盘石软件电话 编辑:程序博客网 时间:2024/05/16 09:35
零售商+经销商+厂商=N(代号0~N-1) 厂家直销价格p 每次转手价格增加百分之r1090. Highest Price in Supply Chain (25)
时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA 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.001 5 4 4 -1 4 5 3 6Sample Output:1.85 2
N个数(代表0~N-1从对应的代号买的,当数为-1,说明这家是厂家)
求消费者可以预期到最高价格是多少,并给出count家卖的价格是这个最高的
评测结果
时间 结果 得分 题目 语言 用时(ms) 内存(kB) 用户 8月18日 21:08答案正确251090C++ (g++ 4.7.2)395812datrilla测试点
测试点 结果 用时(ms) 内存(kB) 得分/满分 0答案正确130812/121答案正确3957603/32答案正确3958123/33答案正确13081/14答案正确3232481/15答案正确13082/26答案正确3543803/3
#include<iostream> #include<vector> #include<queue>#include<iomanip>using namespace std; void readln(vector<vector<int>>*solds, int N,int &root){ int temp; for (int index = 0; index<N; index++) { cin >>temp; if (temp== -1)root = index; else (*solds)[temp].push_back(index); }}void BFSmaxprice(vector<vector<int>>*solds, double p, double r, double&maxprice,int &count,int root){ if ((*solds)[root].size() == 0) { maxprice = p; count = 1; } else { queue<pair<int, double>>Q; Q.push(make_pair(root, p )); while (!Q.empty()) { root = Q.front().first; p = Q.front().second*(100 + r) / 100; Q.pop(); for (vector<int>::iterator iter = (*solds)[root].begin(); iter != (*solds)[root].end(); iter++) { if ((*solds)[(*iter)].size() > 0) { Q.push(make_pair((*iter), p)); } else { if (0 == count ||p > maxprice) { count = 1; maxprice = p; } else if (p == maxprice)count++; } } } }}int main(){ int N,root; double p, r,maxprice; cin >> N >> p >> r; vector<vector<int>>solds(N); readln(&solds, N, root); N = 0; BFSmaxprice(&solds, p, r, maxprice, N, root); cout << setiosflags(ios::fixed) << setprecision(2) <<maxprice<< " " << N << endl; system("pause"); return 0;}
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- 1090. Highest Price in Supply Chain (25)
- Eclipse快捷键
- 字符串处理函数:复值函数strcpy、比较函数strcmp、连接函数strcat、大写转换函数strupr
- 杭电 1869 六度分离(floyd &&dijkstra)
- iOS 设计模式之工厂模式
- 关于android中控件位置属性的解释
- 1090. Highest Price in Supply Chain (25)
- Moist (cin,getline的区别)
- Python StringIO与cStringIO
- JAVA_SE基础——23.类的定义
- hdu5102 The K-th Distance bfs+结构体
- 时间序列学习笔记
- MyEclipse配置Hibernate/MyEclipse反向工程从数据表生成POJO和对象关系映射文件(以及HibernateSessionFactory)
- ACM经典算法之数学问题模板
- SQL注入之DVWA平台测试mysql注入