标签:col different div contain 根据 include into 小数点 0ms
题目链接:POJ 2365 Rope
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7488 | Accepted: 2624 |
Description
Input
Output
Sample Input
4 1 0.0 0.0 2.0 0.0 2.0 2.0 0.0 2.0
Sample Output
14.28
Source
题目大意:
有N颗钉子,每颗钉子半径为R,用一条细线把他们围起来,求细线长度。
大概思路:
①根据每个点的坐标求出两个钉子中心点的距离
②除了中心点的距离,还要加上一颗钉子的周长,一开始我还在想怎么算线接触钉子所占的弧长,其实整体来看,每颗钉子半径相同,细线要围一圈,角度之和为360度,所以加上一个圆周就搞定了!
③半径R要用double, 圆周率要精确到小数点后三位(32ms)小数点后四位(0ms)
AC code(160k 0ms):
1 #include <cmath> 2 #include <cstdio> 3 #include <iostream> 4 #include <algorithm> 5 #define INF 0x3f3f3f3f 6 #define pi 3.1415 7 using namespace std; 8 9 const int MAXN = 101; 10 11 double x[MAXN], y[MAXN]; 12 double ans, R; 13 int N; 14 15 double s(double x1, double x2, double y1, double y2) 16 { 17 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 18 } 19 20 int main() 21 { 22 scanf("%d%lf", &N, &R); 23 for(int i = 1; i <= N; i++) 24 { 25 scanf("%lf %lf", &x[i], &y[i]); 26 } 27 for(int i = 2; i <= N; i++) 28 { 29 ans+=s(x[i], x[i-1], y[i], y[i-1]); 30 } 31 ans+=s(x[1], x[N], y[1], y[N]); 32 ans+=(2*pi*R); 33 printf("%.2lf\n", ans); 34 return 0; 35 }
标签:col different div contain 根据 include into 小数点 0ms
原文地址:https://www.cnblogs.com/ymzjj/p/9393643.html