-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ab5e17
commit 6220281
Showing
5 changed files
with
137 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# A1090 Highest Price in Supply Chain | ||
|
||
## 1.题意理解 | ||
给出一个一条供应链(一棵树),每转手一次都要提升一个差价(按比例给定),问能得到的最高零售价是多少,以及有几个零售商是这个最高价格。 | ||
|
||
## 2.思路分析 | ||
其实就是求树的高度。 | ||
|
||
## 3.参考代码 | ||
```cpp | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
const int N = 100010; | ||
int n; | ||
double p, r; | ||
|
||
vector<int> child[N]; | ||
|
||
int maxdepth = -1, cnt = 1; | ||
void dfs(int root, int depth) | ||
{ | ||
if (!child[root].size()) | ||
{ | ||
if (depth > maxdepth) | ||
{ | ||
maxdepth = depth; | ||
cnt = 1; | ||
} | ||
else if (depth == maxdepth) | ||
cnt++; | ||
return; | ||
} | ||
for (int i = 0; i < child[root].size(); i++) | ||
dfs(child[root][i], depth + 1); | ||
} | ||
|
||
int main() | ||
{ | ||
int root, c; | ||
scanf("%d %lf %lf", &n, &p, &r); | ||
|
||
for (int i = 0; i < n; i++) | ||
{ | ||
scanf("%d", &c); | ||
if (c != -1) | ||
child[c].push_back(i); // 注意别把父子关系搞反! | ||
else | ||
root = i; // 供应商为-1,即没有供应商,那么它就是根结点。 | ||
} | ||
|
||
dfs(root, 1); | ||
printf("%.2lf %d\n", p * pow(1.0 + r / 100.0, maxdepth - 1), cnt); // 注意转手次数,以及比率是百分数 | ||
return 0; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters