algorithm

C# lottery 6 from 49 algorithm

倾然丶 夕夏残阳落幕 提交于 2021-01-29 05:31:24
问题 I need to display odds to win with ten decimals if I play with just one variant, for six five and four numbers. For example I need to have this 0.0000000715 but I have this 0.0027829314 if I introduce 49,6,I. What is the problem?How can I make it work? I am a beginner and I don't know how i can obtain this 0.0000000715. class Program { static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); int k = Convert.ToInt32(Console.ReadLine()); string category = Console.ReadLine(

How to store random integers from the set of 32-bit integers in a compact data structure to rapidly check membership?

陌路散爱 提交于 2021-01-29 05:22:05
问题 I am thinking about how to organize/allocate memory and that led me to this question, which I have distilled to its essence, so it may seem out of the blue, but the memory question is too complicated and confusing and distracting, so I am not asking it here. I tried asking it earlier and got no response. So here it goes. Say you have a system where you want to check if you have some integer exists in it as fast as possible, and you want to be able to add and remove integers as fast as

Maze generation - recursive division (how it works?)

房东的猫 提交于 2021-01-29 04:50:24
问题 I would like to learn how to generate a perfect maze. I am trying to understand Recursive Division Algorithm. I can't understand how to implement this algorithm. This is my code: bool maze[20][20]; void initMaze() { for(int i = 0; i < 20; i++) for(int j = 0; j < 20; j++) maze[i][j] = false; for(int i = 0; i < 20; i++) maze[0][i] = true; for(int i = 0; i < 20; i++) maze[19][i] = true; for(int i = 0; i < 20; i++) maze[i][0] = true; for(int i = 0; i < 20; i++) maze[i][19] = true; } int randNum

Geometric Series Modulus operation

China☆狼群 提交于 2021-01-29 04:33:14
问题 I am giving a series in the form of 1+r+r^2+r^3+r^4+r^5 I have to find modulus of a sum of series i.e i have to find this value [(r^n-1)/(r-1)]%M I can easily calculate the value of (r^n-1)%M , But the problem is how to calculate the denominator term ? Since Inverse modulo can not be exist if both (r-1) and M are not co prime. Please help how to get this value any approximation or algorithm ? Since summation is very large, I can't calculate the value directly. 回答1: Presumably you're proposing

How do I find the Pareto-optimal points in O(nh) and O(nlog(h)) complexity?

心已入冬 提交于 2021-01-29 04:00:37
问题 Can anybody suggest an algorithm to find Pareto-optimal points (to form a staircase) just as given in diagram in O(n*h) and O(n*log(h)) time complexity, where h is the number of Pareto-optimal points? I used gift wrapping algorithm to solve this (in O(n*h) ), but it only finds convex hulls type of staircase and misses those points who form concave angles. 回答1: To put suggestion in one place. Idea is to use divide and conquer strategy. If we can find pareto point P which splits rest of pareto

Find least colorful path in a graph

限于喜欢 提交于 2021-01-29 03:09:27
问题 The problem i'm trying to solve is this: Given a graph G = (V,E) such that every edge is colored in one of 10 colors, and two vertices: s, t. I need to find an algorithm that produces a (shortest) path from s to t, that goes over a minimal amount of colors. My idea was to duplicate the graph 10 times: The first duplicate will include only edges of one color The second will include only edges of two colors... and so on. Also, I connect an outer node: s' to every "s" node in every duplicate.

Could this algorithm be made better?

早过忘川 提交于 2021-01-29 02:59:08
问题 I have a question, in one of the algorithms, I had written, to seperate out, all the even numbers to the left and odd numbers to the right. Example: Input: { 12, 10, 52, 57, 14, 91, 34, 100, 245, 78, 91, 32, 354, 80, 13, 67, 65 } Output: {12,10,52,80,14,354,34,100,32,78,91,245,91,57,13,67,65} Below is the algorithm public int[] sortEvenAndOdd(int[] combinedArray) { int endPointer = combinedArray.length - 1; int startPointer = 0; for (int i = endPointer; i >= startPointer; i--) { if

List as O(log(n))

醉酒当歌 提交于 2021-01-29 02:55:57
问题 I have to make a data structure with certain conditions. First these 4 functions must be in O(log(n)): insert(Object o) insert(int index, Object o) delete(int index) update(int index, Object o) Second: The data structure must implement java.util.List My issue is with the O(log(n)) and the List. There are a lot of trees that can do the operation in O(log(n)) (like BST, Red-Black Tree, AVL Tree), but how can these trees be indexed and how can the insert be anywhere? Setting this up as only a

Chained Hash Table and understanding Deflate

眉间皱痕 提交于 2021-01-29 02:51:49
问题 I am currently trying to create a custom Deflate implementation in C#. I am currently trying to implement the "pattern search" part where I have (up to) 32k of data and am trying to search the longest possible pattern for my input. The RFC 1951 which defines Deflate says about that process: The compressor uses a chained hash table to find duplicated strings, using a hash function that operates on 3-byte sequences. At any given point during compression, let XYZ be the next 3 input bytes to be

Chained Hash Table and understanding Deflate

久未见 提交于 2021-01-29 02:45:45
问题 I am currently trying to create a custom Deflate implementation in C#. I am currently trying to implement the "pattern search" part where I have (up to) 32k of data and am trying to search the longest possible pattern for my input. The RFC 1951 which defines Deflate says about that process: The compressor uses a chained hash table to find duplicated strings, using a hash function that operates on 3-byte sequences. At any given point during compression, let XYZ be the next 3 input bytes to be