PAT(甲级)1090
来源:互联网 发布:数据查询接口 编辑:程序博客网 时间:2024/05/13 12:27
1090. Highest Price in Supply Chain (25)
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.001 5 4 4 -1 4 5 3 6Sample Output:
1.85 2
#include <iostream>#include <deque>#include <vector>#include <cstring>#define SIZE 100005using namespace std;/////////////////////////////////////////////////////////////where is the bug???????????????????// no bug ,maybe affeted by some other unrelated code///////////////////////////////////////////////////////////////////deque<int> q;vector<vector<int> > v(SIZE);int main(){int root,num,N;double p,r;freopen("test.txt","r",stdin);scanf("%d%lf%lf",&N,&p,&r);r =r/100+1;for(int i = 0;i<N;i++){ //creating chain listscanf("%d",&num);if(num != -1) v[num].push_back(i); else root = i;}int count=0,count1=0; //maybe count must be initialized as 0 q.push_back(root); q.push_back(-1); while(count1 !=N){ int curr = q.front(); if(curr == -1){ count = 0; p *=r; q.push_back(-1);}else{if(v[curr].size()){q.insert(q.end(),v[curr].begin(),v[curr].end());} count1++;count++;}q.pop_front();}printf("%.2lf %d\n",p,count);fclose(stdin);return 0;}
- PAT(甲级)1090
- PAT甲级1090
- PAT 甲级
- 浙大PAT甲级 1090 广搜
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- PAT(甲级)1014
- [前端] 定位光标位置
- tomcat性能调优
- 谈业务流程全生命周期管理支撑业务流程再造(3)
- 城市天气三小时预报,天气预报接口实现
- Android 回调实例详解
- PAT(甲级)1090
- 青少年如何使用 Python 开始游戏开发
- jQuery.validate验证上传文件大小
- Android如何调用支付宝支付 微信支付
- mysql 索引设计准则
- 在Ubuntu中安装Redis
- Retrofit 1.9源码学习
- c/c++生成不重复的字符串(6个字符组成,可表示的个数可以扩充),简易版数据库主键
- 模块