I am trying to solve the problem Secret Code on SPOJ, and it's obviously a math problem.
The full problem
For those who are lazy to go and read, it's like this:
a0, a1, a2, ..., an - sequence of N numbers
B - a Complex Number (has both real and imaginary components)
X = a0 + a1*B + a2*(B^2) + a3*(B^3) + ... + an*(B^n)
So if you are given B…
I am trying to solve the problem Secret Code and it's obviously math problem.
The full problem
For those who are lazy to go and read, it's like this:
a0,a1,a2,...,an - sequence of N numbers
B - some number known to us
X = a0 + a1*B + a2*(B^2) + a3*(B^3) + ... + an*(B^n)
So if you are given B and X, you should find a0,a1,..an.
I don't know…
The following function is trying to find the nth to last element of a singly linked list.
For example:
If the elements are 8->10->5->7->2->1->5->4->10->10 then the result is
7th to last node is 7.
Can anybody help me on how this code is working or is there a better and simpler approach?
LinkedListNode…
You have been given an array of size 2n+1 that have n pair of integers(can be +ve, -ve or 0) and one unpaired element.
How would you find the unpaired element.
Pair means duplicate. So (3,3) is a pair and (3,-3) is not a pair.
I'm maintaining a web application which deals with some kind of subscriptions. Users can to renew their subscriptions from 2 months before expiry (not earlier than that). Sometimes user does not renew before expiry and get grace period which is of 3 months. Now he can renew in these 3 months of grace period.
Now the problem part.…
In a sequence of length n, where n=2k+3, that is there are k unique numbers appeared twice
and three numbers appeared only once.
The question is: how to find the three unique numbers that appeared only once?
for example, in sequence 1 1 2 6 3 6 5 7 7 the three unique numbers are 2 3 5.
Note:
3<=n<1e6 and the number will…
Given an image with a large dimension ( 1.000 x 1.000). What is a good approach to find a small image (e.g. 50 x 50) in the big one?
The smaller image can be rotated and differ in the size, but only with a 1:1 ratio.
It's not related to any programming language - I'm just interested in pattern recognition.
Thank you.
I need to check in Java if a word consists of unique letters (case insensitive). As straight solution is boring, I came up with:
For every char in a string check if indexOf(char) == lastIndexOf(char).
Add all chars to HashSet and check if set size == string length.
Convert a string to a char array, sort it alphabetically, loop…
Given two date ranges, what is the simplest or most efficient way to determine whether the two date ranges overlap?
As an example, suppose we have ranges denoted by DateTime variables StartDate1 to EndDate1 and StartDate2 to EndDate2.
For any three given sets A, B and C: is there a way to determine (programmatically) whether there is an element of A that is part of the conjunction of B and C?
example:
A: all numbers greater than 3
B: all numbers lesser than 7
C: all numbers that equal 5
In this case there is an element in set A, being the number 5, that…
I need to study about load-balancers, such as Network Load Balancing, Linux Virtual Server, HAProxy,...There're somethings under-the-hood I need to know:
What algorithms/technologies are used in these load-balancers? Which is the most popular? most effective?
I expect that these algorithms/technologies will not be too…
You have been given an array of size 2n+1 that have n pair of integers(can be +ve, -ve or 0) and one unpaired element.
How would you find the unpaired element.
MIX is the hypothetical computer outlined by Donald Knuth in the Art of Computer Programming.
I guess when I say best, I mean most suitable for working with the algorithms and problems in the Art of Computer Programming.
Greetings,
I am trying to perform a copy from one vector (vec1) to another vector (vec2) using the following 2 abbreviated lines of code (full test app follows):
vec2.reserve( vec1.size() );
copy(vec1.begin(), vec1.end(), vec2.begin());
While the call to vec2 sets the capacity of vector vec2, the copying of data to…
Single Source shortest Path
Dijkstra's - directed and undirected - works only for positive edge weights - cycles ??
Bellman Ford - directed - no cycles should exist
All source shortest path
Floyd Warshall - no info
Minimum Spanning Tree
( no info about edge weights or nature of graph or cycles)
Kruskal's
…
#include<stdio.h>
main()
{
long long int m,n,i,j;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&m);
scanf("%lld",&n);
long long int a[n+2];
for(i=0;i<=n;i++)
{
a[i]=1;
}
for(i=2;i<=sqrt(n);i++)
{
…
Which programming language would you recommend to learn about data structures and algorithms in?
Considering the follwing:
Personal experience
Language features (pointers, OO, etc)
Suitability for learning DS & A concepts
I ask because there are some books out there that are programming language-agnostic…
I have a digraph which is strongly connected (i.e. there is a path from i to j and j to i for each pair of nodes (i, j) in the graph G). I wish to find a strongly connected graph out of this graph such that the sum of all edges is the least.
To put it differently, I need to get rid of edges in such a way that…
Recently there was a question asking about generating all subsets of a set using a stack and a queue, which was closed (and now deleted it seems) as not a real question for no good reason, since it didn't fit into any of these conditions:
It's difficult to tell what is being asked here.
No, it was clear…
I am trying to get a feel for the difference between the various classes of machine-learning algorithms.
I understand that the implementations of evolutionary algorithms are quite different from the implementations of neural networks.
However, they both seem to be geared at determining a correlation…
i am working to generate tango tree,
where i need to check whether every sub tree in tango is balanced or not.
if its not balanced i need to make it balance? I trying so hard to make entire RB-tree balance but i not getting any proper logic so can any one help me out??
here i am adding code to check …
basically I have a texture. I also have a lets say octagon (or any polygon). I find that octagon's bounding box. Let's say my texture is the size of the octagon's bounding box. How could I figure out the texture coordinates so that the texture maps to it. To clarify, lets say you had a square of tin…
9 numbers need to be arranged in a magic number square. A magic number square is a square of numbers that is arranged such that every row and column has the same sum.(condition for diagonal has been relaxed) For example:
1 2 3
3 2 1
2 2 2
How do we calculate total number of distinct magic square…