Hey, can you check if my code matches the criteria? Participants are tasked with organizing a rescue mission in a dense forest, where several people
are lost and scattered across different zones. The goal is to guide rescue teams to retrieve them
efficiently, manage supplies, and prioritize those in most need of rescue. Participants must design
a system that uses data structures to optimize team movement, resource management, and the
tracking of rescued individuals.
Specific Tasks
1. Zones and Rescue Teams Setup: The forest is divided into multiple zones. Each zone
has a priority level (1 = highest priority, 5 = lowest) and contains people in need of
rescue. Each zone also contains necessary supplies for the rescue teams.
2. The system should be able to prioritize zones based on urgency and manage the
distribution of supplies to the teams.
3. Team Movement (Zone Visit Management): Teams must move between zones
efficiently, visiting the zones that need rescue while avoiding unnecessary backtracking.
The movement should follow a structured order to ensure that zones are visited without
missing any priority rescues.
4. Rescue Supply Management: Each rescue team has limited supplies such as first aid kits,
food, etc. The system should manage the supplies effectively, ensuring that the rescue
teams use them in a strategic and optimal manner when entering each zone.
5. Tracking Rescued People: The system must track the people who have been rescued,
recording their details and the time of rescue. The system should allow for quick updates
and retrieval of rescue information.
6. Sorting Rescue Priorities: As the zones are prioritized, the system should manage and
sort the rescue operation, ensuring that the most urgent rescues are addressed first. The
priority of zones and people should be constantly updated based on the progression of the
rescue mission.
Evaluation Criteria
1. Effective Use of Priority Queue: The priority queue should be used effectively to handle
zone priorities, ensuring that high-priority zones are rescued first.
2. Efficient Path Management and Resource Management: The queue should be used to
manage team movement between zones, ensuring that each zone is visited in the correct
order without backtracking. The stack should effectively handle resource allocation,
ensuring teams have the necessary supplies when needed.
3. Binary Tree for Efficient Record-Keeping: The binary tree should efficiently track and
sort rescued people based on time or urgency, allowing for quick lookups and updates.
4. System Efficiency: The system should handle dynamic changes, such as updating zones
or the status of rescued people, in an efficient manner.
5. User-Friendliness: The design should be intuitive, with an easy-to-understand flow for
zone visits, rescue priorities, and supply usage.#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_RESOURCES 10
#define GROUP_SIZE 5

typedef struct {
    char *array[MAX_RESOURCES];
    int top;
} resources;

typedef struct Zone {
    resources resources;
    int people;
    struct Zone *next;
    char *zoneID;
    int zonePriority;
} zone;

typedef struct PQNode {
    zone *zone;
    int priority; // Re consider
    struct PQNode *next;
} PQNode;

typedef struct PriorityZones { // Priority Q structure
    PQNode *head;
    PQNode *tail;
} PriorityZones;

typedef struct Team {
    char *id;
    int numMembers;
} Team;

typedef struct RescuedRecord { 
    char *groupID; 
    struct RescuedRecord *left;
    struct RescuedRecord *right;
} RescuedRecord;

typedef struct { // Binary Tree structure 
    RescuedRecord *root;
} RescuedTree;

void initPriorityZones(PriorityZones *zoneSet);
zone *createZone();
void insertZone(PriorityZones *zoneSet, zone *newZone);
zone *dequeueZone(PriorityZones *zoneSet);
void addRandomResource(resources *r, int resourceCount);
void manageSupplies(resources *zoneResources, Team *team);
RescuedRecord *insertRescued(RescuedRecord *node, char *groupID);
void printRescued(RescuedRecord *root);
void setTeam(Team *team, int teamIndex);
void freeZone(zone *z);

void initPriorityZones(PriorityZones *zoneSet) {
    zoneSet->head = NULL;
    zoneSet->tail = NULL;
}

zone *createZone() {
    zone *newZone = (zone *)malloc(sizeof(zone));
    newZone->resources.top = -1;

    newZone->zoneID = (char *)malloc(50 * sizeof(char));
    printf("Enter Zone ID: ");
    scanf("%49s", newZone->zoneID); // Replace with scanf("%[^\n]s") in all instances

    printf("Enter number of people in %s: ", newZone->zoneID);
    scanf("%d", &newZone->people);

    printf("Enter priority for %s (1-5): ", newZone->zoneID);
    scanf("%d", &newZone->zonePriority);// zone priority is from 1-->5, so zones with higher priorities are handled quickly

    printf("Enter number of resources in %s: ", newZone->zoneID);
    int resourceCount;
    scanf("%d", &resourceCount);
    addRandomResource(&newZone->resources, resourceCount);

    printf("\n");
    newZone->next = NULL;
    return newZone;
}

