Gym - 101666A Amsterdam Distance

75 篇文章 0 订阅

A Amsterdam Distance
Your friend from Manhattan is visiting you in Amsterdam. Because she can only stay for a
short while, she wants to see as many tourist attractions in Amsterdam in as little time as
possible. To do that, she needs to be able to figure out how long it takes her to walk from
one landmark to another. In her hometown, that is easy: to walk from point m = (mx,my)
to point n = (nx, ny) in Manhattan you need to walk a distance
|nx − mx| + |ny − my|,
since Manhattan looks like a rectangular grid of city blocks. However, Amsterdam is not well
approximated by a rectangular grid. Therefore, you have taken it upon yourself to figure out
the shortest distances between attractions in Amsterdam. With its canals, Amsterdam looks
much more like a half-disc, with streets radiating at regular angles from the center, and with
canals running the arc of the circle at equally spaced intervals. A street corner is given by
the intersection of a circular canal and a street which radiates from the city center.

Figure 1: The first sample input.
Depending on how accurately you want to model the street plan of Amsterdam, you can
split the city into more or fewer half rings, and into more or fewer segments. Also, to avoid
conversion problems, you want your program to work with any unit, given as the radius of
the half circle. Can you help your friend by writing a program which computes the distance
between any two street corners in Amsterdam, for a particular approximation?
Input
The input consists of
• One line with two integers M,N and a floating point number R.
– 1 M 100 is the number of segments (or ‘pie slices’) the model of the city is
split into.
4 Problem A: Amsterdam Distance
– 1 N 100 is the number of half rings the model of the city is split into.
– 1 R 1000 is the radius of the city.
• One line with four integers, ax, ay, bx, by, with 0 ax, bx M, and 0 ay, by N, the
coordinates of two corners in the model of Amsterdam.
Output
Output a single line containing a single floating point number, the least distance needed to
travel from point a to point b following only the streets in the model. The result should have
an absolute or relative error of at most 10−6.
Sample Input 1 Sample Output 1
6 5 2.0
1 3 4 2
1.65663706143592
Sample Input 2 Sample Output 2
9 7 3.0
1 5 9 5
4.28571428571429
Sample Input 3 Sample Output 3
10 10 1.0
2 0 6 0
0

 

 

【静思:】

    ACM读题是我过不去的坎,怎么办呢,,,,,,

【题目大意:】

    如图所示的定义的阿姆斯特丹距离(类似曼哈顿距离),求两点之间的最短距离

【题目分析:】

    无非由两种走法,一是先走到内圈点上 然后走一弧长,二是走到圆心,走两个半径具体看代码,至于我为什么放弃了scanf 自己体会吧  注意特判0

//
// Created by DELL on 2020/2/28.
//
#include <cstring>
#include <cstdio>
#include <cmath>
#include <iostream>
#define Pai 3.14159265358979323846
using namespace std;
 double R,r,Ans,Ans2;
int ax,ay,bx,by,n,m;
const double eps = 1e-6;
int main() {
    //scanf("%d%d%f",&m,&n,&R);
    //scanf("%d%d%d%d",&ax,&ay,&bx,&by);
    cin >> m >> n >> R;
    cin >> ax >> ay >> bx >> by;
    r = R / (n * 1.0);
    //printf("%lf\n",R);
    Ans2 = fabs(ay + by) * r;// 璧板埌鍦嗗績
    Ans = r * fabs(ay - by) + r * min(ay,by) * Pai * fabs(ax - bx) / m;
    Ans = min(Ans,Ans2);
    if(fabs(Ans - 0.0) < eps) printf("0\n");
    else printf("%.14lf\n",Ans);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值