algorithm

Generating points in area with at least X gap length in-between

我与影子孤独终老i 提交于 2021-02-06 03:47:43
问题 I am trying to come up with a method for generating X amount of random points in a given area (in my case a square). The one thing that makes this such an issue is that each point has to be at least Y units away from all other points. What springs to mind at first is (in c#) to check the distance between the new point and all existing points: while(points.Count < pointsToGenerate) { Point newPoint = NewPoint(); bool addPoint = true; foreach(Point p in points) { if((p - newPoint).Length() <

Generating points in area with at least X gap length in-between

你。 提交于 2021-02-06 03:47:06
问题 I am trying to come up with a method for generating X amount of random points in a given area (in my case a square). The one thing that makes this such an issue is that each point has to be at least Y units away from all other points. What springs to mind at first is (in c#) to check the distance between the new point and all existing points: while(points.Count < pointsToGenerate) { Point newPoint = NewPoint(); bool addPoint = true; foreach(Point p in points) { if((p - newPoint).Length() <

Count of co-prime pairs from two arrays in less than O(n^2) complexity

£可爱£侵袭症+ 提交于 2021-02-06 03:46:43
问题 I came to this problem in a challenge. There are two arrays A and B both of size of N and we need to return the count of pairs (A[i],B[j]) where gcd(A[i],B[j])==1 and A[i] != B[j] . I could only think of brute force approach which exceeded time limit for few test cases. for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { if(__gcd(a[i],b[j])==1) { printf("%d %d\n", a[i], b[j]); } } } Can you advice time efficient algorithm to solve this. Edit: Not able to share question link as this was from a

Generate equation with the result value closest to the requested one, have speed problems

淺唱寂寞╮ 提交于 2021-02-06 02:03:19
问题 I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available operations are division, addition, multiplication and division. Parentheses can be used. Generate mathematical expression which evaluation is equal, or as close as possible, to the target value. For example for numbers given above, expression could be : (6

Generate equation with the result value closest to the requested one, have speed problems

微笑、不失礼 提交于 2021-02-06 02:02:01
问题 I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available operations are division, addition, multiplication and division. Parentheses can be used. Generate mathematical expression which evaluation is equal, or as close as possible, to the target value. For example for numbers given above, expression could be : (6

Generate equation with the result value closest to the requested one, have speed problems

为君一笑 提交于 2021-02-06 02:00:58
问题 I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available operations are division, addition, multiplication and division. Parentheses can be used. Generate mathematical expression which evaluation is equal, or as close as possible, to the target value. For example for numbers given above, expression could be : (6

Generate equation with the result value closest to the requested one, have speed problems

我的梦境 提交于 2021-02-06 02:00:54
问题 I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available operations are division, addition, multiplication and division. Parentheses can be used. Generate mathematical expression which evaluation is equal, or as close as possible, to the target value. For example for numbers given above, expression could be : (6

Generate equation with the result value closest to the requested one, have speed problems

蹲街弑〆低调 提交于 2021-02-06 02:00:46
问题 I am writing some quiz game and need computer to solve 1 game in the quiz if players fail to solve it. Given data : List of 6 numbers to use, for example 4, 8, 6, 2, 15, 50. Targeted value, where 0 < value < 1000, for example 590. Available operations are division, addition, multiplication and division. Parentheses can be used. Generate mathematical expression which evaluation is equal, or as close as possible, to the target value. For example for numbers given above, expression could be : (6

Polygon infill algorithm

不羁岁月 提交于 2021-02-05 20:36:24
问题 I'm working on mesh slicing utility for 3d printing purposes. In general it should slice a 3d mesh model into 2d shapes (a number of polygons, probably with holes) and fill them with paths of determined thickness using a specific pattern. These paths will be used to generate a gcode commands for a 3d printer firmware. There are various open source tools with same purposes, written on python and perl. But my goal is to understand the workflow of slicer and to write my own tool in C or C++. So

How to find Strongly Connected Components in a Graph?

人盡茶涼 提交于 2021-02-05 20:20:17
问题 I am trying self-study Graph Theory, and now trying to understand how to find SCC in a graph. I have read several different questions/answers on SO (e.g., 1,2,3,4,5,6,7,8), but I cant find one with a complete step-by-step example I could follow. According to CORMEN (Introduction to Algorithms), one method is: Call DFS(G) to compute finishing times f[u] for each vertex u Compute Transpose(G) Call DFS(Transpose(G)), but in the main loop of DFS, consider the vertices in order of decreasing f[u]