The Cat Kingdom, after withstanding several waves of attacks from monsters of another dimension, now faces their ultimate challenge: the leader of these monsters, RedCapeFlyingCat.
This fearsome adversary, a flying cat adorned with a red scarf, has brought the battle to its final stage. To defend their homeland, warriors of various cat tribes have gathered once again. However, their resources and equipment will only last for T units of time. The warriors must find a way to defeat RedCapeFlyingCat within the remaining time.
Your task is to simulate the battle on the battlefield and determine the outcome of this epic confrontation.
This is a partial judge problem, please trace the code and check the following description.
main.c
The main.c file orchestrates the simulation, handling interactions between cat warriors and RedCapeFlyingCat.
The simulation starts by reading the details of all participating cat tribes, including their attack power, attack speed, and level-up requirements.
A single monster, RedCapeFlyingCat, is introduced with its health points and unique abilities.
At each time step, cats are summoned to the battlefield, where they gain levels over time and attack the monster.
The monster counters with two powerful skills that disrupt the cats' efforts.
If RedCapeFlyingCat 's health drops to zero or below within T seconds, the cats win.
Otherwise, RedCapeFlyingCat triumphs, and the Cat Kingdom falls.
#include <stdio.h>
#include "function.h"
#define MAX_CAT_TYPE 5
#define MAX_CAT_NUM 100
Battlefield *battlefield[MAX_CAT_NUM];
Cat *cat[MAX_CAT_TYPE];
Monster *monster;
int catType;
int gameOverTime;
int main() {
scanf("%d", &catType);
for(int i=0; i<catType; i++) cat[i] = newCatType();
monster = buildMonster();
scanf("%d", &gameOverTime);
for(int i=1; i<=gameOverTime; i++){
for(int j=0; j<MAX_CAT_NUM; j++){
if(battlefield[j] == NULL){
battlefield[j] = newCat(cat,i);
break;
}
}
if(i % monster->skill_1_CooldownTime == 0){
skill_1(battlefield, monster, i);
}
if(i % monster->skill_2_CooldownTime == 0){
skill_2(battlefield, monster, i);
}
for(int j=0; j<MAX_CAT_NUM; j++){
if(battlefield[j] != NULL){
if(battlefield[j]->catLevel <= 0){
battlefield[j] = deleteCat(battlefield[j]);
}
else if(i % battlefield[j]->cat->attackSpeed == 0){
monster->hp -= battlefield[j]->cat->attackPower*battlefield[j]->catLevel;
}
}
}
for(int j=0; j<MAX_CAT_NUM; j++){
if(battlefield[j] != NULL){
int AppearanceTime = battlefield[j]->catAppearanceTime;
int levelUpTime = battlefield[j]->cat->levelUpTime;
if(i != AppearanceTime && (i - AppearanceTime) % levelUpTime == 0){
battlefield[j]->catLevel += 1;
}
}
}
if(monster->hp <= 0){
printf("[Time] : %d\n",i);
printf("The Cats win!\n");
break;
}
if(i % 3 == 0){
printf("[Time] : %d\n",i);
printf("[RedCapeFlyingCat remaining hp] : %d\n",monster->hp);
printf("[Cats information] : \n");
int catCount = 0;
for(int j=0; j<MAX_CAT_NUM; j++){
if(battlefield[j] != NULL){
catCount++;
printf("%d.[%s] Level = %d\n",catCount,battlefield[j]->cat->catName,battlefield[j]->catLevel);
}
}
printf("==================================================\n");
}
}
}
function.h
Cat* newCatType()
:
Cat
struct, and returns it.Monster* buildMonster()
:
Monster
struct, and returns it.Battlefield* newCat(Cat **catTypes, int currentTime)
:
Battlefield
struct, and returns it.catTypes
array, and its name string also requires memory allocation.void skill_1(Battlefield *battlefield[], Monster *monster)
:
void skill_2(Battlefield *battlefield[], Monster *monster)
:
Battlefield* deleteCat(Battlefield *battlefield)
:
NULL
.free()
)
#ifndef __FUNCTION_H__
#define __FUNCTION_H__
typedef struct {
char *catName;
int attackPower;
int attackSpeed;
int levelUpTime;
} Cat;
typedef struct {
int catLevel;
int catAppearanceTime;
Cat *cat;
} Battlefield;
typedef struct {
int hp;
int skill_1_CooldownTime;
int skill_2_CooldownTime;
int skill_2_Duration;
} Monster;
Cat* newCatType();
Monster* buildMonster();
Battlefield* newCat(Cat **catTypes, int currentTime);
void skill_1(Battlefield *battlefield[], Monster *monster, int currentTime);
void skill_2(Battlefield *battlefield[], Monster *monster, int currentTime);
Battlefield* deleteCat(Battlefield *battlefield);
#endif
The first line contains an integer N (number of cat tribes).
The next N lines each describe a cat tribe with:
The next line contains attributes for RedCapeFlyingCat :
The next line contains a positive integer T (the duration of the simulation).
The next line contains T numbers a1 , a2 , ... , aT , each representing the cat type to summon at the corresponding time step.
(This part is already implemented in main.c)
Every 3 time steps, the following details are printed:
[Time] : <time>
[RedCapeFlyingCat remaining hp] : <hp>
[Cats information]
.<index>.[<catName>] Level = <catLevel>
.==================================================
to distinguish between outputs for different time steps.If RedCapeFlyingCat 's HP falls to 0 or below at any time step, print the following and terminate the simulation:
[Time] : <time>
The Cats win!