这真的是太囧了,我差点就
![](http://hi.csdn.net/attachment/201108/3/0_1312356603uUNe.gif)
这样了,明明就是一道模板题,可怎么改都错,交了十几二十次还是WA……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………............................................................................................................................................……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………一天早上就过去了……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………吃完饭当然还是不甘心,突然在用别人的代码上看到,当只有两点的时候,有要算一边就好了,这时我就
![](http://hi.csdn.net/attachment/201108/3/0_1312356269EiZx.gif)
这样了,太囧了…………结果就这样过了
烦,不解释,不写了
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<cmath>
using namespace std;
class cor{
public:
int x, y;
};
cor start;
bool drection(cor& p0,cor& p1,cor& p2){
int x1 = p1.x-p0.x;
int y1 = p1.y-p0.y;
int x2 = p2.x-p0.x;
int y2 = p2.y-p0.y;
if(x2*y1-x1*y2 > 0)
return true;
return false;
}
bool cmp(cor& lhs,cor& rhs){
return drection(start,rhs,lhs);
}
double calc(cor p1,cor p2){
double a = pow((double)(p1.x-p2.x),2);
double b = pow((double)(p1.y-p2.y),2);
return sqrt(a+b);
}
int main()
{
int ntree;
while(cin >>ntree && ntree){
vector<cor> trees;
stack<cor> ch;
cin >>start.x >>start.y;
for(int i = 1;i < ntree;i++){
cor p;
cin >>p.x >>p.y;
if(p.y < start.y){
trees.push_back(start);
start = p;
}
else if(p.y == start.y && p.x <start.x){
trees.push_back(start);
start = p;
}
else
trees.push_back(p);
}
if(ntree == 1){
printf("0.00\n");
continue;
}
if(ntree == 2){
printf("%.2lf\n",calc(start,trees[0]));
continue;
}
sort(trees.begin(),trees.end(),cmp);
ch.push(start);
ch.push(trees[0]);
ch.push(trees[1]);
for(vector<cor>::size_type i = 2;i < trees.size();i++){
cor p0,p1,p2;
p1 = ch.top();
ch.pop(); p0 = ch.top(); ch.push(p1);//取栈顶下一个元素
p2 = trees[i];
while(drection(p0,p1,p2)){
ch.pop();
p1 = ch.top();
ch.pop(); p0 = ch.top(); ch.push(p1);//取栈顶下一个元素
}
ch.push(p2);
}
double len = 0.0;
cor p1,p2; ch.push(start);
p1 = ch.top(); p2 = p1;
stack<cor>::size_type k = ch.size();
for(stack<cor>::size_type i = 1;i < k;i++){
ch.pop();
p2 = ch.top();
len += calc(p1,p2);
p1 = p2;
}
printf("%.2lf\n",len);
}
return 0;
}