PAT2020春3月份 1090 Highest Price in Supply Chain 经验分享和心路历程

题干:https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944

题解:做了30分钟,拿了满分

// A1090.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <bits/stdc++.h>
using namespace std;
#define max 100010
unordered_map<int, vector<int>> gn;
unordered_map<int, bool> visit;
//vector<bool> visit(max, false);
int n; double p, r;
double highest_price = -1;
vector<double> an;

void DFS(int root,double p) {
    if (p > highest_price) {
        highest_price = p;
    }
    if (gn[root].size() == 0) {
        an.push_back(p);
        return;
    }
    for (int i = 0; i < gn[root].size(); i++) {
        if (visit[gn[root][i]] != true) {
            visit[gn[root][i]] = true;//debug 不等于true的时候,可以进行遍历,但是在遍历以后要设为true
            DFS(gn[root][i],p*(1.0+r));//debug 不是直接输入root,是用它的领接表里面的内容
            visit[gn[root][i]] = false;
        }
    }
}
int main()
{
#ifndef ONLINE_JUDGE
    FILE* s1;
    freopen_s(&s1, "in.txt", "r", stdin);
#endif // !ONLINE_JUDGE

    cin >> n >> p >> r;
    r = r / 100.0; //debug r没有除100之前是不能用的,因为有一个百分比的说法
    int s;
    int root = -1;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s != -1) {
            gn[s].push_back(i);
        }
        else {
            root = i;
        }   
    }
    DFS(root,p);
    int match = 0;
    for (int i = 0; i < an.size(); i++) {
        if (an[i] == highest_price) {
            match++;
        }
    }
    
    printf("%.2f %d\n",highest_price,match);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Exodus&Focus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值