zoukankan      html  css  js  c++  java
  • PAT A1090 Highest Price in Supply Chain (25分)(边界问题)

    #include<cstdio>
    #include<vector>
    #include<math.h>
    #include<queue>
    using namespace std;
    const int N = 100010;
    struct node{
        bool isretailer=true;
        vector<int> child;
        int deep;
    }Node[N];
    int n;
    double p,r;
    
    void updatedeep(int root){
        queue<int> q;
        if(root==-1) return;
        q.push(root);
        Node[root].deep = 0;
        while(q.empty()==false){
            int front = q.front();
            q.pop();
            for(int i  = 0;i<Node[front].child.size();i++){
                int childid = Node[front].child[i];
                Node[childid].deep = Node[front].deep+1;
                q.push(childid);
            }
        }
        return;
    }
    int main(){
        scanf("%d %lf %lf",&n,&p,&r);
        int root=-1;
    // 9 1.80 1.00
    // 1 5 4 4 -1 4 5 3 6
        for(int i = 0;i<n;i++){
            
            int father;
            scanf("%d",&father);
            if(father==-1){
                root = i;
                continue;
            }else{
                Node[father].child.push_back(i);
                Node[father].isretailer  = false;
            }
        }
        updatedeep(root);
        int maxdeep = 0;
        int count = 0;
        for(int i = 0;i<n;i++){
            if(Node[i].isretailer==true){
                if(Node[i].deep>maxdeep){
                    maxdeep = Node[i].deep;
                    count = 1;
                }else if(Node[i].deep == maxdeep){
                    count++;
                }
            }
        }
        double rate = 1 + r/100;
        double max = p*pow(rate,maxdeep);
        printf("%.2f %d",max,count);
        return 0;
    }
    
  • 相关阅读:
    javascript变量
    javascript数据类型
    javascript基本语法
    javascript用法
    javascript简介
    js 随机生成颜色值
    JS 判断传入的变量类型是否是Array
    swiper2 swiper-slide 之间的间距调整
    IE9以及以下不支持jquery ajax跨域问题
    HBuilder只提示html 不提示js
  • 原文地址:https://www.cnblogs.com/shuibeng/p/13634360.html
Copyright © 2011-2022 走看看