void insertZone(PriorityZones *zoneSet, zone *newZone) {
    PQNode *newNode = (PQNode *)malloc(sizeof(PQNode));
    newNode->zone = newZone;
    newNode->priority = newNode->zone->zonePriority;
    newNode->next = NULL;

    if (zoneSet->head == NULL) {
        zoneSet->head = zoneSet->tail = newNode;
    } else {
        PQNode *current = zoneSet->head, *prev = NULL;
        while (current != NULL && current->priority <= newNode->priority) {
            prev = current;
            current = current->next;
        }
        if (prev == NULL) {
            newNode->next = zoneSet->head;
            zoneSet->head = newNode;
        } else if (current == NULL) {
            zoneSet->tail->next = newNode;
            zoneSet->tail = newNode;
        } else {
            prev->next = newNode;
            newNode->next = current;
        }
    }
}

zone *dequeueZone(PriorityZones *zoneSet) {
    if (zoneSet->head == NULL) {
        printf("No zones left to process.\n");
        return NULL;
    }
    PQNode *nodeToRemove = zoneSet->head;
    zone *z = nodeToRemove->zone;
    zoneSet->head = zoneSet->head->next;
    free(nodeToRemove);
    return z;
}

void addRandomResource(resources *r, int resourceCount) {
    const char *resourceTypes[] = {"Water", "Food", "Medicine", "Tools", "Blankets"};
    int numResourceTypes = sizeof(resourceTypes) / sizeof(resourceTypes[0]);

    for (int i = 0; i < resourceCount && i < MAX_RESOURCES; i++) {
        r->top++;
        int randomIndex = rand() % numResourceTypes;
        r->array[r->top] = (char *)resourceTypes[randomIndex];
    }
}

void manageSupplies(resources *zoneResources, Team *team) {
    if (zoneResources->top >= 0) {
        printf("Team %s using resource %s from zone.\n", team->id, zoneResources->array[zoneResources->top]);
        zoneResources->top--;
    } else {
        printf("No resources left in this zone.\n");
    }
}

RescuedRecord *insertRescued(RescuedRecord *node, char *groupID) {
    if (node == NULL) {
        RescuedRecord *newRecord = (RescuedRecord *)malloc(sizeof(RescuedRecord));
        newRecord->groupID = groupID;
        newRecord->left = newRecord->right = NULL;
        return newRecord;
    }
    if (strcmp(groupID, node->groupID) < 0) {
        node->left = insertRescued(node->left, groupID);
    } else {
        node->right = insertRescued(node->right, groupID);
    }
    return node;
}

void printRescued(RescuedRecord *root) {
    if (root != NULL) {
        printRescued(root->left);
        printf("Rescued Group: %s\n", root->groupID);
        printRescued(root->right);
    }
}

void setTeam(Team *team, int teamIndex) {
    team->id = (char *)malloc(20 * sizeof(char));
    team->id[0] = '\0';
    sprintf(team->id, "Team_%d", teamIndex + 1);

    printf("Enter number of members in %s: ", team->id);
    scanf("%d", &team->numMembers);
}

void freeZone(zone *z) {
    free(z->zoneID);
    free(z);
}

int main() {
    PriorityZones zoneSet;
    initPriorityZones(&zoneSet);

    RescuedTree rescuedTree = {NULL};

    int numberOfZones;
    printf("Enter number of zones to process: ");
    scanf("%d", &numberOfZones);
    for (int i = 0; i < numberOfZones; ++i) {
        zone *newZone = createZone();
        insertZone(&zoneSet, newZone);
    }

    int numberOfTeams;
    printf("Enter number of rescue teams: ");
    scanf("%d", &numberOfTeams);
    Team *teams = (Team *)malloc(numberOfTeams * sizeof(Team));
    for (int i = 0; i < numberOfTeams; i++) {
        setTeam(&teams[i], i);
    }

    zone *currentZone;
    while ((currentZone = dequeueZone(&zoneSet)) != NULL) {
        printf("\nProcessing %s with priority %d\n", currentZone->zoneID, currentZone->zonePriority);
        for (int teamIndex = 0; teamIndex < numberOfTeams; ++teamIndex) {
            printf("Team %s entering %s...\n", teams[teamIndex].id, currentZone->zoneID);
            manageSupplies(&currentZone->resources, &teams[teamIndex]);

            int groups = currentZone->people / GROUP_SIZE;
            if (currentZone->people % GROUP_SIZE != 0) {
                groups++; // If there are remaining people less than a full group
            }

            for (int g = 0; g < groups; g++) {
                char *groupID = (char *)malloc(50 * sizeof(char));
                groupID[0] = '\0';
                sprintf(groupID, "Group_%d_From_%s", g + 1, currentZone->zoneID);
                rescuedTree.root = insertRescued(rescuedTree.root, groupID);
            }
        }
        freeZone(currentZone);
    }

    printf("\nList of Rescued Groups:\n");
    printRescued(rescuedTree.root);

    for (int i = 0; i < numberOfTeams; i++) {
        free(teams[i].id);
    }
    free(teams);

    return 0;
}