ZJU-PAT 1079. Total Sales of Supply Chain (25) 浙大2014年上机复试第三题
来源:互联网 发布:域名不解析可以不备案 编辑:程序博客网 时间:2024/06/15 02:28
#include<iostream>#include<cstdio>using namespace std;struct Node{ int parent; //父节点 bool flag; //是否是retailers int level; //第几层 int num; //销售多少个};Node tt[100005];int n;double p,r,sum;int Jisuan(int num){ if(tt[num].level!=-1) return tt[num].level; else return Jisuan(tt[num].parent)+1;}double Count[100005];void run(){ scanf("%d",&n); scanf("%lf%lf",&p,&r); Count[0]=p; for(int i=1; i<100005; i++) { Count[i]=Count[i-1]*(1.0+r/100.0); } for(int i=1; i<n; i++) { tt[i].level=-1; } tt[0].level=0; for(int i=0; i<n; i++) { int tmp; scanf("%d",&tmp); if(tmp==0) { scanf("%d",&tmp); tt[i].flag=true; tt[i].num=tmp; } else { tt[i].flag=false; for(int j=0; j<tmp; j++) { int t; scanf("%d",&t); tt[t].parent=i; } } } for(int i=1; i<n; i++) { tt[i].level=Jisuan(i); } sum=0.0; for(int i=0; i<n; i++) { if(tt[i].flag==true) sum+=tt[i].num*Count[tt[i].level]; } printf("%.1lf\n",sum);}int main(){ run(); return 0;}
#include<iostream>#include<cstdio>#include<queue>using namespace std;const int N=100005;struct Node{ int parent; //父节点 vector<int> child; //孩子 int level; //第几层 int num; //销售多少个};Node tt[N];int n;double p,r,sum;double Count[N];void BFS(){ queue<Node> Q; Q.push(tt[0]); tt[0].level=0; while(!Q.empty()) { Node tmp=Q.front(); Q.pop(); for(int i=0;i<tmp.child.size();i++) { tt[tmp.child[i]].level=tmp.level+1; Q.push(tt[tmp.child[i]]); } }}void Init(){ scanf("%d",&n); scanf("%lf%lf",&p,&r); Count[0]=p; for(int i=1; i<N; i++) { Count[i]=Count[i-1]*(1.0+r/100.0); } for(int i=0; i<n; i++) { int tmp; scanf("%d",&tmp); if(tmp==0) { scanf("%d",&tmp); tt[i].num=tmp; } else { tt[i].num=0; for(int j=0; j<tmp; j++) { int t; scanf("%d",&t); tt[t].parent=i; tt[i].child.push_back(t); } } }}void Jisuan(){ sum=0.0; for(int i=0; i<n; i++) { if(tt[i].num) sum+=tt[i].num*Count[tt[i].level]; } printf("%.1lf\n",sum);}int main(){ Init(); BFS(); Jisuan(); return 0;}
0 0
- ZJU-PAT 1079. Total Sales of Supply Chain (25) 浙大2014年上机复试第三题
- 浙大机试2014:Total Sales of Supply Chain (25)
- 【PAT】1079. Total Sales of Supply Chain
- PAT--1079. Total Sales of Supply Chain
- PAT 1079. Total Sales of Supply Chain (25)
- PAT (Advanced) 1079. Total Sales of Supply Chain (25)
- PAT Advanced Level 1079. Total Sales of Supply Chain (25)
- PAT A 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- PAT 1079. Total Sales of Supply Chain (25)
- 【PAT】1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)PAT甲级
- PAT甲级练习1079. Total Sales of Supply Chain (25)
- PAT-A-1079. Total Sales of Supply Chain (25)
- 【PAT甲级】1079. Total Sales of Supply Chain (25)
- 【PAT】【Advanced Level】1079. Total Sales of Supply Chain (25)
- PAT 甲级 1079. Total Sales of Supply Chain (25)
- POJ 2778 AC自动机+矩阵相乘
- 风高放火非官方的身法
- strut2标签库iterator
- win7多用户同时登录、操作
- jjj
- ZJU-PAT 1079. Total Sales of Supply Chain (25) 浙大2014年上机复试第三题
- Java 易错笔试题
- 多线程的顺序锁
- C#与Java的简单比较
- 是定义站点的icon图标,跟网页中的图片有本质上的区别,icon是显示在地址栏最前面的一个16*16的小图标
- 马方发现mh370强有力线索 已禁止机长独处驾驶舱
- 怎样让HTML5 CSS3网站在低版IE中显示
- Java批量操作数据库
- eclipse导入ant项目