CodeForces - 908C New Year and Curling(圆与圆之间的关系的问题)
2018-01-01 11:24
525 查看
Carol is currently curling.
She has n disks each with radius r on the 2D plane.
Initially she has all these disks above the line y = 10100.
She then will slide the disks towards the line y = 0 one by one in order from 1 to n.
When she slides the i-th disk, she will place its center at the point (xi, 10100). She will then push it
so the disk’s y coordinate continuously decreases, and xcoordinate stays constant. The disk stops once it touches the line y = 0 or it touches
any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.
Compute the y-coordinates of centers of all the disks after all disks have been pushed.
Input
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively.
The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) —
the x-coordinates of the disks.
Output
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th
disk. The output will be accepted if it has absolute or relative error at most 10 - 6.
Namely, let's assume that your answer for a particular value of a coordinate is aand the answer of the jury is b. The checker program will consider your answer correct if
for
all coordinates.
Example
Input
Output
Note
The final positions of the disks will look as follows:
In particular, note the position of the last disk.
题意: 已知一些圆在(xi,10100)处,然后依次落下,下落时只要碰到某个圆或
达到y=0处,就会自动停止,就算再被其他球碰住也不会动,求这些圆的最后的y值,也即是水平高度
说实话考试时,这道题我没做出来,wrong anwer 7;
做了这道题给我的收获是:1:以后再判断圆与圆的位置关系时,就用两个圆心与半径之间的关系来判断;2:因为这个是依次放球,他可能会和当前坐标左边的碰撞也也能和右边的碰撞,怎么判断它与那个球碰撞?
我开始的思路就是找它前面的球能与它相撞,且圆心位置最高的球;但是 wrong anwer 7;说实话,我现在还不确定这样判断为啥错,希望看了我博客的同学们,找到我的错误,给我留言,告诉我那错了,谢谢!qq邮箱:755672829@qq.com
收获2:我们可以换一种思路,就是这个球与其他某个球相撞了,这个球现在位置一定是当前能达到最高的高度,因为这个球是从高处y = 10^100下滑的,碰撞住东西就停住;
错误代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Max 1010
#include<math.h>
struct node
{
double t;
double l,r;
double h;
}stu[Max];
int n;
double r;
void fff(int j,int i)
{
double kk = sqrt((2*r*2*r)-(stu[i].t-stu[j].t)*(stu[i].t-stu[j].t));
stu[i].h = stu[j].h + kk;
}
int main()
{
int i,j;
while(~scanf("%d%lf",&n,&r))
{
for(i= 0 ;i < n;i++)
{
scanf("%lf",&stu[i].t);
stu[i].l = stu[i].t - r;
stu[i].r = stu[i].t + r;
double hh = -1;
int flag = -1;
for(j = 0;j < i;j ++)
{
if(stu[i].l>stu[j].r||stu[j].l>stu[i].r)
continue;
if(stu[j].h>hh)
{
flag = j;
hh = stu[j].h;
}
}
if(flag == -1)
stu[i].h = r;
else
fff(flag,i);
}
for(i=0;i<n;i++)
{
if(i==n-1) printf("%.10f\n",stu[i].h);
else printf("%.10f ",stu[i].h);
}
}
return 0;
}正确的代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Max 1010
#include<math.h>
struct node
{
double t;
double h;
}stu[Max];
int n;
double r;
int main()
{
int i,j;
while(~scanf("%d%lf",&n,&r))
{
for(i= 0 ;i < n;i++)
{
scanf("%lf",&stu[i].t);
stu[i].h = -1;
for(j = 0;j < i;j ++)
{
// 能落到的一定是最大高度;
if(fabs(stu[i].t-stu[j].t)<=2*r)
stu[i].h = max(stu[i].h,stu[j].h+(sqrt((2*r*2*r)-(stu[i].t-stu[j].t)*(stu[i].t-stu[j].t))));
}
if(stu[i].h==-1)
stu[i].h = r;
}
for(i=0;i<n;i++)
{
if(i==n-1) printf("%.10f\n",stu[i].h);
else printf("%.10f ",stu[i].h);
}
}
return 0;
}
She has n disks each with radius r on the 2D plane.
Initially she has all these disks above the line y = 10100.
She then will slide the disks towards the line y = 0 one by one in order from 1 to n.
When she slides the i-th disk, she will place its center at the point (xi, 10100). She will then push it
so the disk’s y coordinate continuously decreases, and xcoordinate stays constant. The disk stops once it touches the line y = 0 or it touches
any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.
Compute the y-coordinates of centers of all the disks after all disks have been pushed.
Input
The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively.
The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) —
the x-coordinates of the disks.
Output
Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th
disk. The output will be accepted if it has absolute or relative error at most 10 - 6.
Namely, let's assume that your answer for a particular value of a coordinate is aand the answer of the jury is b. The checker program will consider your answer correct if
for
all coordinates.
Example
Input
6 2 5 5 6 8 3 12
Output
2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613
Note
The final positions of the disks will look as follows:
In particular, note the position of the last disk.
题意: 已知一些圆在(xi,10100)处,然后依次落下,下落时只要碰到某个圆或
达到y=0处,就会自动停止,就算再被其他球碰住也不会动,求这些圆的最后的y值,也即是水平高度
说实话考试时,这道题我没做出来,wrong anwer 7;
做了这道题给我的收获是:1:以后再判断圆与圆的位置关系时,就用两个圆心与半径之间的关系来判断;2:因为这个是依次放球,他可能会和当前坐标左边的碰撞也也能和右边的碰撞,怎么判断它与那个球碰撞?
我开始的思路就是找它前面的球能与它相撞,且圆心位置最高的球;但是 wrong anwer 7;说实话,我现在还不确定这样判断为啥错,希望看了我博客的同学们,找到我的错误,给我留言,告诉我那错了,谢谢!qq邮箱:755672829@qq.com
收获2:我们可以换一种思路,就是这个球与其他某个球相撞了,这个球现在位置一定是当前能达到最高的高度,因为这个球是从高处y = 10^100下滑的,碰撞住东西就停住;
错误代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Max 1010
#include<math.h>
struct node
{
double t;
double l,r;
double h;
}stu[Max];
int n;
double r;
void fff(int j,int i)
{
double kk = sqrt((2*r*2*r)-(stu[i].t-stu[j].t)*(stu[i].t-stu[j].t));
stu[i].h = stu[j].h + kk;
}
int main()
{
int i,j;
while(~scanf("%d%lf",&n,&r))
{
for(i= 0 ;i < n;i++)
{
scanf("%lf",&stu[i].t);
stu[i].l = stu[i].t - r;
stu[i].r = stu[i].t + r;
double hh = -1;
int flag = -1;
for(j = 0;j < i;j ++)
{
if(stu[i].l>stu[j].r||stu[j].l>stu[i].r)
continue;
if(stu[j].h>hh)
{
flag = j;
hh = stu[j].h;
}
}
if(flag == -1)
stu[i].h = r;
else
fff(flag,i);
}
for(i=0;i<n;i++)
{
if(i==n-1) printf("%.10f\n",stu[i].h);
else printf("%.10f ",stu[i].h);
}
}
return 0;
}正确的代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Max 1010
#include<math.h>
struct node
{
double t;
double h;
}stu[Max];
int n;
double r;
int main()
{
int i,j;
while(~scanf("%d%lf",&n,&r))
{
for(i= 0 ;i < n;i++)
{
scanf("%lf",&stu[i].t);
stu[i].h = -1;
for(j = 0;j < i;j ++)
{
// 能落到的一定是最大高度;
if(fabs(stu[i].t-stu[j].t)<=2*r)
stu[i].h = max(stu[i].h,stu[j].h+(sqrt((2*r*2*r)-(stu[i].t-stu[j].t)*(stu[i].t-stu[j].t))));
}
if(stu[i].h==-1)
stu[i].h = r;
}
for(i=0;i<n;i++)
{
if(i==n-1) printf("%.10f\n",stu[i].h);
else printf("%.10f ",stu[i].h);
}
}
return 0;
}
相关文章推荐
- Interface的Object之间的关系问题
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- 面试中会遇到的问题:TCP、HTTP、SOCKET之间的关系(详)
- java基础之问题:请说出hashCode方法、equals方法、HashSet、HashMap之间的关系
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- Interface与Object之间的关系问题
- 向日葵Gantt 0.7 中的任务之间链接关系问题
- 编码问题 :Unicode utf8等之间的关系
- EF数据存贮问题二之“无法定义这两个对象之间的关系,因为它们附加到不同的 ObjectContext 对象”
- mySql---or和in的效率问题(和<=、>=、between之间的关系)
- <原创>一串简单的代码牵扯出的session,cookie,$_session,$_cookie之间关系问题
- 请教Interface与Object之间的关系问题
- P问题,NP问题,NPC问题,以及三者之间的关系
- Django中的Model定义和各Model之间的一对一、多对一,多对多关系以及级联查询的问题
- <学习html>第三天笔记-链接标签;锚点定位、<base />标签;遇到标签之间关系的问题及解决方法
- 客户端程序无法直接调用CMP之间one-many关系的cmrfield的问题
- vuex state mutation action 之间关系,axios 跨域代理请求问题
- 在两台服务器之间建立信任关系解决scp,ssh等不用输入密码等问题
- MFC中资源ID和具体控件之间的关系问题【学习笔记】
- 面试可能遇到这样的问题 TCP HTTP SOCKET之间的有什么关系