PAT 甲 1106 Lowest Price in Supply Chain

news/2024/7/20 21:31:58 标签: 深度优先, 算法, 树结构, c++

2022.1.28 练习 PAT甲 1106 Lowest Price in Supply Chain(原题链接)

题解如下:

#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE=100010;
const int INF=1e8;
int n;
double p,r;

vector<int> child[MAX_SIZE];

int min_high=INF,num=0;

void DFS(int index,int high)
{
    if(child[index].size()==0)
    {
        if(high<min_high)
        {
            min_high=high;
            num=1;
        }
        else if(high==min_high)
        {
            num++;
        }
        return;
    }
    for(unsigned int i=0;i<child[index].size();i++)
    {
        DFS(child[index][i],high+1);
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin>>n>>p>>r;
    r=r/100;
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            child[i].push_back(tmp);
        }
    }
    DFS(0,0);
    cout<<setiosflags(ios::fixed)<<setprecision(4)<<p*pow(1+r,min_high)<<" "<<num;
    return 0;
}


http://www.niftyadmin.cn/n/1265240.html

相关文章

二三四五方法论

二三四五方法论价 值 观一、2345文化坦诚客观如实&#xff0c;不忽悠、不糊弄、不隐瞒 不增不减&#xff0c;好的不多说&#xff0c;坏的不少说简单为人处事&#xff0c;简单是真理 把复杂的事变简单&#xff0c;才能抓住重点直接有话直说&#xff0c;直达目的、不绕弯、不留情…

PAT 甲 1079 Total Sales of Supply Chain

2022.1.28 练习 PAT甲 1079 Total Sales of Supply Chain &#xff08;原题链接&#xff09; 题解如下&#xff1a; #include <bits/stdc.h> using namespace std; const int MAX_SIZE100010; int n; double p,r;struct node {int data;vector<int> child; }Node…

垂直旋转的TextView

有需要需要使用到文字纵向布局 但是找了一便竟然没找到一个可用的&#xff0c;于是自己自定义一个,做个记录 ​​​​​​​

PAT 甲 1004 Counting Leaves

2022.1.28 练习 PAT甲 1004 Counting Leaves &#xff08;原题链接&#xff09; 题解如下&#xff1a; #include <bits/stdc.h> using namespace std; const int MAX_SIZE110; int num[MAX_SIZE]{0};vector<int> Node[MAX_SIZE];int max_high0;void DFS(int inde…

android仪表盘,柱形图,折线图,类似于监控网速的那种

刚工作不久&#xff0c;老大给了我一个仪表盘的地址&#xff0c;叫我去下载&#xff0c;下载完之后发现是用图片做背景的&#xff0c; 效果是这样的&#xff1a; 这个不符合要求&#xff0c;老大要求自己画&#xff0c; oh&#xff0c;my god&#xff0c;这个超浪费时间&#…

妙啊 PAT 甲 1064 Complete Binary Search Tree

2022.1.28 练习 PAT甲 1064 Complete Binary Search Tree &#xff08;原题链接&#xff09; 妙啊&#xff0c;自己想的好麻烦&#xff0c;一看算法笔记上的题解&#xff0c;佩服佩服&#xff0c;我的脑袋怎么这么不转弯。。。 思想&#xff1a; 步骤1&#xff1a; 如果使用…

PAT 甲 1099 Build A Binary Search Tree

2022.1.28 练习 PAT甲 1099 Build A Binary Search Tree &#xff08;原题链接&#xff09; 题解如下&#xff1a; #include <bits/stdc.h> using namespace std; const int MAX_SIZE110; int n; int indexx0; int num[MAX_SIZE];struct node {int data;int lchild;int…

Android仪表盘

仪表盘&#xff0c;看到这个我无奈了&#xff0c; 老大说要用这个&#xff0c;网上找的他说都好难看 然后自己改额&#xff0c;改动第三方的源码&#xff0c;改了挺久 最后出来了这个效果最后看到效果 发现改的值得了MainActivity.java 代码package com.example.testybp.act…