math

How do I calculate the angle between the hour and minutes hands?

痞子三分冷 提交于 2021-02-06 19:59:23
问题 I'm trying to workout this problem, but I am still struggling to understand the logic to solve this problem. hour degree = 360 / 12 = 30 minutes degree = 360 / 12 / 60 = 0.5 So, according to this, I thought I could formulate the following function in python: def clockangles(hour, min): return (hour * 30) + (min * 0.5) For the hour, it works fine, as it appears to have a 1=1 mapping. But for the minute there is one problem at least. When it's 0 minutes, the minutes hand points to 12. For

How do I calculate the angle between the hour and minutes hands?

≯℡__Kan透↙ 提交于 2021-02-06 19:58:13
问题 I'm trying to workout this problem, but I am still struggling to understand the logic to solve this problem. hour degree = 360 / 12 = 30 minutes degree = 360 / 12 / 60 = 0.5 So, according to this, I thought I could formulate the following function in python: def clockangles(hour, min): return (hour * 30) + (min * 0.5) For the hour, it works fine, as it appears to have a 1=1 mapping. But for the minute there is one problem at least. When it's 0 minutes, the minutes hand points to 12. For

What algorithm can I use to find the shortest path between specified node types in a graph?

一个人想着一个人 提交于 2021-02-06 19:56:45
问题 This is the problem: I have n points (p1, p2, p3, .. pn), each of them can connect to any other with a determined cost x. Each point belongs to one of a set of point-types (for example "A" "B" "C" "D"...). The input of the method is the path I want to follow, for example "A-B-C-A-D-B". The output is the shortest path connecting the points of the type I give in input so for example "p1-p4-p32-p83-p43-p12" where p1 is an A-type, p4 a B-type, p32 a C-type, p83 an A-type, p43 a D-type and p12 a B

Max product of the three numbers for a given array of size N

淺唱寂寞╮ 提交于 2021-02-06 09:11:25
问题 I need to write a program to find the Max product of three numbers for a given array of size N. Is there any effective algorithm for this? I just need to know the algorithm steps. Non of algorithms that i thought works for all the test cases. Thanks! FYI Array may contains +ve, -ve, or zero elements) 回答1: Find the three largest numbers in the array (n1, n2, n3) and the two smallest numbers (m1, m2). The answer is either n1 x n2 x n3 or n1 x m1 x m2 回答2: The method get the max product of 3

Max product of the three numbers for a given array of size N

半腔热情 提交于 2021-02-06 09:08:44
问题 I need to write a program to find the Max product of three numbers for a given array of size N. Is there any effective algorithm for this? I just need to know the algorithm steps. Non of algorithms that i thought works for all the test cases. Thanks! FYI Array may contains +ve, -ve, or zero elements) 回答1: Find the three largest numbers in the array (n1, n2, n3) and the two smallest numbers (m1, m2). The answer is either n1 x n2 x n3 or n1 x m1 x m2 回答2: The method get the max product of 3

Max product of the three numbers for a given array of size N

寵の児 提交于 2021-02-06 09:07:32
问题 I need to write a program to find the Max product of three numbers for a given array of size N. Is there any effective algorithm for this? I just need to know the algorithm steps. Non of algorithms that i thought works for all the test cases. Thanks! FYI Array may contains +ve, -ve, or zero elements) 回答1: Find the three largest numbers in the array (n1, n2, n3) and the two smallest numbers (m1, m2). The answer is either n1 x n2 x n3 or n1 x m1 x m2 回答2: The method get the max product of 3

Calculate distance between two x/y coordinates?

对着背影说爱祢 提交于 2021-02-06 07:56:53
问题 I would like to calculate the distance between two x/y coordinates on the surface of a torus. So, this is a normal grid that has the property that its corners and sides are 'connected'. For example, on a grid of 500x500, the point at (499, 499) is adjacent to (0, 0) and the distance between e.g. (0,0) and (0,495) should then be 5. Is there any good mathematical way of calculating this? 回答1: So you are looking for the Euclidean distance on the two-dimensional surface of a torus, I gather. sqrt

Discarding alpha channel from images stored as Numpy arrays

耗尽温柔 提交于 2021-02-06 07:15:48
问题 I load images with numpy/scikit. I know that all images are 200x200 pixels. When the images are loaded, I notice some have an alpha channel, and therefore have shape (200, 200, 4) instead of (200, 200, 3) which I expect. Is there a way to delete that last value, discarding the alpha channel and get all images to a nice (200, 200, 3) shape? 回答1: Just slice the array to get the first three entries of the last dimension: image_without_alpha = image[:,:,:3] 来源: https://stackoverflow.com/questions

Efficient Packing Algorithm for Irregular Polygons

我们两清 提交于 2021-02-06 03:51:32
问题 I'm looking for a packing algorithm which will reduce an irregular polygon into rectangles and right triangles. The algorithm should attempt to use as few such shapes as possible and should be relatively easy to implement (given the difficulty of the challenge). It should also prefer rectangles over triangles where possible. If possible, the answer to this question should explain the general heuristics used in the suggested algorithm. This should run in deterministic time for irregular

Efficient Packing Algorithm for Irregular Polygons

ぃ、小莉子 提交于 2021-02-06 03:50:29
问题 I'm looking for a packing algorithm which will reduce an irregular polygon into rectangles and right triangles. The algorithm should attempt to use as few such shapes as possible and should be relatively easy to implement (given the difficulty of the challenge). It should also prefer rectangles over triangles where possible. If possible, the answer to this question should explain the general heuristics used in the suggested algorithm. This should run in deterministic time for irregular