http://poj.org/problem?id=1113
答案是凸包周长+半径为l的圆的周长...
证明?这是个坑..
#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; #define pii pair<int, int> #define mkpii make_pair<int, int> #define pdi pair<double, int> #define mkpdi make_pair<double, int> #define pli pair<ll, int> #define mkpli make_pair<ll, int> #define rep(i, n) for(int i=0; i<(n); ++i) #define for1(i,a,n) for(int i=(a);i<=(n);++i) #define for2(i,a,n) for(int i=(a);i<(n);++i) #define for3(i,a,n) for(int i=(a);i>=(n);--i) #define for4(i,a,n) for(int i=(a);i>(n);--i) #define CC(i,a) memset(i,a,sizeof(i)) #define read(a) a=getint() #define print(a) printf("%d", a) #define dbg(x) cout << (#x) << " = " << (x) << endl #define error(x) (!(x)?puts("error"):0) #define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; } #define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } inline const int max(const int &a, const int &b) { return a>b?a:b; } inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=2005; struct Pt { int x, y; }; int Cross(Pt &a, Pt &b, Pt &c) { static int x1, x2, y1, y2; x1=a.x-c.x; y1=a.y-c.y; x2=b.x-c.x; y2=b.y-c.y; return x1*y2-x2*y1; } int sqr(int x) { return x*x; } double dis(Pt &a, Pt &b) { return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); } bool cmp(const Pt &a, const Pt &b) { return a.x==b.x?a.y<b.y:a.x<b.x; } void tu(Pt *p, Pt *s, int n, int &cnt) { sort(p, p+n, cmp); cnt=-1; rep(i, n) { while(cnt>0 && Cross(p[i], s[cnt], s[cnt-1])>=0) --cnt; s[++cnt]=p[i]; } int k=cnt; for3(i, n-2, 0) { while(cnt>k && Cross(p[i], s[cnt], s[cnt-1])>=0) --cnt; s[++cnt]=p[i]; } if(n>1) --cnt; ++cnt; } int n, m, l; Pt a[N], b[N]; int main() { read(n); read(l); rep(i, n) read(a[i].x), read(a[i].y); tu(a, b, n, m); b[m]=b[0]; double ans=2*l*acos(-1); rep(i, m) ans+=dis(b[i], b[i+1]); printf("%.0f\n", ans); return 0; }
Description
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
![]() Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements. The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet. Input
The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices. Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.
Sample Input 9 100 200 400 300 400 300 300 400 300 400 400 500 400 500 200 350 200 200 200 Sample Output 1628 Hint
结果四舍五入就可以了
Source |