#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std ;
int Cost [ 5 ], Time_Index , Strength [ 5 ]; //记录武士的生命元,初始时间,攻击力
int ord1 [ 5 ] = { 2 , 3 , 4 , 1 , 0 }, ord2 [ 5 ] = { 3 , 0 , 1 , 2 , 4 }; //红 蓝 阵营制造武士的顺序
char Weapon_Name [ 3 ][ 6 ] = { "sword" , "bomb" , "arrow" };
int Weapon_Index [ 3 ] = { 0 , 1 , 2 }; //武器的种类的编号
char Warrior_Name [ 5 ][ 7 ] = { "dragon" , "ninja" , "iceman" , "lion" , "wolf" };
char Headquarter_Name [ 2 ][ 5 ] = { "red" , "blue" };
int City_Amount ; //城市个数
int K ; //每次忠诚度减少的值
float Time_Tick ; //用来让战争走出循环的状态
int fight_control = 0 ; //作用同上
int FLAG = 1 ; //用来判断是否可以停止输出
int T ;
class Headquarter ;
class Warrior ;
Warrior * City [ 30 ][ 2 ], * New_City [ 30 ][ 2 ]; //城市 new作为临时变量
class Weapon {
public :
char Name [ 6 ];
int Index ; //武器的编号
int Can_use ; //武器的耐久度
Weapon ( int which ){
Index = Weapon_Index [ which ];
Can_use = 2 ; //初始值为2,bomb每使用一次-2,arrow每使用一次-1
strcpy ( Name , Weapon_Name [ which ]);}
}; //武器类
bool cmp ( const Weapon * A , const Weapon * B ){
if ( A == NULL ) return false ;
if ( B == NULL ) return true ;
if ( A -> Index != B -> Index ) return A -> Index < B -> Index ;
return A -> Can_use > B -> Can_use ;
}
class Warrior {
friend class Headquarter ;
public :
int HP ; //生命值
int MP ; //攻击力
char Name [ 7 ];
int Born_Number ; //出生顺序
int Weapon_Count ; //表示武器的数量
int record ; //用来记录战争的情况 如果还活着为1,死去为0
Weapon * w [ 10 ]; //解决武士和武器之间的关系
int Temp ;
int Direction ; //行军方向
int City_Index ; //城市的编号
bool Red_Lost , Blue_Lost ;
Warrior ( int HP_ , int MP_ , char * s , int b_ , int d_ , int c_ ){
memset ( Name , '\0' , sizeof ( Name ));
HP = HP_ ;
MP = MP_ ;
Born_Number = b_ ;
City_Index = c_ ;
record = 1 ;
strcpy ( Name , s );
Direction = d_ ;
Temp = 0 ;
Red_Lost = false ; Blue_Lost = false ;
for ( int i = 0 ; i < 10 ; i ++ ) w [ i ] = NULL ;
Weapon_Count = 0 ;
}
virtual void get_weapon (){
w [ 0 ] = new Weapon (( Time_Index + 1 ) % 3 );
Weapon_Count ++ ;
}
void Name_print (){
cout << Name ;}
virtual void Weapon_print (){}
virtual void weapon_report (){
int sword_ = 0 , bomb_ = 0 , arrow_ = 0 ;
for ( int i = 0 ; i < 10 ; i ++ ){
if ( w [ i ] != NULL && w [ i ] -> Name [ 0 ] == 's' ) sword_ ++ ;
if ( w [ i ] != NULL && w [ i ] -> Name [ 0 ] == 'b' ) bomb_ ++ ;
if ( w [ i ] != NULL && w [ i ] -> Name [ 0 ] == 'a' ) arrow_ ++ ;
}
cout << sword_ << " sword " << bomb_ << " bomb " << arrow_ << " arrow" ;
}
virtual void Process (){
Temp = 0 ;
City [ City_Index ][ Direction < 0 ] = NULL ;
City_Index += Direction ;
New_City [ City_Index ][ Direction < 0 ] = this ;
if ( City_Index == 0 ){
Red_Lost = true ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 blue " << Name << ' ' << Born_Number << " reached red headquarter with " << HP << " elements and force " << MP << endl ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 red headquarter was taken" << endl ;
}
else if ( City_Index == City_Amount + 1 ){
Blue_Lost = true ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 red " << Name << ' ' << Born_Number << " reached blue headquarter with " << HP << " elements and force " << MP << endl ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 blue headquarter was taken" << endl ;
}
else
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 " << Headquarter_Name [ Direction < 0 ] << ' ' << Name << " " << Born_Number << " marched to city " << City_Index << " with " << HP << " elements and force " << MP << endl ;
if ( 60 * Time_Index + 10 == T ){ FLAG = 0 ; return ;}
}
virtual void Before_Fight ( Warrior * enermy ){}
virtual int fight ( Warrior * enermy ){ //战中
if ( fight_control == 0 ){
sort ( w , w + 10 , cmp );
sort ( enermy -> w , enermy -> w + 10 , cmp );}
//开战
int flag = 0 ;
Time_Tick -= 0.5 ;
int temp1 = 0 , temp2 = 0 ;
while ( w [ Temp % 10 ] == NULL && temp1 < 10 ) { Temp ++ ; temp1 ++ ;}
while ( enermy -> w [ enermy -> Temp % 10 ] == NULL && temp2 < 10 ){ enermy -> Temp ++ ; temp2 ++ ;}
if ( temp1 == 10 && temp2 == 10 &&
#include<cstring>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std ;
int Cost [ 5 ], Time_Index , Strength [ 5 ]; //记录武士的生命元,初始时间,攻击力
int ord1 [ 5 ] = { 2 , 3 , 4 , 1 , 0 }, ord2 [ 5 ] = { 3 , 0 , 1 , 2 , 4 }; //红 蓝 阵营制造武士的顺序
char Weapon_Name [ 3 ][ 6 ] = { "sword" , "bomb" , "arrow" };
int Weapon_Index [ 3 ] = { 0 , 1 , 2 }; //武器的种类的编号
char Warrior_Name [ 5 ][ 7 ] = { "dragon" , "ninja" , "iceman" , "lion" , "wolf" };
char Headquarter_Name [ 2 ][ 5 ] = { "red" , "blue" };
int City_Amount ; //城市个数
int K ; //每次忠诚度减少的值
float Time_Tick ; //用来让战争走出循环的状态
int fight_control = 0 ; //作用同上
int FLAG = 1 ; //用来判断是否可以停止输出
int T ;
class Headquarter ;
class Warrior ;
Warrior * City [ 30 ][ 2 ], * New_City [ 30 ][ 2 ]; //城市 new作为临时变量
class Weapon {
public :
char Name [ 6 ];
int Index ; //武器的编号
int Can_use ; //武器的耐久度
Weapon ( int which ){
Index = Weapon_Index [ which ];
Can_use = 2 ; //初始值为2,bomb每使用一次-2,arrow每使用一次-1
strcpy ( Name , Weapon_Name [ which ]);}
}; //武器类
bool cmp ( const Weapon * A , const Weapon * B ){
if ( A == NULL ) return false ;
if ( B == NULL ) return true ;
if ( A -> Index != B -> Index ) return A -> Index < B -> Index ;
return A -> Can_use > B -> Can_use ;
}
class Warrior {
friend class Headquarter ;
public :
int HP ; //生命值
int MP ; //攻击力
char Name [ 7 ];
int Born_Number ; //出生顺序
int Weapon_Count ; //表示武器的数量
int record ; //用来记录战争的情况 如果还活着为1,死去为0
Weapon * w [ 10 ]; //解决武士和武器之间的关系
int Temp ;
int Direction ; //行军方向
int City_Index ; //城市的编号
bool Red_Lost , Blue_Lost ;
Warrior ( int HP_ , int MP_ , char * s , int b_ , int d_ , int c_ ){
memset ( Name , '\0' , sizeof ( Name ));
HP = HP_ ;
MP = MP_ ;
Born_Number = b_ ;
City_Index = c_ ;
record = 1 ;
strcpy ( Name , s );
Direction = d_ ;
Temp = 0 ;
Red_Lost = false ; Blue_Lost = false ;
for ( int i = 0 ; i < 10 ; i ++ ) w [ i ] = NULL ;
Weapon_Count = 0 ;
}
virtual void get_weapon (){
w [ 0 ] = new Weapon (( Time_Index + 1 ) % 3 );
Weapon_Count ++ ;
}
void Name_print (){
cout << Name ;}
virtual void Weapon_print (){}
virtual void weapon_report (){
int sword_ = 0 , bomb_ = 0 , arrow_ = 0 ;
for ( int i = 0 ; i < 10 ; i ++ ){
if ( w [ i ] != NULL && w [ i ] -> Name [ 0 ] == 's' ) sword_ ++ ;
if ( w [ i ] != NULL && w [ i ] -> Name [ 0 ] == 'b' ) bomb_ ++ ;
if ( w [ i ] != NULL && w [ i ] -> Name [ 0 ] == 'a' ) arrow_ ++ ;
}
cout << sword_ << " sword " << bomb_ << " bomb " << arrow_ << " arrow" ;
}
virtual void Process (){
Temp = 0 ;
City [ City_Index ][ Direction < 0 ] = NULL ;
City_Index += Direction ;
New_City [ City_Index ][ Direction < 0 ] = this ;
if ( City_Index == 0 ){
Red_Lost = true ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 blue " << Name << ' ' << Born_Number << " reached red headquarter with " << HP << " elements and force " << MP << endl ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 red headquarter was taken" << endl ;
}
else if ( City_Index == City_Amount + 1 ){
Blue_Lost = true ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 red " << Name << ' ' << Born_Number << " reached blue headquarter with " << HP << " elements and force " << MP << endl ;
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 blue headquarter was taken" << endl ;
}
else
cout << setw ( 3 ) << setfill ( '0' ) << Time_Index << ":10 " << Headquarter_Name [ Direction < 0 ] << ' ' << Name << " " << Born_Number << " marched to city " << City_Index << " with " << HP << " elements and force " << MP << endl ;
if ( 60 * Time_Index + 10 == T ){ FLAG = 0 ; return ;}
}
virtual void Before_Fight ( Warrior * enermy ){}
virtual int fight ( Warrior * enermy ){ //战中
if ( fight_control == 0 ){
sort ( w , w + 10 , cmp );
sort ( enermy -> w , enermy -> w + 10 , cmp );}
//开战
int flag = 0 ;
Time_Tick -= 0.5 ;
int temp1 = 0 , temp2 = 0 ;
while ( w [ Temp % 10 ] == NULL && temp1 < 10 ) { Temp ++ ; temp1 ++ ;}
while ( enermy -> w [ enermy -> Temp % 10 ] == NULL && temp2 < 10 ){ enermy -> Temp ++ ; temp2 ++ ;}
if ( temp1 == 10 && temp2 == 10 &&