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.










share|improve this question






















  • 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















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.










share|improve this question






















  • 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













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    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.






    share|improve this answer

























      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.






      share|improve this answer























        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 14:23









        Paul Ogilvie

        16.8k11134




        16.8k11134






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma