1020. Rope
2017-10-10 19:26
597 查看
1020. Rope
Time limit: 1.0 second
Memory limit: 64 MB
Plotters have barbarously hammered N nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they…it is awful… have roped
off the nails, so that the shape felt upset (the rope was very thin). They’ve done it as it is shown in the figure.
Problem illustration
Your task is to find out a length of the rope.
Input
There two numbers in the first line of the standard input: N — a number of nails (1 ≤ N ≤ 100), and a real number R — a radius of heads of nails. All the heads have the same radius. Further there are N lines, each of them contains a pair of real coordinates
(separated by a space) of centers of nails. An absolute value of the coordinates doesn’t exceed 100. The nails are described either in a clockwise or in a counterclockwise order starting from an arbitrary nail. Heads of different nails don’t overlap.
Output
Output a real number with two digits precision (after a decimal point) — a length of the rope.
Sample
input
4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0
output
14.28
#include<iostream>
#include <math.h>
using namespace std;
float a[105][2];
int main(){
int pointnum ;
int r ;
cin>>pointnum;
cin>>r;
double rope = 0;
for(int i = 0 ; i < pointnum ; i++){
cin>>a[i][0];
cin>>a[i][1];
}
for(int i = 0 ; i < pointnum+1 ; i++){
if(i==pointnum){
int t = (a[0][0]-a[i][0])*(a[0][0]-a[i][0]) + (a[0][1]-a[i][1])*(a[0][1]-a[i][1]);
rope = rope + sqrt(abs(t));
}
else{
int t = (a[i+1][0]-a[i][0])*(a[i+1][0]-a[i][0]) + (a[i+1][1]-a[i][1])*(a[i+1][1]-a[i][1]);
rope = rope + sqrt(abs(t));
}
}
rope = rope + 3.14 * 2 * r;
cout<<rope;
return 0;
}
Time limit: 1.0 second
Memory limit: 64 MB
Plotters have barbarously hammered N nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they…it is awful… have roped
off the nails, so that the shape felt upset (the rope was very thin). They’ve done it as it is shown in the figure.
Problem illustration
Your task is to find out a length of the rope.
Input
There two numbers in the first line of the standard input: N — a number of nails (1 ≤ N ≤ 100), and a real number R — a radius of heads of nails. All the heads have the same radius. Further there are N lines, each of them contains a pair of real coordinates
(separated by a space) of centers of nails. An absolute value of the coordinates doesn’t exceed 100. The nails are described either in a clockwise or in a counterclockwise order starting from an arbitrary nail. Heads of different nails don’t overlap.
Output
Output a real number with two digits precision (after a decimal point) — a length of the rope.
Sample
input
4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0
output
14.28
#include<iostream>
#include <math.h>
using namespace std;
float a[105][2];
int main(){
int pointnum ;
int r ;
cin>>pointnum;
cin>>r;
double rope = 0;
for(int i = 0 ; i < pointnum ; i++){
cin>>a[i][0];
cin>>a[i][1];
}
for(int i = 0 ; i < pointnum+1 ; i++){
if(i==pointnum){
int t = (a[0][0]-a[i][0])*(a[0][0]-a[i][0]) + (a[0][1]-a[i][1])*(a[0][1]-a[i][1]);
rope = rope + sqrt(abs(t));
}
else{
int t = (a[i+1][0]-a[i][0])*(a[i+1][0]-a[i][0]) + (a[i+1][1]-a[i][1])*(a[i+1][1]-a[i][1]);
rope = rope + sqrt(abs(t));
}
}
rope = rope + 3.14 * 2 * r;
cout<<rope;
return 0;
}
相关文章推荐
- ural 1020. Rope(几何)
- URAL 1020 Rope(圆与切线)
- URAL 1020 Rope
- Ural 1020 Rope 解题报告
- [timus] 1020. Rope
- URAL 1020 Rope 简单几何
- URAL1020 ROPE
- ural 1020 Rope
- ural 1020 Rope
- Ural 1020 Rope 解题报告
- Ural-1020. Rope(简单计算几何)
- HDU-1020-Encoding,题意不清,其实很水~~
- 1020. 月饼 (25)
- 九度 OJ 1020:最小长方形
- hdu 1020 Encoding
- HDU1020 Encoding
- PAT-A 1020. Tree Traversals
- 1020 月饼
- 1020. Tree Traversals (25)
- PAT乙级1020