当前位置:网站首页>L2-020 descendants of kung fu
L2-020 descendants of kung fu
2022-07-30 05:02:00 【Cod_ing】
In the beginning, the simulation method was used,So it took a little more time,After reading other people's work, I know that it can be done with deep search.
If you use the simulation method, you need to pay attention:The apprentice's serial number may be higher than the master's serial number
For example, the bold part in the test case:
10 18.0 1.00
3 2 3 5
1 9
1 4
1 7
0 7
2 6 1
1 8
0 9
0 4
0 3
因此,For these points, it should be counted from the skill of the person behind,It needs to be pushed onto the stack first:The top of the stack is the last pushed,And its apprentice is under it,i.e. count after it.
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
const int MAX = 1e5 + 5;
struct Person {
double power; //power value
vector<int> tudi; //this man's apprentice
int N; //Get the multiplier of the disciple's skill
};
Person p[MAX];
stack<pair<int,int> > waiting; //Apprentices who have not yet dealt with skills
double get_power(int x,double r) {
//Seek skill
return (100 - r) * p[x].power / 100;
}
int main() {
int N;
double Z,r,ans=0;
cin >> N >> Z >> r;
p[0].power = Z;
for (int i = 0; i < N ; i++) {
int n,x;
cin >> n;
for (int j = 0; j < n; j++) {
cin >> x;
p[i].tudi.push_back(x);
if (p[i].power > 0.001) {
//Master's power is known,Therefore, it can be regarded as an apprentice skill
p[x].power= get_power(i, r);
}
else {
//Otherwise push on the stack
waiting.push({
i, x });
}
}
if (n == 0) {
cin>>p[i].N;
}
}
//Handle unhandled apprentices
while (!waiting.empty()) {
pair<int, int> temp = waiting.top();
waiting.pop();
p[temp.second].power = get_power(temp.first, r);
}
//Seek the power of the Taoist
for (int i = 0; i < N; i++) {
if (p[i].N > 0) {
ans += p[i].power * p[i].N;
}
}
cout << (int)ans;
return 0;
}
The code is more concise by using deep search recursion!
#include<iostream>
#include<vector>
using namespace std;
const int MAX = 1e5 + 5;
vector<int> Map[MAX];
int N;
double Z, r, ans;
int other[MAX];
void DFS(int n,double power) {
if (Map[n].size() == 0 && other[n] > 0) {
ans += power * other[n];
return;
}
for (int i = 0; i < Map[n].size(); i++) {
DFS(Map[n][i], power * r);
}
}
int main() {
cin >> N >> Z >> r;
int M;
r = (100 - r) / 100; //衰减值
for (int i = 0; i < N; i++) {
cin >> M;
for (int j = 0; j < M; j++) {
int x;
cin >> x;
Map[i].push_back(x);
}
if (M == 0) cin >> other[i];
}
DFS(0, Z);
cout << (int)ans;
return 0;
}
边栏推荐
- LeetCode Algorithm 2326. Spiral Matrix IV
- 22. 为什么需要消息队列?使用消息队列有什么好处?
- Shanxi group (enterprises) in the second network security skills competition part problem WP (7)
- VisualStudio2022本地调试进入特别慢问题解决
- Perspective transformation matrix of image perspective correction should be matrix (single)/findHomography with getPerspectiveTransformd difference
- Go study notes (84) - Go project directory structure
- SVN 查看用户名密码
- 双指针问题(下)
- 模拟问题(上)
- The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Part of the WP (9)
猜你喜欢

2.5 Quick Sort
![[Awards every week] The](/img/78/4b510b190475d603490614d2c8199f.png)
[Awards every week] The "Edge Containers" track of the Cloud Native Programming Challenge invites you to fight!

三、依赖配置管理

Six, read application configuration + log configuration

Simulation problem (middle)

深圳见!云原生加速应用构建专场:来看云原生 FinOps、SRE、高性能计算场景最佳实践

A must see for software testers!Database knowledge MySQL query statement Daquan

Golang eight-legged text finishing (continuous handling)

Stimulsoft ReportsJS and DashboardsJS. 2022.3.3

2.6 Radix sort (bucket sort)
随机推荐
【周周有奖】云原生编程挑战赛“边缘容器”赛道邀你来战!
Mini Program wx.miniProgram.navigateTo jump address cannot be tabbar address
动态规划问题(完结篇)
1. Get data - requests.get()
error: The following untracked working tree files would be overwritten by
模拟问题(下)
五、视图解析与模板引擎
1315_Use the LOOPBACK simulation mode to test whether the pyserial installation is successful
全流程调度——Azkaban入门与进阶
L2-020 功夫传人
Boss Rush (two-point answer + DP)
Discourse Custom Header Links
The Azure developer news 丨 memorabilia in July
Code readability, pre-checks, comments and summaries
ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序
The Double Pointer Problem (Part 2)
双指针问题(中)
[High Performance Computing] openMP
LeetCode Algorithm 2326. 螺旋矩阵 IV
Notes on "The Law of Construction"---Chapter 10 Typical Users and Scenarios