18.03.17 作业A:魔兽世界之一:备战

描述

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

两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值、攻击力这三种属性。 

双方的武士编号都是从1开始计算。红方制造出来的第n个武士,编号就是n。同样,蓝方制造出来的第n个武士,编号也是n。 

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

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

红方司令部按照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武士。(为简单起见,不考虑单词的复数形式)注意,每制造出一个新的武士,都要输出此时司令部里共有多少个该种武士。

2) 司令部停止制造武士
输出样例: 010 red headquarter stops making warriors
表示在10点整,红方司令部停止制造武士

输出事件时: 

首先按时间顺序输出; 

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

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

每组测试数据共两行。 

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

第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于10000。输出对每组测试数据,要求输出从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
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
  1 #include <iostream>
  2 #include <cstdio>
  3 #include <algorithm>
  4 #include <stdlib.h>
  5 
  6 using namespace std;
  7 
  8 class dragon
  9 {
 10 public:
 11     int str;
 12     int totalnum_r;
 13     int totalnum_b;
 14     int total;
 15 };
 16 class iceman
 17 {
 18 public:
 19     int str;
 20     int totalnum_r;
 21     int totalnum_b;
 22     int total;
 23 };
 24 class ninja
 25 {
 26 public:
 27     int str;
 28     int totalnum_r;
 29     int totalnum_b;
 30     int total;
 31 };
 32 class wolf
 33 {
 34 public:
 35     int str;
 36     int totalnum_r;
 37     int totalnum_b;
 38     int total;
 39 };
 40 class lion
 41 {
 42 public:
 43     int str;
 44     int totalnum_r;
 45     int totalnum_b;
 46     int total;
 47 };
 48 class red
 49 {
 50 public:
 51     int warrior;
 52 };
 53 class blue
 54 {
 55 public:
 56     int warrior;
 57 };
 58 
 59 //red:i,l,w,n,d
 60 //blue:l,d,n,i,w
 61 //生命元根据生成武士的生命值减少
 62 //先红后蓝
 63 int main()
 64 {
 65     int n;//case数
 66     cin >> n;
 67     for (int c = 1; c <= n; c++) {
 68         int M;//每个司令部的初始生命元数量
 69         int r_n, b_n, r_w = 1, b_w = 1;//红蓝双方的生命元数,红蓝双方要制造的武士类型
 70         dragon d;
 71         ninja n;
 72         iceman i;
 73         lion l;
 74         wolf w;
 75         red r;
 76         blue b;
 77         d.totalnum_r = 0, d.totalnum_b = 0, d.total = 0;
 78         i.totalnum_r = 0, i.totalnum_b = 0, i.total = 0;
 79         n.totalnum_r = 0, n.totalnum_b = 0, n.total = 0;
 80         l.totalnum_r = 0, l.totalnum_b = 0, l.total = 0;
 81         w.totalnum_r = 0, w.totalnum_b = 0, w.total = 0;
 82         r.warrior = 0, b.warrior = 0;
 83         cin >> M >> d.str >> n.str >> i.str >> l.str >> w.str;
 84         int strmin = min(d.str, i.str);
 85         strmin = min(strmin, n.str);
 86         strmin = min(strmin, l.str);
 87         strmin = min(strmin, w.str);
 88         r_n = M, b_n = M;
 89         int t = 0;
 90         int flag_r = 1, flag_b = 1;//判断是否已停产的条件
 91         printf("Case:%d\n", c);
 92         while (r_n >= strmin|| b_n >= strmin) {
 93             if (r_n < strmin&&flag_r)
 94             {
 95                 flag_r = 0;
 96                 printf("%03d red headquarter stops making warriors\n", t);
 97             }
 98             int rcons = 0, bcons = 0;//红蓝双方这次要消耗的生命元数
 99             while (r_n >= strmin)
100             {
101                 switch (r_w)
102                 {
103                 case 1:rcons = i.str; break;
104                 case 2:rcons = l.str; break;
105                 case 3:rcons = w.str; break;
106                 case 4:rcons = n.str; break;
107                 case 5:rcons = d.str; break;
108                 }
109                 if (r_n < rcons) {
110                     r_w++;
111                     if (r_w > 5)
112                         r_w -= 5;
113                     continue;
114                 }
115                     r_n -= rcons;
116                     printf("%03d red ", t);
117                     switch (r_w)
118                     {
119                     case 1: {i.totalnum_r++; r.warrior++; printf("iceman %d born with strength %d,%d iceman", r.warrior, i.str, i.totalnum_r); break; }
120                     case 2: {l.totalnum_r++; r.warrior++; printf("lion %d born with strength %d,%d lion", r.warrior, l.str, l.totalnum_r); break; }
121                     case 3: {w.totalnum_r++; r.warrior ++; printf("wolf %d born with strength %d,%d wolf", r.warrior, w.str, w.totalnum_r); break; }
122                     case 4: {n.totalnum_r++; r.warrior++; printf("ninja %d born with strength %d,%d ninja", r.warrior, n.str, n.totalnum_r); break; }
123                     case 5: {d.totalnum_r++; r.warrior++; printf("dragon %d born with strength %d,%d dragon", r.warrior, d.str, d.totalnum_r); break; }
124                     }
125                     printf(" in red headquarter\n");
126                     break;
127             }
128             if (b_n < strmin&&flag_b)
129             {
130                 flag_b = 0;
131                 printf("%03d blue headquarter stops making warriors\n", t);
132             }
133             while (b_n >= strmin)
134             {
135                 switch (b_w)
136                 {
137                 case 1:bcons = l.str; break;
138                 case 2:bcons = d.str; break;
139                 case 3:bcons = n.str; break;
140                 case 4:bcons = i.str; break;
141                 case 5:bcons = w.str; break;
142                 }
143                 if (b_n < bcons) {
144                     b_w++;
145                     if (b_w > 5)
146                         b_w -= 5;
147                     continue;
148                 }
149                     b_n -= bcons;
150                     printf("%03d blue ", t);
151                     switch (b_w)
152                     {
153                     case 1: {l.totalnum_b++; b.warrior++;  printf("lion %d born with strength %d,%d lion", b.warrior, l.str, l.totalnum_b); break; }
154                     case 2: {d.totalnum_b++; b.warrior++; printf("dragon %d born with strength %d,%d dragon", b.warrior, d.str, d.totalnum_b); break; }
155                     case 3: {n.totalnum_b++; b.warrior++; printf("ninja %d born with strength %d,%d ninja", b.warrior, n.str, n.totalnum_b); break; }
156                     case 4: {i.totalnum_b++; b.warrior++; printf("iceman %d born with strength %d,%d iceman", b.warrior, i.str, i.totalnum_b); break; }
157                     case 5: {w.totalnum_b++; b.warrior++; printf("wolf %d born with strength %d,%d wolf", b.warrior, w.str, w.totalnum_b); break; }
158                     }
159                     printf(" in blue headquarter\n");
160                     break;
161             }
162             t++;
163             r_w++,b_w++;
164             if (r_w > 5)
165                 r_w -= 5;
166             if (b_w>5)
167                 b_w -= 5;
168         }
169         if (flag_r)
170             printf("%03d red headquarter stops making warriors\n", t);
171         if (flag_b)
172             printf("%03d blue headquarter stops making warriors\n", t);
173     }
174         return 0;
175     }
View Code

g老师的题都很有意思呢……

一开始以为魔兽系列都很虐就没敢做,而且今天做的时候以为会用到各种类想也没想就把所有类都直接写上去了

结果发现不用类会更短&&更好做:)

但也考虑到系列后期需要就没有改动

但是没错,在这道题中这些类都是毫无意义的:)

所以非常长+繁琐///

posted @ 2018-03-17 23:03  TobicYAL  阅读(606)  评论(0编辑  收藏  举报