PAT甲1106 Lowest Price in Supply Chain
2019-08-07 21:51
941 查看
题意
供货商,中间商和零售商每层都会加价,找到最便宜的零售商
题解
dfs找到深度最浅的零售商
源码
">#include<cstring> #include<cmath> #include<map> #include<algorithm> #include<vector> #include<iomanip> using namespace std; vector<int>mp[100005]; int visit[100005]; vector<int>retailer; void dfs(int x,int depth){ if(mp[x].size()==0){ retailer.push_back(depth); } for(int i=0;i<mp[x].size();i++){ if(visit[mp[x][i]]==0){ visit[mp[x][i]]=1; dfs(mp[x][i],depth+1); } } } bool cmp(int x,int y){ return x<y; } int main(){ int n; double p,r; memset(visit,0,sizeof(visit)); cin>>n>>p>>r; for(int i=0;i<n;i++){ int len; cin>>len; while(len--){ int x; cin>>x; mp[i].push_back(x); } } visit[0]=1; dfs(0,1); sort(retailer.begin(),retailer.end(),cmp); int pre=retailer[0]; int counter=1; for(int i=1;i<retailer.size();i++){ if(retailer[i]==pre){ counter++; }else{ break; } } cout<<fixed<<setprecision(4)<<p*pow(1+r/100,retailer[0]-1)<<" "<<counter<<endl; return 0; }
相关文章推荐
- 【PAT】1106. Lowest Price in Supply Chain
- 【PAT】【Advanced Level】1106. Lowest Price in Supply Chain (25)
- PAT--1106. Lowest Price in Supply Chain
- pat 1106. Lowest Price in Supply Chain (25)
- PAT (Advanced Level) Practise 1106 Lowest Price in Supply Chain (25)
- PAT 1106 Lowest Price in Supply Chain
- PAT甲级——1106 Lowest Price in Supply Chain (BFS)
- pat 1106. Lowest Price in Supply Chain (25)
- PAT 1106 Lowest Price in Supply Chain
- PAT (Advanced Level) Practise 1106 Lowest Price in Supply Chain(25)
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
- PAT - 甲级 - 1106. Lowest Price in Supply Chain (25)(多叉树)
- 1106. Lowest Price in Supply Chain (25)-PAT甲级真题(dfs,bfs,树的遍历)
- 1106. Lowest Price in Supply Chain (25) PAT甲级
- PAT 甲级 1106. Lowest Price in Supply Chain (25)
- PAT甲题题解-1106. Lowest Price in Supply Chain (25)-(dfs计算树的最小层数)
- Pat(A) 1106. Lowest Price in Supply Chain (25)
- PAT 1106 Lowest Price in Supply Chain
- PAT (Advanced Level)-1106 Lowest Price in Supply Chain
- PAT 1106. Lowest Price in Supply Chain (25)