3140 - I2P(I)2024_Yang_lab10 Scoreboard

Time

2024/12/03 22:00:00 2024/12/03 22:01:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13389 Two-Phase Sorting
14542 Super Cats II

13389 - Two-Phase Sorting   

Description

Denny just learned the sorting method in school.

Sorting once is too easy for him, so the teacher asked a question that needs to be sorted twice to test him.

In this question, you will get N strings of length 6, you need to sort the strings internally according to a ~ z, and then sort the N strings in dictionary order.

 

For example:

N = 2

S1 = abcabc, S2 = ababab

Internally sorted string: S1 = aabbcc, S2 = aaabbb

The sorted string after sorting: aaabbb aabbcc

Input

The first line contains a integer N, the number of strings you need to sort

The following line contains N strings S1 ~ SN

For all testcase:

1 <= N <= 100

Output

The Output contains only one line, the sorted string after sorting.

note: remember to add a '\n' in the end of output

Sample Input  Download

Sample Output  Download

Tags




Discuss




14542 - Super Cats II   

Description

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():
    • A function that reads the input for a cat tribe, allocates memory for the Cat struct, and returns it.
    • The function reads the tribe's name, attack power, attack speed, and level-up time.
    • The name string also requires memory allocation.
  • Monster* buildMonster():
    • A function that reads the input for a monster, allocates memory for the Monster struct, and returns it.
    • The function reads the monster's health points, skill 1 cooldown time, skill 2 cooldown time, and skill 2 duration.
  • Battlefield* newCat(Cat **catTypes, int currentTime) :
    • A function that reads the input for the type of cat to summon, allocates memory for the Battlefield struct, and returns it.
    • The struct includes a pointer to the summoned cat and initializes its level to 1.
    • The cat's data (name, attack power, attack speed, and level-up time) is copied from the catTypes array, and its name string also requires memory allocation.
  • void skill_1(Battlefield *battlefield[], Monster *monster) :
    • A function that implements the monster's first skill.
    • It reduces the level of all cats on the battlefield by 1 and increases the monster's health by 100 for each affected cat.
  • void skill_2(Battlefield *battlefield[], Monster *monster) :
    • A function that implements the monster's second skill.
    • It charms all cats present on the battlefield at the moment the skill is activated, causing their attacks to heal RedCapeFlyingCat instead of damaging it for a limited duration.
    • Cats that are summoned after the skill is activated are not affected by the charm.
    • During the skill's duration, whenever a charmed cat's attack is triggered, its attack power is added to the monster's health instead of reducing it.
    • Once the skill's duration ends, all charmed cats return to their normal state, and their attacks resume dealing damage to the monster.
  • Battlefield* deleteCat(Battlefield *battlefield) :
    • A function that frees the memory associated with a cat on the battlefield and returns NULL.
    • If a cat’s level drops to 0 or below (e.g., due to the effect of skill_1), the cat is considered dead and is removed from the battlefield. 
    • It deallocates the memory for the cat's name, the cat itself, and the battlefield struct. (Use 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

Input

The first line contains an integer N (number of cat tribes).

The next N lines each describe a cat tribe with:

  • Scat : The name of the tribe (string, maximum length of 20).
  • Atk : The attack power (positive integer).
  • Spd : The attack speed (positive integer).
  • LvUp : The time required for the cat to level up (positive integer).

The next line contains attributes for RedCapeFlyingCat :

  • HP : Initial health points.
  • Skill1_CD : Cooldown time for skill 1 (integer).
  • Skill2_CD : Cooldown time for skill 2 (integer).
  • Skill2_Dur : Duration of skill 2’s effect (integer).

The next line contains a positive integer T (the duration of the simulation).

The next line contains T numbers a, a, ... , aT , each representing the cat type to summon at the corresponding time step.

Constraints

  • 1 ≤ N ≤ 5
  • 1 ≤ |Scat | ≤ 20
  • 1 ≤ Atk ≤ 105
  • 1 ≤ HP ≤ 109
  • 1 ≤ Spd ≤ 10
  • 1 ≤ LvUp ≤ 3000
  • 1 ≤ Skill1_CD , Skill2_CD  ≤ 310000
  • 1 ≤ Skill2_Dur Skill2_CD
  • 1 ≤ T ≤ 300000
  • 0 ≤ ai ≤ N-1

Subtasks

  • Testcases 1~3: N = 1 , T ≤ 3000 , Skill1_CD = 5000 , Skill2_CD = 5000 , Skill2_Dur = 4000 
  • Testcases 4~6: T ≤ 3000 , Skill1_CD = 5000 , Skill2_CD = 5000 , Skill2_Dur = 4000 
  • Testcases 7~8: Skill2_CD = 310000 , Skill2_Dur = 300000
  • Testcases 9~10: No additional restrictions.

Output

(This part is already implemented in main.c)

Every 3 time steps, the following details are printed:

  • The current time : [Time] : <time>
  • The remaining HP of RedCapeFlyingCat : [RedCapeFlyingCat remaining hp] : <hp>
  • Information about all cats currently on the battlefield:
    • The first line should output [Cats information].
    • Then, for each cat, display its index (starting from 1), name, and level in the following : <index>.[<catName>] Level = <catLevel>.
  • A separator line ================================================== 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:

  • The current time : [Time] : <time>
  • A victory message : The Cats win!

Sample Input  Download

Sample Output  Download

Partial Judge Code

14542.c

Partial Judge Header

14542.h

Tags




Discuss