PAT 甲級(jí) 刷題日記|A 1106 Lowest Price in Supply Chain (25 分)

題目

A supply chain is a network of retailers(零售商), distributors(經(jīng)銷商), and suppliers(供應(yīng)商)-- 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. Only the retailers will face the customers. 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 lowest price a customer 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 their ID's are numbered from 0 to N?1, and the root supplier's ID is 0); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then N lines follow, each describes a distributor or retailer in the following format:

Ki ID[1] ID[2] ... ID[Ki]

where in the i-th line, Ki is the total number of distributors or retailers who receive products from supplier i, and is then followed by the ID's of these distributors or retailers. Kj being 0 means that the j-th member is a retailer. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the lowest price we can expect from some retailers, accurate up to 4 decimal places, and the number of retailers that sell at the lowest price. There must be one space between the two numbers. It is guaranteed that the all the prices will not exceed 1010.

Sample Input:

10 1.80 1.00
3 2 3 5
1 9
1 4
1 7
0
2 6 1
1 8
0
0
0
結(jié)尾無空行

Sample Output:

1.8362 2
結(jié)尾無空行

思路

和1090題幾乎一樣 甚至更簡單一些恳啥,一般樹的建立(靜態(tài))加遍歷娶桦。

代碼

#include <bits/stdc++.h>
using namespace std;

const int maxn = 100002;
vector<int> num[maxn];
int N;
double p, r;
int mindepth = maxn;
int clus;

void DFS (int indexs, int depth) {
    if (num[indexs].size() == 0) {
        if (depth < mindepth) {
            clus = 1;
            mindepth = depth;
        } else if (depth == mindepth) {
            clus++;
        }
    }
    for (int i = 0; i < num[indexs].size(); i++) {
        DFS(num[indexs][i], depth + 1);
    }
}

int main() {
    cin>>N>>p>>r;
    int len;
    for (int i = 0; i < N; i++) {
        cin>>len;
        int ma;
        for (int j = 0; j < len; j++) {
            cin>>ma;
            num[i].push_back(ma);
        }
    }
    DFS(0, 0);
    double price = p * pow(1 + 0.01 * r, mindepth);
    printf("%.4f %d", price, clus);
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末踢步,一起剝皮案震驚了整個(gè)濱河市鄙币,隨后出現(xiàn)的幾起案子弛车,更是在濱河造成了極大的恐慌符匾,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件赦拘,死亡現(xiàn)場離奇詭異阁猜,居然都是意外死亡剃袍,警方通過查閱死者的電腦和手機(jī)民效,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門业扒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來凶赁,“玉大人虱肄,你說我怎么就攤上這事∷卣鳎” “怎么了根欧?”我有些...
    開封第一講書人閱讀 163,624評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長今豆。 經(jīng)常有香客問我呆躲,道長灰瞻,這世上最難降的妖魔是什么箩祥? 我笑而不...
    開封第一講書人閱讀 58,356評(píng)論 1 293
  • 正文 為了忘掉前任底瓣,我火速辦了婚禮,結(jié)果婚禮上凳鬓,老公的妹妹穿的比我還像新娘。我一直安慰自己仅孩,他們只是感情好辽慕,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評(píng)論 6 392
  • 文/花漫 我一把揭開白布他宛。 她就那樣靜靜地躺著镜撩,像睡著了一般琐鲁。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上奈泪,一...
    開封第一講書人閱讀 51,292評(píng)論 1 301
  • 那天烙样,我揣著相機(jī)與錄音蛤肌,去河邊找鬼壁却。 笑死,一個(gè)胖子當(dāng)著我的面吹牛裸准,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播盐肃,決...
    沈念sama閱讀 40,135評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼砸王,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起疮方,我...
    開封第一講書人閱讀 38,992評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎珠洗,沒想到半個(gè)月后溜歪,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡许蓖,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評(píng)論 3 334
  • 正文 我和宋清朗相戀三年膊爪,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了自阱。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,785評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡米酬,死狀恐怖沛豌,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情赃额,我是刑警寧澤加派,帶...
    沈念sama閱讀 35,492評(píng)論 5 345
  • 正文 年R本政府宣布阁簸,位于F島的核電站,受9級(jí)特大地震影響哼丈,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜筛严,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評(píng)論 3 328
  • 文/蒙蒙 一醉旦、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧桨啃,春花似錦车胡、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至析命,卻和暖如春主卫,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背鹃愤。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評(píng)論 1 269
  • 我被黑心中介騙來泰國打工簇搅, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人软吐。 一個(gè)月前我還...
    沈念sama閱讀 47,891評(píng)論 2 370
  • 正文 我出身青樓瘩将,卻偏偏與公主長得像,于是被迫代替她去往敵國和親凹耙。 傳聞我的和親對(duì)象是個(gè)殘疾皇子姿现,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容