首页 > 代码库 > Asakura的魔法世界
Asakura的魔法世界
Font Size:AaAaAa DescriptionAsakura存在于一个魔法世界中。 Input多组输入 对于每组測试数据:包括三行 第一行输入四个整数x1,y1,x2,y2.当中(x1,y1)为A。(x2,y2)为B.(-10000<=x1,y1,x2,y2<=10000) 第二行输入四个整数x3,y3,x4,y4.当中(x3,y3)为C,(x4,y4)为D.(-10000<=x3,y3,x4,y4<=10000) 第三行输入三个整数v1,v2,v3.(1<=v1,v2,v3<=50) 每两组測试数据间输入一个空行。 Output输出A到D最短的时间。结果精度到小数点后两位(四舍五入)。 Sample Input0 0 50 50 50 0 50 50 1 1 1 0 0 50 50 50 0 50 50 3 1 3 0 0 50 50 50 0 50 50 1 3 1 Sample Output70.71 23.57 63.81
代码例如以下: #include<cstdio> #include<cmath> double dis( double x1, double y1, double x2, double y2) { return sqrt ((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)); } double v1, v2, v3, x[4], y[4]; double mindis( double xi, double yi) { double i = x[3] - x[2]; double j = y[3] - y[2]; double l = 0, r = 1; int t; double tmid, tmidmid; for (t = 1; t <= 50; t++) { double mid = (l + r) / 2; double midmid = (mid + r) / 2; double midx = x[2] + mid*i; double midy = y[2] + mid*j; double midmidx = x[2] + midmid*i; double midmidy = y[2] + midmid*j; tmid = dis(xi, yi, midx, midy) / v3 + dis(midx, midy, x[3], y[3]) / v2; tmidmid = dis(xi, yi, midmidx, midmidy) / v3 + dis(midmidx, midmidy, x[3], y[3]) / v2; if (tmid > tmidmid) l = mid; else r = midmid; } return tmidmid; } int main() { while (~ scanf ( "%lf %lf %lf %lf" , &x[0], &y[0], &x[1], &y[1])) { scanf ( "%lf %lf %lf %lf" , &x[2], &y[2], &x[3], &y[3]); scanf ( "%lf %lf %lf" , &v1, &v2, &v3); double i = x[1] - x[0]; double j = y[1] - y[0]; double l = 0, r = 1; int t; double tmid, tmidmid; for (t = 1; t <= 50; t++) { double mid = (l + r) / 2; double midmid = (mid + r) / 2; double midx = x[0] + mid*i; double midy = y[0] + mid*j; double midmidx = x[0] + midmid*i; double midmidy = y[0] + midmid*j; tmid = dis(x[0], y[0], midx, midy) / v1 + mindis(midx, midy); tmidmid = dis(x[0], y[0], midmidx, midmidy) / v1 + mindis(midmidx, midmidy); if (tmid > tmidmid) l = mid; else r = midmid; } printf ( "%.2lf\n" , tmid); } return 0; } |
Asakura的魔法世界
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。