TimeLimit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 430 Accepted Submission(s): 102
Problem Description
Magina is surround by hundreds of monsters. Can he survive in T unit times?
Now matter Magina or monster have three attributes(ATI, DEF, HP), but Magina have another attributes (MaxHP). Magina can own some equipments as a hero , there are six kinds of equipment ("Head", "Weapon", "Armor","Shoes", "Trump","Cuff") in this world. Equipment have three attributes (A, D, MH), each standing the value can increase to ATI, DEF and MaxHP of Magina.
To every some kinds of equipment, Magina can only choose one to use. So when he have some kinds of equipments, he will choose the one have the bigger value. The value of equipments define as A*3 + D*2 + MH. If the value of equipments is equal to the one Magina have, he will not choose to change his equipment.







Now describe a fighting between A and B.
We know A hurt B first, the value of harm define as P.
P = MAX(1,(int)((A's ATI - B's DEF) / ( abs(Xa-Xb) + abs(Ya-Yb) + 1))). (Xa,Ya) and (Xb,Yb) is the position of A and B. So B's HP will reduce P.
Than B hurt A. A will loss MAX(1,(int)((B's ATI - A's DEF) / ( abs(Xa-Xb) + abs(Ya-Yb) + 1))).
Every one will die if his HP is small or equal to 0.
In the 2d-world. Magina standing in the position (0,0) and never moving, in T unit time, n monsters will move nearly to attack he. To every unit time we divide it to four processes.
First Magina choose K monsters to attack once each continuously .(He will attack all if there are no K monsters survived ) If a monster die by attacking, he will drop a equipment. Than Magina can choose weather to use it. The way Magina choose is according to the P which is the value of his hurting to the monster. The first K higher monsters will be selected at the every unit time's begining, if two monsters have some P, the smaller ID of monsters will be selected.
Second every monster survived will hurt Magina once continuously. If Magina die, game over.
Third every monster survived will move to Magina one unit. If the monster is standing the place of Magina, he will not move. One unit is meaning X or Y to change only one.
Fourth Magina will revert W HP. W = (int) ( MaxHP*0.05 ). The maximum of HP can not bigger than MaxHP.
Now matter Magina or monster have three attributes(ATI, DEF, HP), but Magina have another attributes (MaxHP). Magina can own some equipments as a hero , there are six kinds of equipment ("Head", "Weapon", "Armor","Shoes", "Trump","Cuff") in this world. Equipment have three attributes (A, D, MH), each standing the value can increase to ATI, DEF and MaxHP of Magina.
To every some kinds of equipment, Magina can only choose one to use. So when he have some kinds of equipments, he will choose the one have the bigger value. The value of equipments define as A*3 + D*2 + MH. If the value of equipments is equal to the one Magina have, he will not choose to change his equipment.







