Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- class Planet{
- public:
- int myU,enU,myT,enT;
- int CmyU,CenU,CmyT,CenT;
- bool canAssign;
- bool CcanAssign;
- int neighbours[8];
- int neighboursC;
- Planet(){
- neighboursC = 0;
- }
- Planet(int mU,int eU,int mT,int eT,bool canA){
- myU = mU;
- enU = eU;
- myT = mT;
- enT = eT;
- canAssign = canA;
- neighboursC = 0;
- }
- void update(int mU,int eU,int mT,int eT,bool canA){
- myU = mU;
- enU = eU;
- myT = mT;
- enT = eT;
- canAssign = canA;
- }
- void addEdge(int index){
- neighbours[neighboursC] = index;
- neighboursC++;
- }
- void save(){
- CmyU = myU;
- CenU = enU;
- CmyT = myT;
- CenT = enT;
- CcanAssign = canAssign;
- }
- void copy(){
- myU = CmyU;
- enU = CenU;
- myT = CmyT;
- enT = CenT;
- canAssign = CcanAssign;
- }
- void debug(){
- cerr << "PLANET myU " << myU << " enU " << enU << " myT " << myT << " enT " << enT << " canAssign " << canAssign << endl;
- for(int i = 0;i < neighboursC;i++){
- cerr << "NEIGHBOUR " << neighbours[i] << endl;
- }
- }
- };
- class Action{
- public:
- int indexes[5];
- int spread;
- Action(){
- spread = -1;
- }
- Action(int indexes_[5],int s){
- for(int i = 0;i < 5;i++)indexes[i] = indexes_[i];
- spread = s;
- }
- };
- class Game{
- public:
- Planet planets[90];
- int planetCount;
- int edgeCount;
- void turn(Action& action){
- int planetAffected[5];
- int planetAffC = 0;
- for(int i = 0;i < 5;i++){
- bool add = true;
- for(int ii = 0;ii < planetAffC;ii++){
- if(action.indexes[i] == planetAffected[ii]){
- add = false;
- break;
- }
- }
- if(add == true){
- planetAffected[planetAffC] = action.indexes[i];
- planetAffC++;
- }
- planets[action.indexes[i]].myU++;
- }
- if(action.spread != -1){
- if(planets[action.spread].myU >= 5){
- planets[action.spread].myU -= 5;
- for(int p = 0;p < planets[action.spread].neighboursC;p++){
- planets[planets[action.spread].neighbours[p]].myU++;
- }
- }
- }
- for(int i = 0;i < planetAffC;i++){
- planets[planetAffected[i]].myT--;
- }
- for(int p = 0;p < planetCount;p++){
- }
- }
- void save(){
- for(int i = 0;i < planetCount;i++)planets[i].save();
- }
- void copy(){
- for(int i = 0;i < planetCount;i++)planets[i].copy();
- }
- };
- int main()
- {
- Game game;
- int planetCount;
- int edgeCount;
- cin >> planetCount >> edgeCount; cin.ignore();
- game.planetCount = planetCount;
- game.edgeCount = edgeCount;
- for (int i = 0; i < edgeCount; i++) {
- int planetA;
- int planetB;
- cin >> planetA >> planetB; cin.ignore();
- game.planets[planetA].addEdge(planetB);
- game.planets[planetB].addEdge(planetA);
- }
- // game loop
- while (1) {
- vector<int>planetsValid;
- for (int i = 0; i < planetCount; i++) {
- int myUnits;
- int myTolerance;
- int otherUnits;
- int otherTolerance;
- int canAssign;
- cin >> myUnits >> myTolerance >> otherUnits >> otherTolerance >> canAssign; cin.ignore();
- game.planets[i].update(myUnits,otherUnits,myTolerance,otherTolerance,canAssign);
- if(canAssign)planetsValid.push_back(i);
- }
- // for(int i = 0;i < planetCount;i++)game.planets[i].debug();
- for(int i = 0;i < planetsValid.size();i++)cerr << planetsValid[i] << endl;
- // Write an action using cout. DON'T FORGET THE "<< endl"
- // To debug: cerr << "Debug messages..." << endl;
- int printed = 0;
- bool error = false;
- while(printed < 5){
- if(planetsValid.size() == 0){
- cout << "0" << endl;
- printed++;
- }
- for(int i = 0;i < planetsValid.size() && printed < 5;i++){
- if(error == false && game.planets[planetsValid[i]].myU > game.planets[planetsValid[i]].enU)continue;
- cout << planetsValid[i] << endl;
- printed++;
- }
- if(printed == 0)error = true;
- }
- bool spreading = false;
- /* for(int i = 0;i < planetsValid.size();i++){
- if(game.planets[planetsValid[i]].myU > game.planets[planetsValid[i]].enU &&
- game.planets[planetsValid[i]].myU >= 5){cout << planetsValid[i] << endl;spreading = true;break;}
- }*/
- if(spreading == false)
- cout << "NONE" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement