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.00
1 5 4 4 -1 4 5 3 6

Sample Output:

1.85 2
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const int maxn = 100010;
struct Node{vector<int> child;
}node[maxn];int n,maxdepth = 0,num = 0;
double p,r;void DFS(int index,int depth){if(node[index].child.size() == 0){//    printf("yezi %d\n",depth);if(depth > maxdepth){maxdepth = depth;num = 1;}else if(depth == maxdepth){num++;}return;}for(int i = 0; i < node[index].child.size(); i++){//    printf("jiedian %d\n",node[index].child[i]);DFS(node[index].child[i],depth + 1);}
}
int main(){int father,root;scanf("%d%lf%lf",&n,&p,&r); //p是價格,r是增長率r /= 100;for(int i = 0; i < n; i++){scanf("%d",&father);if(father == -1) root = i;else{node[father].child.push_back(i);}        } DFS(root,0);printf("%.2f %d",p * pow(1 + r,maxdepth),num);return 0;
} 

?

轉載于:https://www.cnblogs.com/wanghao-boke/p/8572275.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/385386.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/385386.shtml
英文地址,請注明出處:http://en.pswp.cn/news/385386.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

opendir、readdir和closedir函數

注意&#xff1a;在Linux中&#xff0c;目錄的輸入格式&#xff1a;/mnt//fghs、/mnt/fghs、/mnt/fghs和/mnt/fghs//是等效的&#xff0c;都一樣。 #include <sys/types.h> #include <dirent.h> DIR *opendir(const char *name); DIR *fdopendir(int fd); 返回…

146. LRU緩存機制

運用你所掌握的數據結構&#xff0c;設計和實現一個 LRU (最近最少使用) 緩存機制。它應該支持以下操作&#xff1a; 獲取數據 get 和 寫入數據 put 。 獲取數據 get(key) - 如果密鑰 (key) 存在于緩存中&#xff0c;則獲取密鑰的值&#xff08;總是正數&#xff09;&#xff…

dup和dup2函數

#include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); 作用&#xff1a;dup函數實現對一個文件的文件描述符進行復制&#xff0c;復制之后該進程就會新增加一一個文件描述符指向該文件&#xff08;即實現同一個文件對應多個文件描述符&#xff0…

fcntl函數(網絡編程會用)

#include <unistd.h> #include <fcntl.h> int fcntl&#xff08;int fd, int cmd&#xff09;&#xff1b; int fcntl&#xff08;int fd, int cmd, long arg&#xff09;&#xff1b;//long 長整型 int fcntl&#xff08;int fd, int cmd, struct flock *lock…

189. 旋轉數組

給定一個數組&#xff0c;將數組中的元素向右移動 k 個位置&#xff0c;其中 k 是非負數。 示例 1: 輸入: [1,2,3,4,5,6,7] 和 k 3 輸出: [5,6,7,1,2,3,4] 解釋: 向右旋轉 1 步: [7,1,2,3,4,5,6] 向右旋轉 2 步: [6,7,1,2,3,4,5] 向右旋轉 3 步: [5,6,7,1,2,3,4]示例 2: 輸…

58. 最后一個單詞的長度

給定一個僅包含大小寫字母和空格 的字符串&#xff0c;返回其最后一個單詞的長度。 如果不存在最后一個單詞&#xff0c;請返回 0 。 說明&#xff1a;一個單詞是指由字母組成&#xff0c;但不包含任何空格的字符串。 示例: 輸入: "Hello World" 輸出: 5 clas…

CPU和MMU(內存管理單元)

CPU的架構&#xff1a;要求能夠理解從源程序到微指令的整個經歷過程&#xff1a;存儲器的層次結構&#xff08;網絡資源下載到硬盤、磁盤緩存、內存、Cache、寄存器&#xff09;&#xff1b;CPU的四大部分&#xff1a;ALU、CU、中斷系統和寄存器&#xff1b;程序執行的整個過程…

【C++ Primer | 09】容器適配器

一、stack s.push(): 向棧內壓入一個成員&#xff1b; s.pop(): 從棧頂彈出一個成員&#xff1b; s.empty(): 如果棧為空返回true&#xff0c;否則返回false&#xff1b; s.top(): 返回棧頂&#xff0c;但不刪除成員&#xff1b; s.size(): 返回棧內元素…

進程控制塊PCB(進程描述符)

&#xff08;1&#xff09;PCB 每個進程在內核中都有一個進程控制塊&#xff08;PCB&#xff09;來維護進程相關的信息&#xff0c;Linux內核的進程控制塊是task_struct結構體。grep -r “task_struct” / 可以查找根目錄下&#xff0c;包含task_struct的文件文件。或者 find…

103. 二叉樹的鋸齒形層次遍歷

給定一個二叉樹&#xff0c;返回其節點值的鋸齒形層次遍歷。&#xff08;即先從左往右&#xff0c;再從右往左進行下一層遍歷&#xff0c;以此類推&#xff0c;層與層之間交替進行&#xff09;。 例如&#xff1a; 給定二叉樹 [3,9,20,null,null,15,7], 3 / \ 9 20 /…

fork、getpid、getppid函數

#include <unistd.h> pid_t fork(void); 作用&#xff1a;創建一個子進程。 到目前為止&#xff0c;我們可以直到兩種創建進程的方法&#xff1a;1. 通過執行二進制文件來創建一個進程&#xff0c;如&#xff1a;./a.out /bin/ls&#xff1b;2.通過fork函數來創建一個…

107. 二叉樹的層次遍歷 II

給定一個二叉樹&#xff0c;返回其節點值自底向上的層次遍歷。 &#xff08;即按從葉子節點所在層到根節點所在的層&#xff0c;逐層從左向右遍歷&#xff09; 例如&#xff1a; 給定二叉樹 [3,9,20,null,null,15,7], 3/ \9 20/ \15 7返回其自底向上的層次遍歷為&#xff…

循環創建N個子進程

以循環創建5個進程為例&#xff0c;給出如下代碼&#xff0c;分析其錯誤&#xff1a; #include <stdio.h> #include <stdlib.h> #include <unistd.h>int main(void) {int i;pid_t pid;printf("xxxxxxxxxxx\n");for (i 0; i < 5; i){pid fork…

【C++ Primer | 19】控制內存分配

1. 測試代碼&#xff1a; #include <iostream> #include <new> #include <cstring> #include <cstdlib> using namespace std;void* operator new(size_t size) {cout << "global Override operator new" << endl;if (void* p…

getuid、geteuid、getgid和getegid函數

#include <unistd.h> #include <sys/types.h> uid_t getuid(void); uid_t geteuid(void); 作用&#xff1a;getuid返回當前進程的實際用戶ID&#xff1b;geteuid返回當前用戶的有效用戶ID。這兩個總是成功&#xff0c;不會失敗。 #include <unistd.h> #…

【第15章】虛函數

一、為什么基類中的析構函數要聲明為虛析構函數&#xff1f; 直接的講&#xff0c;C中基類采用virtual虛析構函數是為了防止內存泄漏。具體地說&#xff0c;如果派生類中申請了內存空間&#xff0c;并在其析構函數中對這些內存空間進行釋放。假設基類中采用的是非虛析構函數&am…

進程共享(讀時共享寫時復制)

父子進程之間在剛fork后。父子相同處: 全局變量、.data、.bbs、.text、棧、堆、環境變量、用戶ID、宿主目錄&#xff08;進程用戶家目錄&#xff09;、進程工作目錄、信號處理方式等等&#xff0c;即0~3G的用戶空間是完全一樣的。父子不同處: 1.進程ID 2.fork返回值 3.父進…

【C++ Primer | 08】IO庫

一、istringstream類 描述&#xff1a;從流中提取數據&#xff0c;支持 >> 操作 這里字符串可以包括多個單詞&#xff0c;單詞之間使用空格分開 #include <iostream> #include <sstream> using namespace std; int main() {istringstream istr(&quo…

gdb調試(如何跟蹤指定進程)

使用gdb調試的時候&#xff0c;gdb只能跟蹤一個進程。可以在fork函數調用之前&#xff0c;通過指令設置gdb調試工具跟蹤父進程或者是跟蹤子進程。默認跟蹤父進程。 set follow-fork-mode child 命令設置gdb在fork之后跟蹤子進程。 set follow-fork-mode parent 設置跟蹤父進程…

【Leetcode | 01】Backtracking

回溯算法序號題號117. 電話號碼的字母組合222. 括號生成 39. 組合總和 40. 組合總和 II 46. 全排列 47. 全排列 II 60. 第k個排列 77. 組合 78. 子集 90. 子集 II 93. 復原IP地址 131. 分割回文串 216. 組合總和 III 306. 累加數 357. 計算各個位數不同的數字個數 401. 二進…