魔兽世界1

Description:

There are two tribes in the world. The headquarter of Red tribe is in the west of the world and the Blue tribe’s is in the east. There are n cities between these two headquarters, denoted as:

Red headquarter -City 1 - City 2 - City 3, … - City n -Blue headquarter


Headquarters can create warriors. There are five types of warriorsin total. They are dragon, ninja,iceman, lion, wolf. Every warrior has three properties: Number, strength, Attack.


In each headquarter, the Number of warriors starts from 1. For example, The Number of the warrioris n, if he was the Nth to be made in Red headquarter. Similarly, If the Blue headquarter made the Nth warrior, his Number is n.


Every warrior is born with a strength.


In every integral point, each headquarter will create a new warrior.

The order of warrior creation in Red headquarter: iceman, lion, wolf, ninja, dragon

The order of warrior creation in Blue headquarter: lion, dragon, ninja, iceman, wolf


The creation of a warrior will consume the strength of the headquarter. For example, if the Blue headquarter made a warrior with m strength, then the strength of the Blue headquarter will reduce m.


If the headquarter doesn’t have the enough strength to create the present warrior,it will move to the warrior of next type. When the headquarter cannot create any type of warriors, it stops.


Requirement:

When the time and the initial strength of two headquarters are given, you need to list every event of two headquarters after 0:00.

There are two types of events:

(1) A warrior is born

Sample: 004 blue lion 5 bornwith strength 5,2 lion in red headquarter

It means in 4:00, a lion was born in red headquarter, his Number is 5 and strength is 5. Now, there are 2 lions in the red headquarter.(notice: do not use plural form, for example it is 2 lionnot 2 lions)

(2) headquarter stops making warriors

Sample: 010 red headquarter stops making warriors

It means in 10:00, the red headquarter stops making warriors


When you list the events, it should output in chronological order. If some events happen at the same time, first output the event in the Red headquarter then Blue headquarter.


Input
The first line is an integer, it means the number of test cases.
For every case:
The first line is an integer M, it means the initial strength of the two headquarters.
The second line are the strength of dragon, ninja, iceman, lion, wolf.


Output
For every case:
You need to output every event starting from 0:00 until the two headquarters stop creating warriors.
First output “Case:n”, n is the number of the case, n is starting from 1 (The total number of cases is given in the first line of input).
Every event start with the timing, the timing is three-digit number (there is no 24 hours limited).


Example Input

1
20
3 4 5 6 7


Example Output

Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
000 blue lion 1 born with strength 6,1 lion in blue headquarter
001 red lion 2 born with strength 6,1 lion in red headquarter
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
002 red wolf 3 born with strength 7,1 wolf in red headquarter
002 blue ninja 3 born with strength 4,1 ninja in blue headquarter
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
004 blue headquarter stops making warriors




Solution:

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
const int WARRIOR_NUM = 5;

class Headquarter;

class Warrior {
private:
    Headquarter * pHeadquarter;
    int kindNum;
    int num;
public:
    static string names[WARRIOR_NUM];
    static int warriorLifeValues[WARRIOR_NUM];
    Warrior(Headquarter * pHeadquarter, int kindNum, int num);
    void PrintResult(int nTime);
};

class Headquarter {
private:
    bool stopped;
    int color;
    int curIndex;
    int HeadquarterLifeValue;
    int totalWarriorNum;
    int warriorNum[WARRIOR_NUM];
    Warrior * pWarriors[1000];
public:
    friend  class Warrior;
    static int RedOrder[WARRIOR_NUM];
    static int BlueOrder[WARRIOR_NUM];
    Headquarter(int color, int HeadquarterLifeValue);
    ~Headquarter();
    int Produce(int nTime);
    string getColor();
};

Warrior::Warrior(Headquarter * pHeadquarter, int kindNum, int num) {
    this->kindNum = kindNum;
    this->num = num;
    this->pHeadquarter = pHeadquarter;
}

void Warrior::PrintResult(int nTime) {
    string color = pHeadquarter->getColor();
    printf("%03d %s %s %d born with strength %d, %d %s in %s headquarter.\n", 
        nTime, color.c_str(), names[kindNum].c_str(), nTime + 1, warriorLifeValues[kindNum], 
        pHeadquarter->warriorNum[kindNum], names[kindNum].c_str(), color.c_str());
}

Headquarter::Headquarter(int color, int HeadquarterLifeValue) {
    this->color = color;
    this->HeadquarterLifeValue = HeadquarterLifeValue;
    stopped = false;
    curIndex = 0;
    totalWarriorNum = 0;
    for (int i = 0; i < WARRIOR_NUM; ++i)
        warriorNum[i] = 0;
}

Headquarter::~Headquarter() {
    for (int i = 0; i < totalWarriorNum; ++i)
        delete pWarriors[i];
}

int Headquarter::Produce(int nTime) {
    int curLifeValue;
    int curKind;
    int * curOrder;
    if (stopped)
        return 0;
    if (color == 0)
        curOrder = Headquarter::RedOrder;
    else if (color == 1)
        curOrder = Headquarter::BlueOrder;
    curLifeValue = Warrior::warriorLifeValues[curOrder[curIndex]];  // before check next
    int searchTimes = 0;
    while (curLifeValue > HeadquarterLifeValue && searchTimes < WARRIOR_NUM) {
            curIndex = (curIndex + 1) % WARRIOR_NUM;
            searchTimes++;
    }
    curLifeValue = Warrior::warriorLifeValues[curOrder[curIndex]];  // after check next
    if (curLifeValue > HeadquarterLifeValue) {
        stopped = true;
        if (color == 0)
            printf("%03d red headquarter stops making warriors.\n", nTime);
        else if (color == 1)
            printf("%03d blue headquarter stopes making warriors.\n", nTime);
        return 0;
    }
    curKind = curOrder[curIndex];
    HeadquarterLifeValue -= curLifeValue;
    warriorNum[curKind]++;
    pWarriors[totalWarriorNum] = new Warrior(this, curKind, totalWarriorNum + 1);
    pWarriors[totalWarriorNum]->PrintResult(nTime);
    curIndex = (curIndex + 1) % WARRIOR_NUM;
    return 1;
}

string Headquarter::getColor() {
    if (color == 0)
        return "red";
    else if (color == 1)
        return "blue";
}

string Warrior::names[WARRIOR_NUM] = {"dargon", "ninja", "iceman", "lion", "wolf"};
int Warrior::warriorLifeValues[WARRIOR_NUM];
int Headquarter::RedOrder[WARRIOR_NUM] = {2, 3, 4, 1, 0};
int Headquarter::BlueOrder[WARRIOR_NUM] = {3, 0, 1, 2, 4};

int main() {
    int t, m;
    scanf("%d", &t);
    int caseNum = 0;
    while (t--) {
        scanf("%d", &m);
        for (int i = 0; i < WARRIOR_NUM; ++i)
            scanf("%d", & Warrior::warriorLifeValues[i]);
        printf("Case:%d\n", caseNum++);
        Headquarter red(0, m);
        Headquarter blue(1, m);
        int nTime = 0;
        while (true) {
            int tmp1 = red.Produce(nTime);
            int tmp2 = blue.Produce(nTime);
            if (tmp1 ==0 && tmp2 == 0)
                break;
            nTime++;
        }
    }
    return 0;
}




/

猜你喜欢

转载自www.cnblogs.com/massquantity/p/12198590.html