|
|
вернуться в форумWhy I got WA4??? struct Point { double x; double y; double ac; }; double Len(Point p1, Point p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } int main() { int n, r; cin >> n >> r; Point* pt = new Point [n]; Point ser; ser.x = 0; ser.y = 0; for(int i = 0; i < n; i++) { cin >> pt[i].x >> pt[i].y; ser.x += pt[i].x; ser.y += pt[i].y; } ser.x /= n; ser.y /= n; double pi = acos(-1.0);
for(int i = 0; i < n; i++) { pt[i].x -= ser.x; pt[i].y -= ser.y;
pt[i].ac = atan(fabs(pt[i].y) / fabs(pt[i].x)); if(pt[i].y > 0 && pt[i].x < 0) pt[i].ac += pi / 2; else if(pt[i].y < 0 && pt[i].x < 0) pt[i].ac += pi; else if(pt[i].y < 0 && pt[i].x > 0) pt[i].ac += 3 * pi / 2; } Point tmp; for(int i = 0; i < n; i++) { for(int j = n - 1; j > i; j--) { if(pt[j-1].ac > pt[j].ac) { tmp = pt[j-1]; pt[j-1] = pt[j]; pt[j] = tmp; } } } double ans = 0; for(int i = 0; i < n-1; i++) { ans += Len(pt[i], pt[i+1]); } ans += Len(pt[0], pt[n-1]); ans += 2 * acos(-1.0) * r; printf("%.2f\n", ans); return 0; } Re: Why I got WA4??? 2*PI*r + sum{dist beetwen points clockwise/counterwise} Re: Why I got WA4??? R should be a double type, not integer. |
|
|