1106. Lowest Price in Supply Chain (25)
来源:互联网 发布:两台台式机共享网络 编辑:程序博客网 时间:2024/06/06 00:08
题目详情:https://www.patest.cn/contests/pat-a-practise/1106
提交情况:
提交代码:
#include <iostream>#include <string.h>#include <vector>#include <math.h>using namespace std;#define Max 100010#define INF 0x3f3f3f3fvector<int> child[Max];int root[Max],Root,depth,visit[Max],n,depths[Max];double rootPrice,percent;void DFS( int vertex ,int depth ){ visit[vertex] = 1; depths[vertex] = depth; //得到节点的深度 for( int i=0;i<child[vertex].size();++i ) { int key = child[vertex][i]; if( visit[key] == 0 ) { ++depth; //跟踪节点的深度 DFS(key,depth); --depth; } }}int main(){ cin>>n>>rootPrice>>percent; for( int i=0;i<n;++i ) //输入处理 { int num; cin>>num; for( int j=0;j<num;++j ) { int kid; cin>>kid; child[i].push_back(kid); } }// cout<<"Root is "<<Root<<endl; depth = 1; DFS(0,depth); int minDepth = INF,number = 0; for( int i=0;i<n;++i ) //得到最大的深度,并用number记录最大深度的个数 { if( child[i].size()==0 && depths[i] < minDepth ) { minDepth = depths[i]; number = 1; } else if ( child[i].size()==0 && depths[i] == minDepth ) { ++number; } //以下代码查看各节点的深度 // if( i == n-1 )// cout<<depths[i]<<endl;// else// cout<<depths[i]<<" "; } printf("%.4lf %d",rootPrice*pow(1+percent/100,minDepth-1),number); return 0;}
最什么好说,和1079题,1090题都差不多,一个求最高的售价,最低的售价和总的销售额。本题求最低售价,1090题求最高售价,1079求总的销售额。
0 0
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain (25)
- 1106. Lowest Price in Supply Chain(25)
- 1106. Lowest Price in Supply Chain (25)
- 进程间通信方式总结——消息队列
- 在线监测显示屏
- Linux进程IPC浅析[进程间通信SystemV进程的信号量和信号量集]
- XAMPP实现HTML&MySQL&PHP简单的表单与数据库交互
- 第八届 蓝桥杯 Java B组 承压计算 解题报告
- 1106. Lowest Price in Supply Chain (25)
- Fisher线性判别分析(Linear Discriminant Analysis,LDA)
- 矩阵连乘,动态规划
- 【JZOJ5058】【GDSOI2017模拟4.13】采蘑菇
- 如何在安装pip3以及第三方python库(for Mac)
- java 命名和数据类型
- 指南针驱动(compass)移植
- 深度学习的目标
- Gulp前端构建工具