Now describe a fighting between A and B.
We know A hurt B first, the value of harm define as P.
P = MAX(1,(int)((A's ATI - B's DEF) / ( abs(Xa-Xb) + abs(Ya-Yb) + 1))). (Xa,Ya) and (Xb,Yb) is the position of A and B. So B's HP will reduce P.
Than B hurt A. A will loss MAX(1,(int)((B's ATI - A's DEF) / ( abs(Xa-Xb) + abs(Ya-Yb) + 1))).
Every one will die if his HP is small or equal to 0.
In the 2d-world. Magina standing in the position (0,0) and never moving, in T unit time, n monsters will move nearly to attack he. To every unit time we divide it to four processes.
First Magina choose K monsters to attack once each continuously .(He will attack all if there are no K monsters survived ) If a monster die by attacking, he will drop a equipment. Than Magina can choose weather to use it. The way Magina choose is according to the P which is the value of his hurting to the monster. The first K higher monsters will be selected at the every unit time's begining, if two monsters have some P, the smaller ID of monsters will be selected.
Second every monster survived will hurt Magina once continuously. If Magina die, game over.
Third every monster survived will move to Magina one unit. If the monster is standing the place of Magina, he will not move. One unit is meaning X or Y to change only one.
Fourth Magina will revert W HP. W = (int) ( MaxHP*0.05 ). The maximum of HP can not bigger than MaxHP.
Input
The input contains multiple test cases.
First line give the integer n (1<= n <=400)
Next line ATI, DEF, MaxHP,K,T. (T<=100). Magina is HP = MaxHP and have no equipment at the begin.
Next follow n line, each line expressing a monster by increasint ID.The input form as ATI, DEF,HP,X,Y, Kind'smane, A, D, MH. All integer are nonnegative.Last four expressing the equipment this monster owned.Kind'smane is the kind name of equipment.It can only be one of six describing foregoing
First line give the integer n (1<= n <=400)
Next line ATI, DEF, MaxHP,K,T. (T<=100). Magina is HP = MaxHP and have no equipment at the begin.
Next follow n line, each line expressing a monster by increasint ID.The input form as ATI, DEF,HP,X,Y, Kind'smane, A, D, MH. All integer are nonnegative.Last four expressing the equipment this monster owned.Kind'smane is the kind name of equipment.It can only be one of six describing foregoing
Output
Output the information of Magina's equipment during the T unit times.
If Magina use a equipment when he have no this kind of equipment, Output “Magina get the Sname”.
If Magina use a new well equipment, output"Magina update the Sname", Sname is the kind name of six equipments.
Last Output "Magina death !" if Magina is death .Otherwise output "Magina killed Num Monster!",Num is a numbers of monsters Magina killed during T unit times.
Every case follow a blank.
If Magina use a equipment when he have no this kind of equipment, Output “Magina get the Sname”.
If Magina use a new well equipment, output"Magina update the Sname", Sname is the kind name of six equipments.
Last Output "Magina death !" if Magina is death .Otherwise output "Magina killed Num Monster!",Num is a numbers of monsters Magina killed during T unit times.
Every case follow a blank.
Sample Input
1
30 2 100 1 3
3 0 10 2 2 Head 1 0 0
5
192 114 29 3 64
22 3 140 15 5 Head 32 18 4
45 15 114 4 11 Trump 34 47 48
44 9 186 19 2 Cuff 28 46 12
32 3 2 10 18 Armor 45 40 15
27 3 104 1 3 Trump 37 2 22
5
30 130 33 2 85
34 4 163 13 15 Head 32 9 15
11 3 8 3 12 Cuff 7 22 4
11 14 143 3 18 Weapon 48 17 35
5 14 27 10 1 Cuff 9 25 41
34 17 135 13 1 Weapon 48 0 33
Sample Output
Magina get the Head
Magina killed 1 Monster!
Magina get the Trump
Magina update the Trump
Magina get the Armor
Magina get the Head
Magina get the Cuff
Magina killed 5 Monster!
Magina get the Cuff
Magina death !
模拟题,但是题目要求的操作比较多。需要注意以下几点:
- 题目每隔一个单位时间 monster 就向 magina 移动一个单位,这里向 x 还是 y 方向移动不要紧,因为计算伤害时使用的是曼哈顿距离而不是欧拉距离(参考),所以可以先向 x 轴移动到 0 再向 y 轴移动到 0,也可以反过来。注意到达位置 (0,0) 后不要继续移动就可以。
- 每次 magina 攻击时需要先选出 K 个 monster,选择时以 magina 当时的装备情况计算伤害排序;但是选完之后攻击时,如果击杀了一个 monster,magina 捡起装备后,需要更新自己的装备属性,也就是说,攻击下一个 monster(还有的话)时的攻击力需要根据装备重新计算。
- 当轮到 montser 攻击的时候,magina 的防御值是它攻击完后装备更新之后的防御值
- 回复过程中,MaxHP 也是 magina 装备更新后的 MaxHP
- 输出击败的 monster 数量时注意是在 T 时间内击败的(我没考虑 T,WA 了 N 次)
参考代码:
#include <cstdio>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
const int MAXN = 405;
int n, ATI, DEF, MaxHP, HP, K, T;
int _ATI, _DEF, _MaxHP;
char* equipments[6] = {"Head", "Weapon", "Armor", "Shoes", "Trump", "Cuff"};
int equipments_value[6][3];
bool equipted[6];
struct monster{
int id, ati, def,hp, x, y, a, d, mh;
char name[10];
int hurt;
};
vector<monster> monsters;
inline bool cmp(const monster& m1, const monster& m2){
if(m1.hurt != m2.hurt) return m1.hurt > m2.hurt;
return m1.id < m2.id;
}
int get_equipment_type(char* e){
for(int i = 0; i < 6; i++){
if(strcmp(e, equipments[i]) == 0) return i;
}
return -1;
}
// 计算装备属性
void update_magina(){
_ATI = ATI;
_DEF = DEF;
_MaxHP = MaxHP;
for(int i = 0; i < 6; i++){
_ATI += equipments_value[i][0];
_DEF += equipments_value[i][1];
_MaxHP += equipments_value[i][2];
}
}
// 计算伤害
inline int caculate_p(int ati, int def, int x, int y){
return max(1, (int)((ati - def) / ((abs(x) + abs(y)) + 1)));
}
// 回复
inline void revert(){
int w = (int)(_MaxHP * 0.05);
HP = (HP + w <= _MaxHP) ? HP + w : _MaxHP;
}
void magina_attack(){
update_magina();
// 计算伤害
for(int i = monsters.size() - 1; i >= 0; i--)
monsters[i].hurt = caculate_p(_ATI, monsters[i].def, monsters[i].x, monsters[i].y);
// 对伤害进行排序
sort(monsters.begin(), monsters.end(), cmp);
// 攻击monster
vector<monster>::iterator it = monsters.begin();
int k = K;
while(it != monsters.end() && k > 0){
// 刷新装备信息
update_magina();
// 重新计算伤害
int hurt = caculate_p(_ATI, (*it).def, (*it).x, (*it).y);
(*it).hp = (*it).hp - hurt;
if((*it).hp <= 0){ // 该monster被消灭了,掉装备
int type = get_equipment_type((*it).name);
if(!equipted[type]){ // 新装备
equipted[type] = true;
equipments_value[type][0] = (*it).a;
equipments_value[type][1] = (*it).d;
equipments_value[type][2] = (*it).mh;
printf("Magina get the %s\n", equipments[type]);
}else{ // 已装备过,需要比较
int prev = 3 * equipments_value[type][0] + 2 * equipments_value[type][1] + equipments_value[type][2];
int now = 3 * (*it).a + 2 * (*it).d + (*it).mh;
if(now > prev){
equipments_value[type][0] = (*it).a;
equipments_value[type][1] = (*it).d;
equipments_value[type][2] = (*it).mh;
printf("Magina update the %s\n", equipments[type]);
}
}
// 移除该monster
it = monsters.erase(it);
}else{
++it;
}
k--;
}
}
// monster攻击magina
void monsters_attack(){
for(int i = monsters.size() - 1; i >= 0; i--){
int p = caculate_p(monsters[i].ati, _DEF, monsters[i].x, monsters[i].y);
HP -= p;
}
}
void monsters_move(){
for(int i = monsters.size() - 1; i >= 0; i--){
if(monsters[i].x != 0) monsters[i].x--;
else if(monsters[i].y != 0) monsters[i].y--;
}
}
int main(){
monster m;
while(~scanf("%d", &n)){
monsters.clear();
memset(equipted, 0, sizeof(equipted));
memset(equipments_value, 0, sizeof(equipments_value));
scanf("%d %d %d %d %d", &ATI, &DEF, &MaxHP, &K, &T);
HP = MaxHP;
for(int i = 0; i < n; i++){
scanf("%d %d %d %d %d %s %d %d %d", &m.ati, &m.def, &m.hp, &m.x,
&m.y, m.name, &m.a, &m.d, &m.mh);
m.id = i;
monsters.push_back(m);
}
for(int i = 0; i < T; i++){
// magina攻击,捡装备
magina_attack();
// 刷新装备
update_magina();
// monsters攻击
monsters_attack();
// mogina已死,游戏结束
if(HP <= 0) break;
// monster全被消灭,游戏结束
if(monsters.size() <= 0) break;
// 怪兽移动
monsters_move();
// migina回血
revert();
}
if(HP <= 0) printf("Magina death !\n");
else printf("Magina killed %d Monster!\n", n - monsters.size());
putchar('\n');
}
return 0;
}