General Question

Hello everyone! I am lately doing some "thinking" C++ problems at Euler and other sites. My question was: what is the best method to solve all this problems?

I always understand what the problem wants but then is very difficult to pass that into code.

OFF: I am really struggling with the combination of pointers + arrays, I really do not know when use a pointer in my program and when they are too much pointers i get confuse.

ON: For example, one problem that i have to solve is this (It's long to read maybe):
A company of electronic equipment is
developing a system
lighting. Since more than one
team of people committed to the development,
they have agreed an interesting interface between
developers of the LEDs and those who
perform the ignition control: in a circumference of the plaquette of control
are determined points which correspond to the different LEDs or to the power switch.

This setup allows some
flexibility, but they have realized that they
now need to determine how to connect
these points (always a LED with a control),
and to do this they must decide
which to join. One complication is that these
unions can not cross because it would make a
short-circuit, and it is necessary to maximize
the number of LEDs that will work! Yes, it is
unbelievable but there could be more (or less)
LEDs than checkpoints.

To help them you must write a function:

connect (chain, pairs)

where:
chain is a secuence of more than 1000 letter "L" or "C" representing the order and function of the points in the circumference. The numeration of the points starts in 1

pairs is a vector of ints where is the conections are hold, always placing the point C in front of their corresponding point L

The function returns an int: the number of the conections that could be established and held in ' connect '


Example:

If chain had:

LLLLCCCLC

The function would return a 4 and pairs could contain:
5 3 7 8 6 2 9 1


Implementation: int connect( (char chain[], int pairs[ ]);

I had to translate all these on my own without google translate (because the translations omg..), it's too bad but it's something.

EDIT: I do not have to do an exam or something, it's just to keep learning by my own, in my classes we only see excel and power point so imagine...

EDIT 2: I am not trying to get the code to this example, just a tip: How to be able to think to solve this kind of excercise
Last edited on
Hm. Maximum number of working LED would be min(LEDS, CONNECT_POINTS).
To solve this is fairly easy: connect adjanced pair of L and C, Then combine next closest one, then next, etc. Example of how it would be done on your input:
 ______
 | __ |
 | || |
LLLLCCCLC
| |  |  |
| ————  |
—————————   
Ok, i see it, what is pair used for? I can not understand for example in my input, what are they there for:
If chain had:

LLLLCCCLC

The function would return a 4 and pairs could contain:
5 3 7 8 6 2 9 1
They are not for input, they are for output. You should write them. And note that in example it is just one of the possible results:
pairs could contain
. In their output grouping is slightly different from my example:
_________
| ___ __|
| | | |||
LLLLCCCLC
 |   |
 —————
5th element is connected with 3rd, 7th with 8th, etc.

Solution from my previous post would have pairs
4 5 3 6 2 7 1 9
in any order.
Thank you very much for clarifying this to me, really thankful.

Delsh
Topic archived. No new replies allowed.