C - order of movement in a 2D array for maximum sum collected
up vote
0
down vote
favorite
I've been having trouble with a problem, something like this:
I have a 2D array where each position is filled with a certain number samples (represented by ints). There are nanorobots, each going in a straight line through a part of a line of column (each with a pre-specified way), collecting all samples along the way. If a nanorobot collects samples on a position, the position becomes contaminated and if another robot comes there, it gets confused and stops. I can deploy the robots in any order, and each robot starts working only after the previous one has stopped.
With this information, I want to find the order in which the highest number of samples is collected.
Any help with the problem would be appreciated, as I am pretty stumped. I have a general idea of how it's done, but can't seem to move forward. One thing specifically is how do I mark which places a robot has been to so that i know where other robots should stop if they come there, every solution I've come up with seems really slow. Thanks.
c arrays sum 2d
add a comment |
up vote
0
down vote
favorite
I've been having trouble with a problem, something like this:
I have a 2D array where each position is filled with a certain number samples (represented by ints). There are nanorobots, each going in a straight line through a part of a line of column (each with a pre-specified way), collecting all samples along the way. If a nanorobot collects samples on a position, the position becomes contaminated and if another robot comes there, it gets confused and stops. I can deploy the robots in any order, and each robot starts working only after the previous one has stopped.
With this information, I want to find the order in which the highest number of samples is collected.
Any help with the problem would be appreciated, as I am pretty stumped. I have a general idea of how it's done, but can't seem to move forward. One thing specifically is how do I mark which places a robot has been to so that i know where other robots should stop if they come there, every solution I've come up with seems really slow. Thanks.
c arrays sum 2d
Can you post your code?
– Fiddling Bits
Nov 11 at 13:55
Welcome to Stack Overflow. Please read the help pages, take the SO tour, read about how to ask good questions, as well as this question checklist. Lastly learn how to create a Minimal, Complete, and Verifiable Example.
– Some programmer dude
Nov 11 at 14:00
If all samples are positive ints, then you can use a negative value to indicate it was visited. You also say each position can have multiple samples (ints), so your array probably should have lists containing the [variable amount of] samples.
– Paul Ogilvie
Nov 11 at 14:14
I honestly don't have much yet, however I was thinking to add visited positions to an array and then compare current element to those in the array, but that's slow. Second idea was to add bools to every position to signify if it was visited, but I'd have to change every bool to false after every iteration, which seems slow also.
– OneT
Nov 11 at 14:20
@PaulOgilvie The number of samples on a position is represented by one int, sorry for not being clear.
– OneT
Nov 11 at 14:23
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've been having trouble with a problem, something like this:
I have a 2D array where each position is filled with a certain number samples (represented by ints). There are nanorobots, each going in a straight line through a part of a line of column (each with a pre-specified way), collecting all samples along the way. If a nanorobot collects samples on a position, the position becomes contaminated and if another robot comes there, it gets confused and stops. I can deploy the robots in any order, and each robot starts working only after the previous one has stopped.
With this information, I want to find the order in which the highest number of samples is collected.
Any help with the problem would be appreciated, as I am pretty stumped. I have a general idea of how it's done, but can't seem to move forward. One thing specifically is how do I mark which places a robot has been to so that i know where other robots should stop if they come there, every solution I've come up with seems really slow. Thanks.
c arrays sum 2d
I've been having trouble with a problem, something like this:
I have a 2D array where each position is filled with a certain number samples (represented by ints). There are nanorobots, each going in a straight line through a part of a line of column (each with a pre-specified way), collecting all samples along the way. If a nanorobot collects samples on a position, the position becomes contaminated and if another robot comes there, it gets confused and stops. I can deploy the robots in any order, and each robot starts working only after the previous one has stopped.
With this information, I want to find the order in which the highest number of samples is collected.
Any help with the problem would be appreciated, as I am pretty stumped. I have a general idea of how it's done, but can't seem to move forward. One thing specifically is how do I mark which places a robot has been to so that i know where other robots should stop if they come there, every solution I've come up with seems really slow. Thanks.
c arrays sum 2d
c arrays sum 2d
asked Nov 11 at 13:31
OneT
1
1
Can you post your code?
– Fiddling Bits
Nov 11 at 13:55
Welcome to Stack Overflow. Please read the help pages, take the SO tour, read about how to ask good questions, as well as this question checklist. Lastly learn how to create a Minimal, Complete, and Verifiable Example.
– Some programmer dude
Nov 11 at 14:00
If all samples are positive ints, then you can use a negative value to indicate it was visited. You also say each position can have multiple samples (ints), so your array probably should have lists containing the [variable amount of] samples.
– Paul Ogilvie
Nov 11 at 14:14
I honestly don't have much yet, however I was thinking to add visited positions to an array and then compare current element to those in the array, but that's slow. Second idea was to add bools to every position to signify if it was visited, but I'd have to change every bool to false after every iteration, which seems slow also.
– OneT
Nov 11 at 14:20
@PaulOgilvie The number of samples on a position is represented by one int, sorry for not being clear.
– OneT
Nov 11 at 14:23
add a comment |
Can you post your code?
– Fiddling Bits
Nov 11 at 13:55
Welcome to Stack Overflow. Please read the help pages, take the SO tour, read about how to ask good questions, as well as this question checklist. Lastly learn how to create a Minimal, Complete, and Verifiable Example.
– Some programmer dude
Nov 11 at 14:00
If all samples are positive ints, then you can use a negative value to indicate it was visited. You also say each position can have multiple samples (ints), so your array probably should have lists containing the [variable amount of] samples.
– Paul Ogilvie
Nov 11 at 14:14
I honestly don't have much yet, however I was thinking to add visited positions to an array and then compare current element to those in the array, but that's slow. Second idea was to add bools to every position to signify if it was visited, but I'd have to change every bool to false after every iteration, which seems slow also.
– OneT
Nov 11 at 14:20
@PaulOgilvie The number of samples on a position is represented by one int, sorry for not being clear.
– OneT
Nov 11 at 14:23
Can you post your code?
– Fiddling Bits
Nov 11 at 13:55
Can you post your code?
– Fiddling Bits
Nov 11 at 13:55
Welcome to Stack Overflow. Please read the help pages, take the SO tour, read about how to ask good questions, as well as this question checklist. Lastly learn how to create a Minimal, Complete, and Verifiable Example.
– Some programmer dude
Nov 11 at 14:00
Welcome to Stack Overflow. Please read the help pages, take the SO tour, read about how to ask good questions, as well as this question checklist. Lastly learn how to create a Minimal, Complete, and Verifiable Example.
– Some programmer dude
Nov 11 at 14:00
If all samples are positive ints, then you can use a negative value to indicate it was visited. You also say each position can have multiple samples (ints), so your array probably should have lists containing the [variable amount of] samples.
– Paul Ogilvie
Nov 11 at 14:14
If all samples are positive ints, then you can use a negative value to indicate it was visited. You also say each position can have multiple samples (ints), so your array probably should have lists containing the [variable amount of] samples.
– Paul Ogilvie
Nov 11 at 14:14
I honestly don't have much yet, however I was thinking to add visited positions to an array and then compare current element to those in the array, but that's slow. Second idea was to add bools to every position to signify if it was visited, but I'd have to change every bool to false after every iteration, which seems slow also.
– OneT
Nov 11 at 14:20
I honestly don't have much yet, however I was thinking to add visited positions to an array and then compare current element to those in the array, but that's slow. Second idea was to add bools to every position to signify if it was visited, but I'd have to change every bool to false after every iteration, which seems slow also.
– OneT
Nov 11 at 14:20
@PaulOgilvie The number of samples on a position is represented by one int, sorry for not being clear.
– OneT
Nov 11 at 14:23
@PaulOgilvie The number of samples on a position is represented by one int, sorry for not being clear.
– OneT
Nov 11 at 14:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
To help you developing your algorithms, I provide you with a possible data structure:
typedef struct LIST {
int sample;
struct LIST *next;
} t_list;
typedef struct ITEM {
t_list *samples;
int visited;
} t_item;
t_item items[10][10];
This defines an array of 10x10 items. Each item has a list of samples and an indicator that it has been visited ("contaminated"). A list element (a sample) has the sample value and a pointer to the next list element (the next sample). I hope this helps.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
To help you developing your algorithms, I provide you with a possible data structure:
typedef struct LIST {
int sample;
struct LIST *next;
} t_list;
typedef struct ITEM {
t_list *samples;
int visited;
} t_item;
t_item items[10][10];
This defines an array of 10x10 items. Each item has a list of samples and an indicator that it has been visited ("contaminated"). A list element (a sample) has the sample value and a pointer to the next list element (the next sample). I hope this helps.
add a comment |
up vote
0
down vote
To help you developing your algorithms, I provide you with a possible data structure:
typedef struct LIST {
int sample;
struct LIST *next;
} t_list;
typedef struct ITEM {
t_list *samples;
int visited;
} t_item;
t_item items[10][10];
This defines an array of 10x10 items. Each item has a list of samples and an indicator that it has been visited ("contaminated"). A list element (a sample) has the sample value and a pointer to the next list element (the next sample). I hope this helps.
add a comment |
up vote
0
down vote
up vote
0
down vote
To help you developing your algorithms, I provide you with a possible data structure:
typedef struct LIST {
int sample;
struct LIST *next;
} t_list;
typedef struct ITEM {
t_list *samples;
int visited;
} t_item;
t_item items[10][10];
This defines an array of 10x10 items. Each item has a list of samples and an indicator that it has been visited ("contaminated"). A list element (a sample) has the sample value and a pointer to the next list element (the next sample). I hope this helps.
To help you developing your algorithms, I provide you with a possible data structure:
typedef struct LIST {
int sample;
struct LIST *next;
} t_list;
typedef struct ITEM {
t_list *samples;
int visited;
} t_item;
t_item items[10][10];
This defines an array of 10x10 items. Each item has a list of samples and an indicator that it has been visited ("contaminated"). A list element (a sample) has the sample value and a pointer to the next list element (the next sample). I hope this helps.
answered Nov 11 at 14:23
Paul Ogilvie
16.8k11134
16.8k11134
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249237%2fc-order-of-movement-in-a-2d-array-for-maximum-sum-collected%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post your code?
– Fiddling Bits
Nov 11 at 13:55
Welcome to Stack Overflow. Please read the help pages, take the SO tour, read about how to ask good questions, as well as this question checklist. Lastly learn how to create a Minimal, Complete, and Verifiable Example.
– Some programmer dude
Nov 11 at 14:00
If all samples are positive ints, then you can use a negative value to indicate it was visited. You also say each position can have multiple samples (ints), so your array probably should have lists containing the [variable amount of] samples.
– Paul Ogilvie
Nov 11 at 14:14
I honestly don't have much yet, however I was thinking to add visited positions to an array and then compare current element to those in the array, but that's slow. Second idea was to add bools to every position to signify if it was visited, but I'd have to change every bool to false after every iteration, which seems slow also.
– OneT
Nov 11 at 14:20
@PaulOgilvie The number of samples on a position is represented by one int, sorry for not being clear.
– OneT
Nov 11 at 14:23