• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

can anybody explain the meaning of this programming problem please  RSS feed

 
Ranch Hand
Posts: 817
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can anybody explain the meaning of this programming problem please
Thanks

----------------------------------------



Problem Statement
����
You are given a set of two-dimensional vectors in two int[]s - x and y (the i-th elements of x and y represent x and y coordinates of the i-th vector). Find a subset of the vectors such that the sum of all vectors in the subset has the maximum possible length. Return this length.
Definition
����
Class:
VectorSet
Method:
maxLength
Parameters:
int[], int[]
Returns:
double
Method signature:
double maxLength(int[] x, int[] y)
(be sure your method is public)
����

Notes
-
The sum of vectors (x1, y1) and (x2, y2) is the vector (x1+x2, y1+y2).
-
The length of vector (x, y) is the value sqrt(x * x + y * y).
-
The returned value must be accurate to within a relative or absolute value of 1E-9.
-
The input (as well as the resulting subset) can contain equal vectors (see example 1).
-
Consider the entire set to be a subset.
Constraints
-
x will contain between 1 and 50 elements, inclusive.
-
x and y will contain the same number of elements.
-
Each element of x will be between -1000 and 1000, inclusive.
-
Each element of y will be between -1000 and 1000, inclusive.
Examples
0)

����
{0,0}
{1,-1}
Returns: 1.0
Choose any one vector.
1)

����
{0, 0}
{1, 1}
Returns: 2.0
Choose two vectors. The sum is (0, 2).
2)

����
{0, 0, 1, -1}
{1, -1, 0, 0}
Returns: 1.4142135623730951

3)

����
{0, 0, 0, 0}
{1, 2, -1, -2}
Returns: 3.0

4)

����
{17,8,-5,-8,-8,-11,-3,2,19,4,22,15,20,13,-7,15,-23,17,-9,-10,17,24,20,-22,-1,-7,-19,18,-17}
{7,-5,-2,18,-9,-24,14,9,-21,14,-23,7,14,23,23,17,17,22,-3,-21,-10,1,24,-17,25,12,-21,12,13}
Returns: 289.4563870430224
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Java in General (beginner) forum.

To anybody that decides to help:
Please try to be as helpful as possible without providing complete solutions. In the long run these don't help anyone

Dave
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a hint:

Brute force: Compute the length of all possibilities and choose the highest length.
You can do this recursively, by making a method that calls itself n (=arraylength) times each time removing one element from the arrays.
That way, you get n! (n * n-1 * n-2 * ... * 2 * 1) iterations.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!