UPC-4979 - Amsterdam Distance - 思维

原创 2018年04月15日 11:31:57

题解链接:

https://lucien.ink/archives/152/


题目链接:

http://exam.upc.edu.cn/problem.php?id=4979


题目:

题目描述

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.

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?

输入

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.
– 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 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.

样例输入

6 5 2.0
1 3 4 2

样例输出

1.65663706143592

题意:

  求半个极角坐标系上两点之间的最短曼哈顿距离。


思路:

  从一个点走到另一个点有两种最优方案,一种是先走半径小的那个内圈圆,然后走直线,还有一种是走直线到原点,再走直线到另一个点。


实现:

#include <bits/stdc++.h>
int main() {
//    freopen("in.txt", "r", stdin);
    int m, n, x[2], y[2];
    long double R, r, ans[2];
    scanf("%d%d%Lf%d%d%d%d", &m, &n, &R, x, y, x + 1, y + 1);
    r = R / n;
    ans[0] = r * (fabs(y[0] - y[1])) + acos(-1) * r * std::min(y[0], y[1]) * fabs(x[0] - x[1]) / m;
    ans[1] = (y[0] + y[1]) * r;
    printf("%.14Lf\n", std::min(ans[0], ans[1]));
    return 0;
}
版权声明:来自lucien.ink,转载请注明文章出处。 https://blog.csdn.net/xs18952904/article/details/79947783

计蒜客_A. Amsterdam Distance_思维

给你图片让你走,只有两种走法#include using namespace std; #define pi acos(-1.0) int main() { // cout...
  • jianbagengmu
  • jianbagengmu
  • 2017-11-25 19:08:47
  • 75

HDU-5102-The K-th Distance【思维】【好题】

题目大意:给出一棵树,每条边的权值为1,将树上所有两点之间的距离存进数组,进行从小到大排序,问前k个的值为多少。...
  • loy_184548
  • loy_184548
  • 2017-04-18 19:10:17
  • 371

2014 Benelux Algorithm Programming Contest (BAPC 14) 部分题解

RT
  • u014247806
  • u014247806
  • 2015-05-25 20:32:10
  • 1103

distanceTransform函数

distanceTransform函数 函数的作用: 主要用于计算非零像素到最近零像素点的最短距离。一般用于求解图像的骨骼。。。。 函数调用形式: C++: void distanceTran...
  • qq_18343569
  • qq_18343569
  • 2015-08-25 09:50:29
  • 1847

Amsterdam is shopper's paradise

Amsterdam can be described as shopper's paradise and has ended upselected when the world's top ten "...
  • imdddddd
  • imdddddd
  • 2016-11-03 14:13:44
  • 109

Amsterdam is called shopper's paradisepoker

Amsterdam is actually a shopper's paradisepoker and has ended upselected when the world's top "best ...
  • imdddddd
  • imdddddd
  • 2016-11-03 14:14:47
  • 90

若干个vps的速度测试

山东省济南市联通 US: Los Angeles, California (IPv4+IPv6) [USCA_2]  170 US: Fremont, California (IPv4+IPv6) [...
  • moest
  • moest
  • 2016-08-05 16:11:58
  • 989

ACM模板整理

字符串处理 字典树Trie /* 字典树Trie */ struct Trie { // 最大节点数:模式串个数 * 最大串长度 static const int MAX_NO...
  • slowlight93
  • slowlight93
  • 2014-12-16 17:53:09
  • 572

Amsterdam is a beautiful city

Amsterdam has beautiful tulip glasses, romantic canal, bikes,sparkling diamonds, important art items...
  • imdddddd
  • imdddddd
  • 2016-11-03 14:16:58
  • 151

ACM模板 数论

ACM模板 数论
  • gdymind
  • gdymind
  • 2017-01-05 20:50:03
  • 314
收藏助手
不良信息举报
您举报文章:UPC-4979 - Amsterdam Distance - 思维
举报原因:
原因补充:

(最多只允许输入30个字)