标签:des style os for c++ size table ui
将所有密度遍历一遍求最小即可
#include <bits/stdc++.h> using namespace std; struct CandyMaking { double findSuitableDensity(vector <int> containerVolume, vector <int> desiredWeight) { vector<double>v; double Min=50000000; for(int i=0;i<containerVolume.size();i++) v.push_back(desiredWeight[i]*1.0/containerVolume[i]); for(int i=0;i<v.size();i++) { double sum=0; for(int j=0;j<v.size();j++) sum+=fabs(containerVolume[j]*v[i]-desiredWeight[j]); if(sum<Min) Min=sum; } return Min; } };
TopCoder SRM629 CandyMaking,布布扣,bubuko.com
标签:des style os for c++ size table ui
原文地址:http://blog.csdn.net/nenuxlp/article/details/38532543