PAT程序设计考题——甲级1090( Highest Price in Supply Chain ) C++实现
来源:互联网 发布:怎样做淘宝生意 编辑:程序博客网 时间:2024/06/08 13:44
点击打开链接
#include<iostream>
#include<math.h>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define INF 100000000
#define maxn 100010
#include<math.h>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define INF 100000000
#define maxn 100010
struct node{//记录最长路径 和个数还有更好的方法
vector<int> child;
int parent;
};
node tree[maxn];
int depthnum[maxn];
int dnum=0;
int n;
double p,r;
void pre(int index,int depth)
{
if(tree[index].child.empty())
{
depthnum[dnum++]=depth;
return;
}
for(int i=0;i<tree[index].child.size();i++)
pre(tree[index].child[i],depth+1);
}
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
cin>>n>>p>>r;
r=r/100;
for(int i=0;i<n;i++)
{
int num;
cin>>num;
tree[i].parent=num;
if(num!=-1) tree[num].child.push_back(i);
}
int root;
for(int i=0;i<n;i++)
if(tree[i].parent==-1) {
root=i;
break;
}
pre(root,0);
sort(depthnum,depthnum+n,cmp);
int qw=1;
for(int i=1;i<n;i++)
{
// cout<<depthnum[i]<<endl;
if(depthnum[i]==depthnum[0]) qw++;
}
printf("%.2lf",p*pow(1+r,depthnum[0]));
cout<<" "<<qw;
return 0;
}
vector<int> child;
int parent;
};
node tree[maxn];
int depthnum[maxn];
int dnum=0;
int n;
double p,r;
void pre(int index,int depth)
{
if(tree[index].child.empty())
{
depthnum[dnum++]=depth;
return;
}
for(int i=0;i<tree[index].child.size();i++)
pre(tree[index].child[i],depth+1);
}
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
cin>>n>>p>>r;
r=r/100;
for(int i=0;i<n;i++)
{
int num;
cin>>num;
tree[i].parent=num;
if(num!=-1) tree[num].child.push_back(i);
}
int root;
for(int i=0;i<n;i++)
if(tree[i].parent==-1) {
root=i;
break;
}
pre(root,0);
sort(depthnum,depthnum+n,cmp);
int qw=1;
for(int i=1;i<n;i++)
{
// cout<<depthnum[i]<<endl;
if(depthnum[i]==depthnum[0]) qw++;
}
printf("%.2lf",p*pow(1+r,depthnum[0]));
cout<<" "<<qw;
return 0;
}
阅读全文
0 0
- PAT程序设计考题——甲级1090( Highest Price in Supply Chain ) C++实现
- pat 1090 Highest Price in Supply Chain
- PAT 1090 Highest Price in Supply Chain
- 1090. Highest Price in Supply Chain (25) PAT甲级
- PAT 甲级 Highest Price in Supply Chain (25)
- PAT 甲级 1090. Highest Price in Supply Chain (25)
- PAT程序设计考题——甲级1079( Total Sales of Supply Chain ) C++实现
- PAT 1090. Highest Price in Supply Chain
- PAT A1090 Highest Price in supply chain
- 【PAT】1090. Highest Price in Supply Chain
- Pat(Advanced Level)Practice--1090(Highest Price in Supply Chain)
- PAT A 1090 Highest Price in Supply Chain 深搜
- PAT 1090. Highest Price in Supply Chain (25)(DFS)
- PAT--1090. Highest Price in Supply Chain(dfs)
- 1090. Highest Price in Supply Chain (25)-PAT甲级真题
- 1090. Highest Price in Supply Chain (25)-PAT甲级真题
- [转]PAT甲级练习1090. Highest Price in Supply Chain (25)
- PAT甲级真题及训练集(22)--1090. Highest Price in Supply Chain (25)
- Spark 2.1.1 learning 002 [generate random char]
- php请求远程数据代码
- 重新学c(一)
- 服务器性能监控之New Relic 入门教程
- Dubbo是什么
- PAT程序设计考题——甲级1090( Highest Price in Supply Chain ) C++实现
- jvm 垃圾回收机制 安全点
- String的使用
- ES内存配置
- JAVA控制CPU占用率(编程之美有感)(一)
- Nginx反向代理和负载均衡部署
- 剑指offer 23----二叉树的前序、中序、后序、层序遍历
- 2017年7月21日博雅培优幼小衔接班毕业校长讲话总结
- 关于一个判断Integer数是否为回文数的算法问题