首页 技术 正文
技术 2022年11月16日
0 收藏 983 点赞 3,781 浏览 1632 个字

L2-020. 功夫传人

时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越

一门武功能否传承久远并被发扬光大,是要看缘分的。一般来说,师傅传授给徒弟的武功总要打个折扣,于是越往后传,弟子们的功夫就越弱…… 直到某一支的某一代突然出现一个天分特别高的弟子(或者是吃到了灵丹、挖到了特别的秘笈),会将功夫的威力一下子放大N倍 —— 我们称这种弟子为“得道者”。

这里我们来考察某一位祖师爷门下的徒子徒孙家谱:假设家谱中的每个人只有1位师傅(除了祖师爷没有师傅);每位师傅可以带很多徒弟;并且假设辈分严格有序,即祖师爷这门武功的每个第i代传人只能在第i-1代传人中拜1个师傅。我们假设已知祖师爷的功力值为Z,每向下传承一代,就会减弱r%,除非某一代弟子得道。现给出师门谱系关系,要求你算出所有得道者的功力总值。

输入格式:

输入在第一行给出3个正整数,分别是:N(<=105)——整个师门的总人数(于是每个人从0到N-1编号,祖师爷的编号为0);Z——祖师爷的功力值(不一定是整数,但起码是正数);r ——每传一代功夫所打的折扣百分比值(不超过100的正数)。接下来有N行,第i行(i=0, …, N-1)描述编号为i的人所传的徒弟,格式为:

Ki ID[1] ID[2] … ID[Ki]

其中Ki是徒弟的个数,后面跟的是各位徒弟的编号,数字间以空格间隔。Ki为零表示这是一位得道者,这时后面跟的一个数字表示其武功被放大的倍数。

输出格式:

在一行中输出所有得道者的功力总值,只保留其整数部分。题目保证输入和正确的输出都不超过1010

输入样例:

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

输出样例:

404现在大二来做,觉得比较水了。。记录好每个人为传道第几代就好。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#define maxn 100010
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
vector<int> E[maxn]; //每个人的徒弟
int idx[maxn]; //每个人的传道第几代
struct node {
int x,y;
};
node num[maxn]; //记录得道人的编号和武功被放大的倍数
void init() {
for( int i = ; i < maxn; i ++ ) {
E[i].clear();
idx[i] = ;
num[i].x = num[i].y = ;
}
}
void dfs( int n ) {
if( E[n].size() == ) {
return ;
}
for( int i = ; i < E[n].size(); i ++ ) {
idx[E[n][i]] = idx[n] + ;
dfs(E[n][i]);
}
}
int main() {
int n;
double z,r;
while( cin >> n >> z >> r ) {
init();
int ans = ;
for( int i = ; i < n; i ++ ) {
int m;
cin >> m;
if( m == ) {
int t;
cin >> t;
num[ans].x = i;
num[ans++].y = t;
}
while( m -- ) {
int t;
cin >> t;
E[i].push_back(t);
}
}
dfs();
double all = ;
for( int i = ; i < ans; i ++ ) {
double sum = z;
sum = sum * pow( - r * 0.01, idx[num[i].x] );
/*while( idx[num[i].x] -- ) {
sum = sum - ( sum * r * 1.0 ) / 100.0;
}*/
sum = sum * num[i].y;
all += sum;
}
all = floor(all);
printf("%.0lf\n",all);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902