algorithm

Calculating precision of sum of fractions

喜夏-厌秋 提交于 2021-01-28 12:15:37
问题 I have this mathematical expression : ∑(2k+1)/(2k)! , k =0,... ,∞ , it is sum from zero to infinity of all fractions in the form (2k+1)/(2k)! I want to create a method which when passed an integer "n", it will output me the result with n digits after the decimal point.This expression first 100 digits can be viewed here : https://miniwebtool.com/first-n-digits-of-e/?number=100 Here is my code, what I have attempted package pi.strategy; import java.math.BigDecimal; import java.math.BigInteger;

Partitioning a set of points in 2D plane

风流意气都作罢 提交于 2021-01-28 11:56:07
问题 The problem statement is - "You are given a set of N points, where N is even and N <= 1000. You have to find the number of pairs of points, such that if you draw a line through that pair, each side of the line will contains equal number of points(N/2-1)." I can't figure out, how to solve this problem in O(n^2) or less time? Here is my brute-force solution- class Point{ public: int x, y; Point(){x = y = 0;} void make_point(int X, int Y){ x = X; y = Y; } int Point:: orientation (Point &p0,

How to constrain items with multiple randomly selected positions so that the average position for each is within a certain range

╄→尐↘猪︶ㄣ 提交于 2021-01-28 11:01:03
问题 Problem: In total, I have 1-300 positions to fill in, I have 50 items, each item has 6 unique positions to choose (300 total positions). The average position for each of these items needs to be in range 145-155 (the closer to 150 the better) Constraints: For each item, each of its 6 positions must fall within a list of fixed ranges (called runs), but not be within the same run, e.g. The runs are: [(1,36), (37,73), (74,110), (111,148), (149,186), (187,225), (226,262), (263, 300)] . So item 1

Permutation algorithm for n characters in x positions

泄露秘密 提交于 2021-01-28 10:32:13
问题 e.g. A permutation algorithm for {&, *, %} to be placed in 8 positions: &&&&&&&&& &&&&&&&&* &&&&&&&&% &&&&&&&*% &&&&&&&** ... Heap's permutation algorithm I saw on the Internet works just for those who the number of characters are equal to the number of positions, And those who can work with unequal number of characters and number of positions, Only work with integers, Not characters. I also have to say I haven't reached any working algorithm up to now, As I don't know anything about

Permutation algorithm for n characters in x positions

喜夏-厌秋 提交于 2021-01-28 10:28:42
问题 e.g. A permutation algorithm for {&, *, %} to be placed in 8 positions: &&&&&&&&& &&&&&&&&* &&&&&&&&% &&&&&&&*% &&&&&&&** ... Heap's permutation algorithm I saw on the Internet works just for those who the number of characters are equal to the number of positions, And those who can work with unequal number of characters and number of positions, Only work with integers, Not characters. I also have to say I haven't reached any working algorithm up to now, As I don't know anything about

Permutation algorithm for n characters in x positions

时光毁灭记忆、已成空白 提交于 2021-01-28 10:26:40
问题 e.g. A permutation algorithm for {&, *, %} to be placed in 8 positions: &&&&&&&&& &&&&&&&&* &&&&&&&&% &&&&&&&*% &&&&&&&** ... Heap's permutation algorithm I saw on the Internet works just for those who the number of characters are equal to the number of positions, And those who can work with unequal number of characters and number of positions, Only work with integers, Not characters. I also have to say I haven't reached any working algorithm up to now, As I don't know anything about

Python: Search a sorted list of tuples

ぃ、小莉子 提交于 2021-01-28 09:50:26
问题 Useful information: For information on how to sort a list of various data types see: How to sort (list/tuple) of lists/tuples? .. and for information on how to perform a binary search on a sorted list see: Binary search (bisection) in Python My question: How can you neatly apply binary search (or another log(n) search algorithm) to a list of some data type, where the key is a inner-component of the data type itself? To keep the question simple we can use a list of tuples as an example: x = [(

Recursive algorithm to solve change-making problem

若如初见. 提交于 2021-01-28 09:34:56
问题 I want to make a recursive algorithm that solves the change-making problem. Is it possible to use a non-dynamic approach that not only returns the minimum number of coins but also returns the set of coins used to make-up the given value, For example, given the value 6 and the set of coins=[1, 3, 4]. Is it possible to make a recursive algorithm that doesn't memoise that can return both the minimum number of coins (2) and the set of coins (3,3)? EDIT: This is my current algorithm but it only

Subset sum - Recover solution

倾然丶 夕夏残阳落幕 提交于 2021-01-28 09:02:58
问题 I have written a dynamic programming algorithm that finds the total amount of subsets that sum up to a target value. However, I am having trouble developing a function to recover the solution (that is, print out the actual subsets). For example, let's take the set [1,3,5,7,9,10] with the target 13 . My algorithm calculates that there are 3 subsets. The output table is shown in the image below. Because this is a simple set, I can manually determine which three subsets make up the target. That

Find cut set in a graph [duplicate]

点点圈 提交于 2021-01-28 08:40:41
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Algorithm: for G = (V,E), how to determine if the set of edges(e belong to E) is a valid cut set of a graph A subset S, of edges of a graph G = (V,E), how can one check whether it is a valid cut-set of the graph or not? Note: A cut is a partition of the vertices of a graph into two disjoint subsets. So, cut-set of the cut is the set of edges whose end points are in different subsets of the partition. I am