魔兽世界之二:装备

A:魔兽世界之二:装备

  • 查看
  • 提交
  • 统计
  • 提问
总时间限制:1000ms内存限制:65536kB描述

魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。

红司令部,City 1,City 2,……,City n,蓝司令部

两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值这两种属性。
有的武士可以拥有武器。武器有三种,sword, bomb,和arrow,编号分别为0,1,2。
双方的武士编号都是从1开始计算。红方制造出来的第 n 个武士,编号就是n。同样,蓝方制造出来的第 n 个武士,编号也是n。

不同的武士有不同的特点。
dragon 可以拥有一件武器。编号为n的dragon降生时即获得编号为 n%3 的武器。dragon还有“士气”这个属性,是个浮点数,其值为它降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量。
ninjia可以拥有两件武器。编号为n的ninjia降生时即获得编号为 n%3 和 (n+1)%3的武器。
iceman有一件武器。编号为n的iceman降生时即获得编号为 n%3 的武器。
lion 有“忠诚度”这个属性,其值等于它降生后其司令部剩余生命元的数目。
wolf没特点。
请注意,在以后的题目里,武士的士气,生命值,忠诚度在其生存期间都可能发生变化,都有作用,武士手中的武器随着使用攻击力也会发生变化。

武士在刚降生的时候有一个生命值。

在每个整点,双方的司令部中各有一个武士降生。

红方司令部按照 iceman、lion、wolf、ninja、dragon 的顺序循环制造武士。

蓝方司令部按照 lion、dragon、ninja、iceman、wolf 的顺序循环制造武士。

制造武士需要生命元。

制造一个初始生命值为 m 的武士,司令部中的生命元就要减少 m 个。

如果司令部中的生命元不足以制造某个按顺序应该制造的武士,那么司令部就试图制造下一个。如果所有武士都不能制造了,则司令部停止制造武士。
给定一个时间,和双方司令部的初始生命元数目,要求你将从0点0分开始到双方司令部停止制造武士为止的所有事件按顺序输出。
一共有两种事件,其对应的输出样例如下:

1) 武士降生
输出样例: 004 blue lion 5 born with strength 5,2 lion in red headquarter
表示在 4点整,编号为5的蓝魔lion武士降生,它降生时生命值为5,降生后蓝魔司令部里共有2个lion武士。(为简单起见,不考虑单词的复数形式)注意,每制造出一个新的武士,都要输出此时司令部里共有多少个该种武士。
如果造出的是dragon,那么还要输出一行,例:
It has a arrow,and it's morale is 23.34
表示该dragon降生时得到了arrow,其士气是23.34(为简单起见,本题中arrow前面的冠词用a,不用an,士气精确到小数点后面2位,四舍五入)
如果造出的是ninjia,那么还要输出一行,例:
It has a bomb and a arrow
表示该ninjia降生时得到了bomb和arrow。
如果造出的是iceman,那么还要输出一行,例:
It has a sword
表示该iceman降生时得到了sword。
如果造出的是lion,那么还要输出一行,例:
It's loyalty is 24
表示该lion降生时的忠诚度是24。
2) 司令部停止制造武士
输出样例: 010 red headquarter stops making warriors
表示在 10点整,红方司令部停止制造武士

输出事件时:

首先按时间顺序输出;

同一时间发生的事件,先输出红司令部的,再输出蓝司令部的。

输入第一行是一个整数,代表测试数据组数。

每组测试数据共两行。

第一行,一个整数M。其含义为: 每个司令部一开始都有M个生命元( 1 <= M <= 1000)

第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于100输出对每组测试数据,要求输出从0时0分开始,到双方司令部都停止制造武士为止的所有事件。
对每组测试数据,首先输出“Case:n" n是测试数据的编号,从1开始
接下来按恰当的顺序和格式输出所有事件。每个事件都以事件发生的时间开头,时间以小时为单位,有三位。样例输入
1
20
3 4 5 6 7
样例输出
Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
It has a bomb
000 blue lion 1 born with strength 6,1 lion in blue headquarter
It's loyalty is 14
001 red lion 2 born with strength 6,1 lion in red headquarter
It's loyalty is 9
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
It has a arrow,and it's morale is 3.67
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
It has a sword and a bomb
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
It has a bomb
004 blue headquarter stops making warriors

#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
int lifetomake[5] = {0};
const char* equip[3] = {"sword", "bomb","arrow"};
int t = 0;
const char* monname[5] = {"dragon", "ninja", "iceman", "lion", "wolf"};

class monster
{
public:
    int id, life;
    char* belong;
    monster(int x, int y, const char* s)
    {
        id = x;
        life = y;
        if( s)
        {
            belong = new char[strlen(s) + 1];
            strcpy(belong,s);
        }
        else
            belong = NULL;
        return;
    }
};

