#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
class FoxAndSightseeing{
public:
int getMin(vector <int> position){
int distanceLess[position.size()];
for(int i=1;i<position.size()-1;i++){
distanceLess[i]=abs(position[i]-position[i-1])+abs(position[i]-position[i+1])-abs(position[i+1]-position[i-1]);
}
int missingPoint=1;
int maxDistanceLess=0;
for(int i=1;i<position.size()-1;i++){
if(distanceLess[i]>maxDistanceLess){
missingPoint=i;
maxDistanceLess=distanceLess[i];
}
}
int ret=0;
for(int i=1;i<position.size();i++){
if(i!=missingPoint){
ret+=abs(position[i]-position[i-1]);
}
else{
ret+=abs(position[i+1]-position[i-1]);
i++;
}
cout<<"ret:"<<ret<<" i:"<<i<<endl;
}
return ret;
}
};
#include <vector>
#include <cmath>
using namespace std;
class FoxAndSightseeing{
public:
int getMin(vector <int> position){
int distanceLess[position.size()];
for(int i=1;i<position.size()-1;i++){
distanceLess[i]=abs(position[i]-position[i-1])+abs(position[i]-position[i+1])-abs(position[i+1]-position[i-1]);
}
int missingPoint=1;
int maxDistanceLess=0;
for(int i=1;i<position.size()-1;i++){
if(distanceLess[i]>maxDistanceLess){
missingPoint=i;
maxDistanceLess=distanceLess[i];
}
}
int ret=0;
for(int i=1;i<position.size();i++){
if(i!=missingPoint){
ret+=abs(position[i]-position[i-1]);
}
else{
ret+=abs(position[i+1]-position[i-1]);
i++;
}
cout<<"ret:"<<ret<<" i:"<<i<<endl;
}
return ret;
}
};
作者:doom_ood 发表于2013-12-2 3:34:17 原文链接
阅读:89 评论:0 查看评论