Untitled
raw download clone
C
views 9
,
size 2031 b
#include <stdio.h>
#include <stdlib.h>

typedef struct _Obj
{
    int hp, atk, x, y;
} Obj;

typedef struct _Mon
{
    Obj m[1005];
} Mon;

int k;

int tox[] = {1, -1, 0, 0};
int toy[] = {0, 0, 1, -1};

int visited[10][10];
Obj* enc_id = NULL;
Obj* encounter(Obj Hero, Mon mon)
{
    for (int i = 0; i < k; i++)
    {

        if (mon.m[i].x == Hero.x && mon.m[i].y == Hero.y && mon.m[i].hp > 0)
        {

            enc_id = &(mon.m[i]);
            return enc_id;
        }
    }
    return NULL;
}
int battle(Obj *Hero, Obj *m)
{
    if (m->x == Hero->x && m->y == Hero->y && m->hp > 0)
    {

        int round = (m->hp / Hero->atk) + (m->hp % Hero->atk == 0 ? 0 : 1);
        Hero->hp -= (round - 1) * (m->atk);

        m->hp = 0;
        m->x = 0;
        m->y = 0;


        if (Hero->hp <= 0)
            return 0;
        else
            return 1;
    }
    return 1;
}
int can_go(int px, int py)
{

    if (px < 1 || px > 5 || py < 1 || py > 5 || visited[px][py] == 1) return 0;
    return 1;
}
int dfs(int x, int y, Obj Hero, Mon mon)
{
    Hero.x = x;
    Hero.y = y;

    enc_id = encounter(Hero, mon);
    if (enc_id != NULL)
    {
        if (!battle(&Hero, enc_id))
        {
            return 0;
        }
    }

    if (x == 5 && y == 5)
        return 1;

    for (int i = 0; i < 4; i++)
    {
        if (can_go(x + tox[i], y + toy[i]))
        {
            visited[x + tox[i]][y + toy[i]] = 1;
            if (dfs(x + tox[i], y + toy[i], Hero, mon))
            {
                return 1;
            }
            visited[x + tox[i]][y + toy[i]] = 0;
        }
    }
    return 0;
}

int main(void)
{
    Obj Hero;
    Mon mon;
    scanf("%d %d %d", &Hero.hp, &Hero.atk, &k);
    for (int i = 0; i < k; i++) {
        scanf("%d%d%d%d", &mon.m[i].hp, &mon.m[i].atk, &mon.m[i].x, &mon.m[i].y);
    }

    if (dfs(1, 1, Hero, mon)) printf("HEIR OF FIRE DESTROYED\n");
    else printf("YOU DIED\n");
}
close fullscreen
Login or Register to edit or fork this paste. It's free.