Submission #8408

#TimeUsernameProblemLanguageResultExecution timeMemory
8408aintaWall construction (kriii2_WA)C++98
4 / 4
0 ms1116 KiB
#include<stdio.h> #include<algorithm> #include<math.h> using namespace std; #define PI 3.14159265359 int n, R, st[1010], top, P[1010]; double Res; struct point{ int x, y; bool operator <(const point &p)const{ return x != p.x ? x < p.x : y < p.y; } }w[1010]; int ccw(point a, point b, point c){ return (b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x); } double dist(point a, point b){ double D = (b.x - a.x)*(b.x - a.x) + (b.y - a.y) * (b.y - a.y); return sqrt(D); } int main() { int i, cnt = 0; scanf("%d%d", &n, &R); for (i = 0; i < n; i++){ scanf("%d%d", &w[i].x, &w[i].y); } sort(w, w + n); st[++top] = 0; for (i = 1; i < n; i++){ while (top > 1 && ccw(w[st[top - 1]], w[st[top]], w[i]) <= 0)top--; st[++top] = i; } for (i = 1; i < top; i++)P[++cnt] = st[i]; top = 0; st[++top] = 0; for (i = 1; i < n; i++){ while (top > 1 && ccw(w[st[top - 1]], w[st[top]], w[i]) >= 0)top--; st[++top] = i; } for (i = top; i > 1; i--)P[++cnt] = st[i]; P[cnt + 1] = P[1]; for (i = 1; i <= cnt; i++){ Res += dist(w[P[i + 1]], w[P[i]]); } printf("%.11lf\n", Res + PI * 2.0 * R); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...