我有白痴了原来强制类型转换不会自动四舍五入只会保留整数部分,,,,,好吧我是白痴
#include <iostream>
#include <string.h>#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;
#define MAXN 1111
#define PI 3.1415926
struct Point
{
double x, y;
double len;
}p[MAXN] , sta[MAXN], p0;
int top = 2;
double getdis(Point a, Point b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
double Across(Point a, Point b, Point c)
{
return (b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x);
}
bool cmp(Point a, Point b )
{
double k = Across(p0, a, b);
if(k > 0) return true;
if(k < 0) return false;
a.len = getdis(p0,a);
b.len = getdis(p0,b);
return a.len < b.len;
}
void Findp0( int n)
{
p0 = p[1];
int pos = 1;
for(int i = 2; i <= n; i++)
{
if(p0.y > p[i].y || (p0.y == p[i].y && p0.x > p[i].x))
{
pos = i;
p0 = p[i];
}
}
swap(p[1], p[pos]);
}
void Graham( int n)
{
sta[1] = p[1];
sta[2] = p[2];
for(int i = 3; i <= n; i++)
{
while(Across(sta[top-1],sta[top], p[i]) < 0 && top > 1) top--;
sta[++top] = p[i];
}
}
int main()
{
int n, l;
while(scanf("%d %d",&n ,&l) != EOF)
{
top = 2;
for(int i = 1; i <= n; i++)
scanf("%lf %lf",&p[i].x, &p[i].y);
Findp0(n);
sort(p+1, p + 1 + n, cmp);
Graham(n);
double ans = 0;
for(int i = 1; i < top; i++)
ans += getdis(sta[i], sta[i+1]);
ans += getdis(sta[top], sta[1]);
ans += 2*PI*l;
printf("%d\n",(int)(ans + 0.500001));
}
return 0;
}