SRM503 div1 medium
タイプミスで落とす。
#include <string> #include <vector> #include <iostream> #include <sstream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; class KingdomXCitiesandVillages { public: int n,m; double dist[100][100]; double determineLength(vector <int> cityX, vector <int> cityY, vector <int> villageX, vector <int> villageY) { n=cityX.size(),m=villageX.size(); for(int i=0;i<n+m;i++) for(int j=0;j<n+m;j++) { double xF=(i<n)?cityX[i]:villageX[i-n]; double yF=(i<n)?cityY[i]:villageY[i-n]; double xT=(j<n)?cityX[j]:villageX[j-n]; double yT=(j<n)?cityY[j]:villageY[j-n]; double xD=xT-xF,yD=yT-yF; dist[i][j]=sqrt(xD*xD+yD*yD); } double ans=0.0; for(int picked=n;picked<n+m;picked++) { double minToCity=dist[picked][0]; for(int i=0;i<n;i++) minToCity=min(minToCity,dist[picked][i]); vector<double> candiate; for(int i=n;i<n+m;i++) if(i!=picked && dist[picked][i]<minToCity) candiate.push_back(dist[picked][i]); candiate.push_back(minToCity); sort(candiate.begin(),candiate.end()); /*for(int i=0;i<(int)candiate.size();i++) printf("%2.2f ",candiate[i]); cout << endl;*/ double prob=1.0; double d=2.0; for(int i=0;0.0+1e-10<prob && i<(int)candiate.size();i++) { if(i!=candiate.size()-1) ans+=candiate[i]*prob*1.0/d; else ans+=candiate[i]*prob; prob-=prob*1.0/d; d+=1.0; } } return ans; } };