#include <iostream> #include <vector> using namespace std; #define Dcout(x) cout << #x << ": " << (x) << endl
class HeadQuarter { public: bool Stop= false; struct Warrior { string name; int strength; int cnt; }; enum camp { red= 0, blue= 1 }; HeadQuarter(HeadQuarter::camp color, int HealthPoint, int dragon, int ninja, int iceman, int lion, int wolf) { Warrior Dragon= {"dragon", dragon, 0}, Ninja= {"ninja", ninja, 0}, Iceman= {"iceman", iceman, 0}, Lion= {"lion", lion, 0}, Wolf= {"wolf", wolf, 0}; if (color == camp::red) { Color= "red"; seqcycle.push_back(Iceman); seqcycle.push_back(Lion); seqcycle.push_back(Wolf); seqcycle.push_back(Ninja); seqcycle.push_back(Dragon); } else { Color= "blue"; seqcycle.push_back(Lion); seqcycle.push_back(Dragon); seqcycle.push_back(Ninja); seqcycle.push_back(Iceman); seqcycle.push_back(Wolf); } HP= HealthPoint; Warriorcnt= 0; TimeCount= 0; for (auto &&it : seqcycle) { MinHp= min(MinHp, it.strength); } } void GenWarrior() { static auto index= seqcycle.begin(); auto indexloop= [this]() { index= index == seqcycle.end() ? seqcycle.begin() : index + 1; }; if (HP > MinHp) { for (; HP < index->strength; indexloop()) { } printf("%03d %s %s %d born with strength %d,%d %s in %s " "headquarter\n", TimeCount++, Color.c_str(), index->name.c_str(), ++Warriorcnt, index->strength, ++index->cnt, index->name.c_str(), Color.c_str()); HP-= index->strength; indexloop(); } else { if (!Stop) { printf("%03d %s headquarter stops making warriors\n", TimeCount, Color.c_str()); Stop= true; } } }
private: vector<Warrior> seqcycle; int HP; string Color; int TimeCount; int Warriorcnt; int MinHp= 10000; };
#define BLUE #define RED
int main(int argc, char const *argv[]) { int caseNumber= 0; int caseHp= 0; int casedragon= 0, caseninja= 0, caseiceman= 0, caselion= 0, casewolf= 0; cin >> caseNumber; for (int i= 1; i <= caseNumber; i++) { cin >> caseHp; cin >> casedragon >> caseninja >> caseiceman >> caselion >> casewolf; HeadQuarter *RedCamp= new HeadQuarter(HeadQuarter::red, caseHp, casedragon, caseninja, caseiceman, caselion, casewolf); HeadQuarter *BlueCamp= new HeadQuarter(HeadQuarter::blue, caseHp, casedragon, caseninja, caseiceman, caselion, casewolf); cout << "Case:" << caseNumber << endl; #ifdef RED while (RedCamp->Stop != true) { RedCamp->GenWarrior(); } #endif #ifdef BLUE while (BlueCamp->Stop != true) { BlueCamp->GenWarrior(); } #endif delete RedCamp; delete BlueCamp; }
return 0; }
|