1079. Total Sales of Supply Chain
来源:互联网 发布:安桥e700m 淘宝 编辑:程序博客网 时间:2024/06/07 07:24
Tips:
- 真是no zuo no die.说好的尽量用C来写,脑子一抽,又用Java来写了,最直接的方法,结果来了个超时.好吧,以为是算法问题,继续改,各种思路,仍得不到解决.换C++吧,还是各种思路,没能AC.最后想试试看用C++来写最开始的最直接的方法,呵呵,AC了…再说一遍,没什么事别用Java!!!
- 这题没什么技巧,也没什么陷阱,无非就先把输入的数据用二维数组保存起来,然后用到了队列.其它没什么好说的了.虽然是个25分的题,但我认为难度不大.
#include "iostream"using namespace std;int main(int argc, const char * argv[]) { int n,i,j,m,len,index; double p,r,amount; int **chain,*tree; double *price; while (scanf("%d %lf %lf",&n,&p,&r) != EOF) { chain = new int*[n]; tree = new int[n]; price = new double[n]; price[0] = p; amount = 0.0; for(i = 0;i < n;i++){ scanf("%d",&m); if(m == 0) len = 2; else len = m + 1; chain[i] = new int[len]; chain[i][0] = m; for(j = 1;j < len;j++) scanf("%d",&chain[i][j]); } tree[0] = 0; for(i = 0,index = 1;i < n;i++){ if(chain[tree[i]][0] == 0) amount += price[tree[i]] * chain[tree[i]][1]; else{ for(j = 1;j <= chain[tree[i]][0];j++){ tree[index++] = chain[tree[i]][j]; price[chain[tree[i]][j]] = price[tree[i]] * (1 + r / 100); } } } printf("%.1lf\n",amount); } return 0;}
0 0
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079.Total Sales of Supply Chain
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- 1079. Total Sales of Supply Chain (25)
- Linux教程之文件系统管理
- 修复bug的思考
- 求两个数的最大公约数和最小公倍数
- 信息项目管理师-项目时间管理知识点
- (我总结的实用主义)Loadrunner运行常见错误
- 1079. Total Sales of Supply Chain
- 信息系统项目管理师-成本管理知识点
- SDCC2015:一线公司云集 技术论坛精彩议题先睹为快
- 最大公约数(递归)
- Android 轻松实现百度地图定位
- 最大似然估计(转载)
- PHP 之 FastCGI 与 mod_php 详解
- 信息系统项目管理师-质量管理知识点
- cocos2d-x3.2 在Windows下打包Android平台APK(转载,只为记录)