1090 highest price in supply chain
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1090 highest price in supply chain相关的知识,希望对你有一定的参考价值。
p,r用double类型,pat多题如果用float会WA
AC代码
#include <vector> #include <cstdio> #include <cmath> using namespace std; int main(){ int n; double p,r; scanf("%d %lf %lf",&n,&p,&r); r /= 100.0; vector<int> s; vector<int> ret(n); vector<bool> vs(n,false); for(int i = 0;i < n;i++){ int tmp; scanf("%d",&tmp); if(tmp == -1){ ret[i] = 0; vs[i] = true; } s.push_back(tmp); } int max(0); for(int i = 0;i < s.size();i++){ if(vs[i]) continue; else{ vector<int> tmp; int id(i); while(id != -1){ tmp.push_back(id); id = s[id]; if(vs[id]) break; } for(int j = 0;j < tmp.size();j++){ vs[tmp[j]] = true; ret[tmp[j]] = ret[id] + tmp.size() - j; } if(ret[tmp[0]] > max) max = ret[tmp[0]]; } } int count(0); for(int i = 0;i < ret.size();i++){ if(ret[i] == max) count++; } printf("%.2lf %d\n",p * pow(1+r,max),count); return 0; }
以上是关于1090 highest price in supply chain的主要内容,如果未能解决你的问题,请参考以下文章
1090. Highest Price in Supply Chain (25)
PAT1090:Highest Price in Supply Chain
1090 Highest Price in Supply Chain (25 分)
PAT 1090. Highest Price in Supply Chain