当前位置:网站首页>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;
}
边栏推荐
- Discourse Custom Header Links
- Boss Rush (two-point answer + DP)
- Catch That Cow(详解)
- 字符串问题(上)
- - B + tree index and MySQL series 】 【 what is the difference between a HASH index
- Simple experiment with BGP
- Small programs use npm packages to customize global styles
- Web page element parsing a tag
- Unity踩坑记录 —— GetComponent的使用
- 如何与墨西哥大众VW Mexico建立EDI连接
猜你喜欢

KubeMeet Registration | The complete agenda of the "Edge Native" Online Technology Salon has been announced!
![[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!

webService接口

Excellent MySQL interview questions, 99% must ask in preparation for August!I can't pass the interview

Learning of redis_Basic part

ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序

1315_Use the LOOPBACK simulation mode to test whether the pyserial installation is successful

nSoftware.PowerShell.Server.2020

Hexagon_V65_Programmers_Reference_Manual(14)

Plan for many situations in the processing chain
随机推荐
Image stitching (registration) case based on OpenCV
How to use labelme
The 2nd Shanxi Province Network Security Skills Competition (Enterprise Group) Partial WP (10)
uni-app realizes cross-end development of mobile phone Bluetooth to receive and send data
SVN View Username and Password
Discourse 自定义头部链接(Custom Header Links)
Boss Rush (two-point answer + DP)
字符串问题(下)
See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
webService接口
Web page element parsing a tag
四、Web开发
22. 为什么需要消息队列?使用消息队列有什么好处?
模拟问题(下)
ms project2010项目管理软件使用技巧总结
【Vitis】ZCU102开发板PS端控制PL端复位的代码实现
Protobuf compound data types, speaking, reading and writing
Dynamically bind href url
Hexagon_V65_Programmers_Reference_Manual(11)
Machine Learning: Knowing the Dimensionality Reduction Process Through Low Variance Filtering