Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. /**
  9. * Auto-generated code below aims at helping you parse
  10. * the standard input according to the problem statement.
  11. **/
  12.  
  13. class Planet{
  14. public:
  15. int myU,enU,myT,enT;
  16. int CmyU,CenU,CmyT,CenT;
  17. bool canAssign;
  18. bool CcanAssign;
  19. int neighbours[8];
  20. int neighboursC;
  21.  
  22. Planet(){
  23. neighboursC = 0;
  24.  
  25. }
  26.  
  27. Planet(int mU,int eU,int mT,int eT,bool canA){
  28. myU = mU;
  29. enU = eU;
  30. myT = mT;
  31. enT = eT;
  32. canAssign = canA;
  33. neighboursC = 0;
  34. }
  35.  
  36. void update(int mU,int eU,int mT,int eT,bool canA){
  37. myU = mU;
  38. enU = eU;
  39. myT = mT;
  40. enT = eT;
  41. canAssign = canA;
  42. }
  43.  
  44. void addEdge(int index){
  45. neighbours[neighboursC] = index;
  46. neighboursC++;
  47. }
  48.  
  49. void save(){
  50. CmyU = myU;
  51. CenU = enU;
  52. CmyT = myT;
  53. CenT = enT;
  54. CcanAssign = canAssign;
  55. }
  56.  
  57. void copy(){
  58. myU = CmyU;
  59. enU = CenU;
  60. myT = CmyT;
  61. enT = CenT;
  62. canAssign = CcanAssign;
  63. }
  64.  
  65. void debug(){
  66. cerr << "PLANET myU " << myU << " enU " << enU << " myT " << myT << " enT " << enT << " canAssign " << canAssign << endl;
  67.  
  68. for(int i = 0;i < neighboursC;i++){
  69. cerr << "NEIGHBOUR " << neighbours[i] << endl;
  70. }
  71. }
  72. };
  73.  
  74. class Action{
  75. public:
  76. int indexes[5];
  77. int spread;
  78.  
  79. Action(){
  80. spread = -1;
  81. }
  82.  
  83. Action(int indexes_[5],int s){
  84. for(int i = 0;i < 5;i++)indexes[i] = indexes_[i];
  85. spread = s;
  86. }
  87. };
  88.  
  89. class Game{
  90. public:
  91. Planet planets[90];
  92. int planetCount;
  93. int edgeCount;
  94.  
  95. void turn(Action& action){
  96. int planetAffected[5];
  97. int planetAffC = 0;
  98. for(int i = 0;i < 5;i++){
  99. bool add = true;
  100. for(int ii = 0;ii < planetAffC;ii++){
  101. if(action.indexes[i] == planetAffected[ii]){
  102. add = false;
  103. break;
  104. }
  105. }
  106. if(add == true){
  107. planetAffected[planetAffC] = action.indexes[i];
  108. planetAffC++;
  109. }
  110.  
  111.  
  112. planets[action.indexes[i]].myU++;
  113. }
  114.  
  115. if(action.spread != -1){
  116. if(planets[action.spread].myU >= 5){
  117. planets[action.spread].myU -= 5;
  118.  
  119. for(int p = 0;p < planets[action.spread].neighboursC;p++){
  120. planets[planets[action.spread].neighbours[p]].myU++;
  121. }
  122. }
  123. }
  124.  
  125.  
  126. for(int i = 0;i < planetAffC;i++){
  127. planets[planetAffected[i]].myT--;
  128. }
  129.  
  130. for(int p = 0;p < planetCount;p++){
  131.  
  132. }
  133.  
  134.  
  135. }
  136.  
  137. void save(){
  138. for(int i = 0;i < planetCount;i++)planets[i].save();
  139. }
  140.  
  141. void copy(){
  142. for(int i = 0;i < planetCount;i++)planets[i].copy();
  143. }
  144. };
  145.  
  146. int main()
  147. {
  148. Game game;
  149.  
  150. int planetCount;
  151. int edgeCount;
  152. cin >> planetCount >> edgeCount; cin.ignore();
  153.  
  154. game.planetCount = planetCount;
  155. game.edgeCount = edgeCount;
  156.  
  157. for (int i = 0; i < edgeCount; i++) {
  158. int planetA;
  159. int planetB;
  160. cin >> planetA >> planetB; cin.ignore();
  161. game.planets[planetA].addEdge(planetB);
  162. game.planets[planetB].addEdge(planetA);
  163. }
  164.  
  165. // game loop
  166. while (1) {
  167. vector<int>planetsValid;
  168. for (int i = 0; i < planetCount; i++) {
  169. int myUnits;
  170. int myTolerance;
  171. int otherUnits;
  172. int otherTolerance;
  173. int canAssign;
  174. cin >> myUnits >> myTolerance >> otherUnits >> otherTolerance >> canAssign; cin.ignore();
  175. game.planets[i].update(myUnits,otherUnits,myTolerance,otherTolerance,canAssign);
  176. if(canAssign)planetsValid.push_back(i);
  177. }
  178.  
  179. // for(int i = 0;i < planetCount;i++)game.planets[i].debug();
  180. for(int i = 0;i < planetsValid.size();i++)cerr << planetsValid[i] << endl;
  181. // Write an action using cout. DON'T FORGET THE "<< endl"
  182. // To debug: cerr << "Debug messages..." << endl;
  183.  
  184. int printed = 0;
  185. bool error = false;
  186. while(printed < 5){
  187. if(planetsValid.size() == 0){
  188. cout << "0" << endl;
  189. printed++;
  190. }
  191. for(int i = 0;i < planetsValid.size() && printed < 5;i++){
  192. if(error == false && game.planets[planetsValid[i]].myU > game.planets[planetsValid[i]].enU)continue;
  193. cout << planetsValid[i] << endl;
  194. printed++;
  195. }
  196. if(printed == 0)error = true;
  197. }
  198.  
  199. bool spreading = false;
  200. /* for(int i = 0;i < planetsValid.size();i++){
  201. if(game.planets[planetsValid[i]].myU > game.planets[planetsValid[i]].enU &&
  202. game.planets[planetsValid[i]].myU >= 5){cout << planetsValid[i] << endl;spreading = true;break;}
  203. }*/
  204. if(spreading == false)
  205. cout << "NONE" << endl;
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement