3135 - I2P(I)2024_Yang_hw10 Scoreboard

Time

2024/11/25 17:20:00 2024/12/03 18:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
13398 Two-Phase Sorting 2
14534 Super Cats

13398 - Two-Phase Sorting 2   

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 a string V, and N strings of length 6, you need to sort the strings internally according to the order of the string V, and then sort the N strings in dictionary order. All strings contain only lower-case letters.

 

For example:

N = 2

S1 = abcabc, S2 = ababab

V = cbadefghijklmnopqrstuvwxyz

Internally sorted string: S1 = ccbbaa, S2 = bbbaaa

The sorted string after sorting: bbbaaa ccbbaa

Input

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

The second line contains a string V

The following line contains N strings S1 ~ SN

 

testcase:

(3/6) 1 <= N <= 100, V = abcdefghijklmnopqrstuvwxyz

(3/6) 1 <= <= 100, V = the permutation of a~z

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




14534 - Super Cats   

Description

The Cat Kingdom is under attack by monsters from another dimension. To defend their homeland, warriors of various cat tribes have gathered to repel the invaders.

Your task is to simulate the battle on a 3 × 5 battlefield, managing the summoning of cat warriors and the invasion of monsters, and calculating the outcome of each second based on specific rules.

This is a partial judge problem, please trace the code and check the following description.

main.c

The main.c file handles the simulation of a 3 × 5 battlefield where cats and monsters interact over a given period. It begins by reading the details of all cat tribes, including their name, attack power, and attack speed.

For each time step, it processes events such as summoning new cats or introducing monsters.

When a cat is summoned, the program places it on the battlefield if space is available, or output a message if the battlefield is full.

If two cats of the same type and level are present, they merge into a higher-level cat. Monsters are also introduced with specific names and health points.

At each time step, the program calculates the total attack power of the cats and applies it to the first monster.

If a monster’s health reaches zero, it is removed. The program outputs the battlefield state for each second.

#include <stdio.h>
#include "function.h"

#define TABLE_ROW 3
#define TABLE_COLUMN 5
#define MAX_CAT_TYPE 5
#define MAX_MONSTER_NUM 100
Table *table[TABLE_ROW][TABLE_COLUMN];
Cat *cat[MAX_CAT_TYPE];
Monster *monster[MAX_MONSTER_NUM];
int catType, gameOverTime;

int eventType = 0, monsterCount = 0,newMonsterCount = 0;

int main() {
    scanf("%d", &catType);
    for(int i=0; i<catType; i++) cat[i] = newCatType();
    scanf("%d", &gameOverTime);
    for(int i=1; i<=gameOverTime; i++){
        printf("Time %d:\n",i);
        scanf("%d",&eventType);
        if(eventType == 1){
            int placed = 0;
            for(int j=0; j<TABLE_ROW*TABLE_COLUMN; j++){
                int x = j / TABLE_COLUMN;
                int y = j % TABLE_COLUMN;
                if(table[x][y] == NULL){
                    table[x][y] = newCat(cat);
                    printf("A new %s is summon to (%d,%d).\n",table[x][y]->cat->catName, x, y);
                    placed = 1;
                    break;
                }
            }
            if (!placed) printf("No space to summon a new cat.\n");
            for(int j=0; j<TABLE_ROW*TABLE_COLUMN; j++){
                int x1 = j / TABLE_COLUMN;
                int y1 = j % TABLE_COLUMN;
                for(int k=0; k<TABLE_ROW*TABLE_COLUMN; k++){
                    if(j == k) continue;
                    int x2 = k / TABLE_COLUMN;
                    int y2 = k % TABLE_COLUMN;
                    if(table[x1][y1] != NULL && table[x2][y2] != NULL){
                        if(table[x1][y1]->cat->catType == table[x2][y2]->cat->catType && table[x1][y1]->catLevel == table[x2][y2]->catLevel){
                            table[x1][y1]->catLevel++;
                            table[x2][y2] = deleteCat(table[x2][y2]);
                            printf("The cat located at (%d, %d) and the cat located at (%d, %d) have merged and leveled up.\n", x1, y1, x2, y2);
                            printf("The new %s is now located at (%d, %d) and has reached level %d.\n", table[x1][y1]->cat->catName, x1, y1, table[x1][y1]->catLevel);
                            k = -1;
                        }
                    }
                }
            }
        }
        else if(eventType == -1){
            monster[newMonsterCount] = newMonster();
            printf("New monster %s (HP : %d)\n", monster[newMonsterCount]->monsterName, monster[newMonsterCount]->hp);
            newMonsterCount++;
        }
        int attackSum = getAttackSum(table,i);
        if(monsterCount<newMonsterCount && monster[monsterCount] != NULL){
            monster[monsterCount]->hp -= attackSum;
            if(monster[monsterCount]->hp <= 0){
                printf("Monster %s is dead.\n", monster[monsterCount]->monsterName);
                monster[monsterCount] = deleteMonster(monster[monsterCount]);
                monsterCount++;
            }
        }
    }
}

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, and attack speed.
    • The name string also requires memory allocation.
  • Table* newCat(Cat **catTypes)
    • A function that reads the input for the type of cat to summon, allocates memory for the Table struct, and returns it.
    • The Table struct includes a pointer to the cat and initializes its level to 0.
    • The cat's data (name, attack, speed, and type) is copied from the catTypes array.
    • The cat’s name string also needs memory allocation.
  • Table* deleteCat(Table *table)
    • A function that frees the memory associated with a cat on the battlefield and returns NULL.
    • It deallocates the memory for the cat's name, the cat itself, and the table cell.(Use free())
  • Monster* newMonster():
    • A function that reads the input for a new monster, allocates memory for the Monster struct, and returns it.
    • The function reads the monster's name and health points.
    • The monster’s name string also needs memory allocation.
  • int getAttackSum(Table *table[][5], int currentTime)
    • The function calculates the total attack power of all cats on the battlefield at a specific moment in time. It works by iterating over every cell in the 3 × 5 grid representing the battlefield.
    • For each cell, if a cat is present, the function determines whether the cat's attack is triggered at the given time by checking if the current time is divisible by the cat's attack speed.If the conditions are met, the function calculates the contribution of that cat to the total attack power.
    • The base attack power of the cat is scaled by a factor based on the cat's level, specifically catLevel.
    • By the end of the iteration, the function has accumulated the total attack power of all cats that are active at the specified time,and then returns this value.
  • Monster* deleteMonster(Monster *monster):
    • A function that frees the memory associated with a monster and returns NULL.
    • It deallocates the memory for the monster's name and the struct itself.(Use free())
#ifndef __FUNCTION_H__
#define __FUNCTION_H__

typedef struct {
    char *catName;
    int attack;
    int speed;
    int catType;
} Cat;

typedef struct {
    int catLevel;
    Cat *cat;
} Table;

typedef struct {
    char *monsterName;
    int hp;
} Monster;

Cat* newCatType();

Table* newCat(Cat **catTypes);

Table* deleteCat(Table *table);

Monster* newMonster();

int getAttackSum(Table *table[][5], int currentTime);

Monster* deleteMonster(Monster *monster);

#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 tribe's name (a string with a maximum length of 20).
  • Atk : The attack power (a positive integer).
  • spd : The attack speed (a positive integer, representing the number of seconds between attacks).

The next one line containing a positive integer T, the duration of the simulation (in seconds).

The next T lines, one for each second, describe the event occurring at that time:

  • 1 tp : Summon a cat from tribe tp (0-based index).
  • -1 Smon hp : A monster named Smon with hp health points enters the battlefield.

Constraints

  • 1 ≤ N ≤ 5
  • 1 ≤ |Scat |,|Smon | ≤ 20
  • 1 ≤ Atk,hp ≤ 105
  • 1 ≤ spd ≤ 10
  • 1 ≤ T ≤ 100
  • 0 ≤ tp ≤ N-1

Subtasks

  • Testcases 1~2: N = 1
  • Testcases 3~4: There will be no monsters appearing.
  • Testcases 5~6: No cats will be summoned.
  • Testcases 7~8: No additional restrictions.

Output

(This part is already implemented in main.c)

For each second, first output : Time [CurrentTime]:

Then output the events and battlefield status according to the following rules:

  • If there is space on the battlefield, place the cat and output its tribe and position:
    • A new [Scat] is summon to ([x],[y]).
  • If no space is available, output:
    • No space to summon a new cat.
  • If two cats of the same tribe and level are present, they merge, upgrading their level:
    • The cat located at ([x1],[y1]) and the cat located at ([x2],[y2]) have merged and leveled up.
    • The new [Scat] is now located at ([x1],[y1]) and has reached level [level].
  • When a monster appears, output its name and health points:
    • New monster [Smon] (HP : [hp])
  • Calculate the total attack damage dealt by all cats on the battlefield and apply it to the first monster. If a monster's health drops to zero or below, output:
    • Monster [Smon] is dead.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14534.c

Partial Judge Header

14534.h

Tags




Discuss