PAT (Advanced level) practise 1090 highest price in Supply Chain () __pat/pta Serie A

Source: Internet
Author: User
Tags int size

1090. Highest price in Supply Chain (a) time limit MS
Memory Limit 65536 KB
Code length limit 16000 B
Standard author CHEN, Yue

A supply chain is a network of retailers (retailer), distributors (reseller), and suppliers (suppliers)--everyone involved in moving a produ CT 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 Distribu Te them in a and is r% higher than P. It is assumed this supply chain has exactly one supplier except the root supplier, and there is no supp Ly cycle.

Now given a supply chain, your are supposed to tell the highest price we can expect from some retailers.

Input Specification:

Each input file contains one test case. For the 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 to 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 are defined to be-1. All of the numbers in a line are separated by a.

Output Specification:

For each test case, print at one line the highest price we can expect from some retailers, accurate up to 2 decimal places , and the number of retailers that sell in the highest price. There must is one space between the two numbers. It is guaranteed this price would not exceed 1010. Sample Input:

9 1.80 1.00
1 5 4 4-1 4 5 3 6
Sample Output:
1.85 2


The following: A total of n individuals, respectively, for retailers, distributors and suppliers, suppliers for the root node, retailers for leaf node, give you an item of the initial price, each pass will increase the r%, ask retailers how much money to sell, how many suppliers can sell the most money


#include <iostream> #include <cstdio> #include <cstring> #include <string> #include < algorithm> #include <cmath> #include <map> #include <set> #include <stack> #include <queue

> #include <vector> #include <bitset> using namespace std;

#define LL-long const int INF = 0X3F3F3F3F;
int n,a[100009],cnt,root;
Double P,r,ma;

vector<int>g[100009];
    void Dfs (int k,double x) {if (x>ma) ma=x,cnt=1;
    else if (x==ma) cnt++;
    int size=g[k].size ();
for (int i=0;i<size;i++) DFS (g[k][i],x* (1+1.0*r/100));
        int main () {while (~scanf ("%d%lf%lf", &n,&p,&r)) {ma=-1;
        for (int i=0;i<n;i++) g[i].clear ();
            for (int i=0;i<n;i++) {scanf ("%d", &a[i]);
            if (a[i]==-1) {root=i;continue;}
        G[a[i]].push_back (i);
        DFS (ROOT,P);
    printf ("%.2lf%d\n", ma,cnt);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.