【CodeForces】257C - View Angle(计算几何)
2016-10-22 16:20
337 查看
题目链接:点击打开题目
C. View Angle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and
with all mannequins standing inside or on the boarder of this angle.
As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) —
the number of mannequins.
Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) —
the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that
no two mannequins are located in the same point on the plane.
Output
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6.
Examples
input
output
input
output
input
output
input
output
Note
Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below:
有个坑,刚开始wa了很多次。把每个点与x轴正方向的夹角算出来后,排一下顺序后把每一个点都遍历一遍,以之为起点算角度更新ans就行了。
代码如下:
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
#define MAX 100000
#define PI acos(-1.0)
struct node
{
double x,y,angle;
}a[MAX+11];
double trans(double m) //转化为角度制
{
return 180 * m / PI;
}
double cal(double x,double y)
{
if (x > 0 && y > 0)
return trans(atan(y/x));
else if (x < 0 && y > 0)
return 180 - trans(atan(-y/x));
else if (x < 0 && y < 0)
return 180 + trans(atan(y/x));
else if (x > 0 && y < 0)
return 360 - trans(atan(-y/x));
else if (x == 0 && y > 0)
return 90;
else if (x == 0 && y < 0)
return 270;
else if (x >= 0 && y == 0)
return 0;
else if (x < 0 && y == 0)
return 180;
}
bool cmp(node a,node b)
{
return a.angle < b.angle;
}
int main()
{
int n;
while (~scanf ("%d",&n))
{
for (int i = 1 ; i <= n ; i++)
{
scanf ("%lf %lf",&a[i].x,&a[i].y);
a[i].angle = cal(a[i].x , a[i].y);
}
sort(a+1,a+n+1,cmp);
double ans = a
.angle - a[1].angle;
for (int i = 2 ; i <= n ; i++)
{
double t = a[i-1].angle - a[i].angle;
ans = min(ans , t <= 0 ? t + 360 : t);
}
printf ("%lf\n",ans);
}
return 0;
}
C. View Angle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and
with all mannequins standing inside or on the boarder of this angle.
As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) —
the number of mannequins.
Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) —
the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that
no two mannequins are located in the same point on the plane.
Output
Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6.
Examples
input
2 2 0 0 2
output
90.0000000000
input
3 2 0 0 2 -2 2
output
135.0000000000
input
4 2 0 0 2 -2 0 0 -2
output
270.0000000000
input
2 2 1 1 2
output
36.8698976458
Note
Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below:
有个坑,刚开始wa了很多次。把每个点与x轴正方向的夹角算出来后,排一下顺序后把每一个点都遍历一遍,以之为起点算角度更新ans就行了。
代码如下:
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
#define MAX 100000
#define PI acos(-1.0)
struct node
{
double x,y,angle;
}a[MAX+11];
double trans(double m) //转化为角度制
{
return 180 * m / PI;
}
double cal(double x,double y)
{
if (x > 0 && y > 0)
return trans(atan(y/x));
else if (x < 0 && y > 0)
return 180 - trans(atan(-y/x));
else if (x < 0 && y < 0)
return 180 + trans(atan(y/x));
else if (x > 0 && y < 0)
return 360 - trans(atan(-y/x));
else if (x == 0 && y > 0)
return 90;
else if (x == 0 && y < 0)
return 270;
else if (x >= 0 && y == 0)
return 0;
else if (x < 0 && y == 0)
return 180;
}
bool cmp(node a,node b)
{
return a.angle < b.angle;
}
int main()
{
int n;
while (~scanf ("%d",&n))
{
for (int i = 1 ; i <= n ; i++)
{
scanf ("%lf %lf",&a[i].x,&a[i].y);
a[i].angle = cal(a[i].x , a[i].y);
}
sort(a+1,a+n+1,cmp);
double ans = a
.angle - a[1].angle;
for (int i = 2 ; i <= n ; i++)
{
double t = a[i-1].angle - a[i].angle;
ans = min(ans , t <= 0 ? t + 360 : t);
}
printf ("%lf\n",ans);
}
return 0;
}
相关文章推荐
- Codeforces 257C:View Angle(思维+数学+atan2函数)
- CodeForces 257C View Angle(求角度)
- CodeForces 203D Hit Ball 水!计算几何
- Codeforces 1C Ancient Berland Circus 计算几何
- Codeforces 659D Bicycle Race【计算几何】
- CodeForces 659 D. Bicycle Race(计算几何 + 数学公式)
- codeforces 672C C. Recycling Bottles(计算几何)
- codeforces 113 166B 凸包 计算几何
- UVa 1643 Angle and Squares (计算几何)
- codeforces 23D Tetragon 计算几何
- CodeForces 613 A. Peter and Snow Blower(计算几何)
- Codeforces 140 A. New Year Table(计算几何)
- Codeforces 8D Two Friends 三分+二分+计算几何
- Codeforces 32E Hide-and-Seek 乞讨2关于镜面反射点 计算几何
- Codeforces 1C. Ancient Berland Circus(计算几何:正多边形性质+高精度)
- Codeforces 659D Bicycle Race【计算几何】
- codeforces 223E 计算几何 图论 网络流思想
- CodeForces 281c Rectangle Puzzle 计算几何
- CodeForces 498A-Crazy Town-简单计算几何
- 简单数学题或者计算几何:Codeforces 659D-Bicycle Race