Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

Topcoder-SRM596DIV2-250

$
0
0
#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;
}
};
作者:doom_ood 发表于2013-12-2 3:34:17 原文链接
阅读:89 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>