class dragon:public monster
{
    int equipment;
    double courage;
public:
    dragon(int &m_, int id_, int life_,int num_, const char* s): monster(id_, life_, s)
    {
        equipment = id % 3;
        courage = double(m_)/double(lifetomake[0]);
        cout  << setw(3) << setfill('0') <<t<<" " <<belong <<" " << monname[0]<<" " << id<<" born with strength " << life <<",";
        cout << num_ <<" " << monname[0] << " in " << belong <<" headquarter" << endl;
        cout << "It has a " << equip[equipment] <<",and it's morale is " <<fixed<<setprecision(2)<< courage <<endl;
    }
};
class ninjia:public monster
{
    int equipment1, equipment2;
public:
    ninjia(int &m_, int id_, int life_,int num_,  const char* s):monster(id_,life_,s)
    {
        equipment1 = id % 3;
        equipment2 = (id + 1) % 3;
        cout  << setw(3) << setfill('0') <<  t<<" " <<belong <<" " << monname[1] << " " << id<<" born with strength " << life <<",";
        cout << num_ <<" " << monname[1] << " in " << belong <<" headquarter" << endl;
        cout << "It has a " << equip[equipment1] <<" and a " << equip[equipment2]<<endl;
    }
};

class iceman:public monster
{
    int equipment;
public:
    iceman(int &m_, int id_, int life_, int num_, const char*s):monster(id_,life_,s)
    {
        equipment = id % 3;
        cout  << setw(3) << setfill('0') <<  t<<" " <<belong <<" " << monname[2] <<" " << id<<" born with strength " << life <<",";
        cout << num_<<" "  << monname[2] << " in " << belong <<" headquarter" << endl;
        cout << "It has a " << equip[equipment]<<endl;
    }
};
class lion:public monster
{
    int loyalty;
public:
    lion(int &m_,int id_,int life_, int num_, const char*s):monster(id_, life_, s)
    {
        loyalty = m_;
        cout  << setw(3) << setfill('0') <<  t<<" " <<belong <<" " << monname[3] << " " << id<<" born with strength " << life <<",";
        cout << num_<<" "  << monname[3] << " in " << belong <<" headquarter" << endl;
        cout << "It's loyalty is " << loyalty <<endl;
    }
};
class wolf:public monster
{
public:
    wolf(int& m_, int id_, int life_, int num_, const char*s):monster(id_,life_,s)
    {
        cout  << setw(3) << setfill('0') << t<<" " <<belong <<" " << monname[4]<<" "<< id<<" born with strength " << life <<",";
        cout << num_<<" " << monname[4] << " in " << belong <<" headquarter" << endl;
    }
};

class base
{
private:
    int m, productable[5], end, ord[5], step, num[5],sum;
    char* name;
    monster* p[100];
    friend class monster;
public:
    base(int, int, int, int, int, int, const char*);
    void product();
    static void grow(base, base);
    void setname();
    void mon_product(int , int);
};

base::base(int a, int b, int c, int d, int e, int f, const char* g )
{
    m = f;
    sum = 0;
    step = 0;
    name = new char[strlen(g) + 1];
    strcpy(name,g);
    for(int i = 0; i < 5; i++) num[i] = 0;
    ord[0] = a;
    ord[1] = b;
    ord[2] = c;
    ord[3] = d;
    ord[4] = e;
    memset(productable, 0, sizeof(productable));
    end = 0;
    return;
}

void base::mon_product(int x, int y)
{
    switch(x)
    {
    case 0:
        p[y] = new dragon(m, sum, lifetomake[0],num[0], name);
        break;
    case 1:
        p[y] = new ninjia(m,sum,lifetomake[1],num[1], name);
        break;
    case 2:
        p[y] = new iceman(m,sum,lifetomake[2],num[2],name);
        break;
    case 3:
        p[y] = new lion(m,sum,lifetomake[3],num[3],name);
        break;
    case 4:
        p[y] = new wolf(m,sum,lifetomake[4],num[4],name);
        break;
    default:
        break;
    }
    return;
}

void base::product()
{
    if(end) return;
    if(productable[0] + productable[1] + productable[2] + productable[3] + productable[4] == 5)
    {
        cout << setw(3) << setfill('0') << t <<" " << name << " headquarter stops making warriors" << endl;
        end = 1;
        return;
    }
    if(!productable[ord[step]] && m >= lifetomake[ord[step]])
    {
        num[ord[step]]++;
        m -= lifetomake[ord[step]];
        sum++;
        mon_product(ord[step], sum);
        return;
    }
    else
    {
        productable[ord[step]] = 1;
        step = (step + 1) % 5;
        product();
        return;
    }
}

void base::grow(base a, base b)
{
    while(true)
    {
        a.product();
        a.step = (a.step + 1) % 5;
        b.product();
        b.step = (b.step + 1) % 5;
        t++;
        if(a.end + b.end == 2) break;
    }
    return;
}

int main()
{
    int n = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        t = 0;
        cout << "Case:" << i << endl;
        int tep = 0;
        cin >> tep;
        for(int j = 0; j < 5; j++)
            cin >> lifetomake[j];
        base red(2, 3, 4, 1, 0, tep, "red"), blue(3, 0, 1, 2, 4, tep, "blue");
        base::grow(red, blue);
    }
    return 0;
}




你可能感兴趣的:(OpenJudge)