fork download
  1. #include "Solution.h"
  2. #include <sstream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <cmath>
  6. #include <cstdlib>
  7. #include <iostream>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. #define sqr(a) ((a)*(a))
  13. #define forn(i,n) for (int i = 0; i < (int)(n); ++i)
  14.  
  15. typedef CoordsXY point;
  16. typedef long double ld;
  17.  
  18. FILE *LOG = 0;
  19.  
  20. ld dist (const point &a, const point &b) {
  21. return sqrtl(sqr(a.x - b.x) + sqr(a.y - b.y));
  22. }
  23.  
  24. map<int, int> Strategy() {
  25. map<int, int> answer;
  26. int k = 0;
  27. for (int i = 0; i < MAX_FACTORY_COUNT; i++) {
  28. const Factory &f = pWorld->factories[i];
  29. if (f.id < 0) continue; //пропускаем "мёртвые" заводы
  30. if (f.owner != playerIndex) continue; //пропускаем чужие заводы
  31. answer[f.id] = 0; //говорим, что на нашем заводе надо строить!
  32. }
  33. return answer;
  34. }
  35.  
  36. ld factAttackPrior (int i) {
  37. ld score = 0;
  38. const Factory &g = pWorld->factories[i];
  39. forn (j, 7) {
  40. const Factory &f = pWorld->factories[j];
  41. if (i == j) {
  42. continue;
  43. }
  44. if (f.owner == playerIndex) {
  45. score += 1000.l / dist(f.position, g.position);
  46. }
  47. if (f.owner == 1 - playerIndex) {
  48. score -= 1000.l / dist(f.position, g.position) * 0.5;
  49. }
  50. }
  51. return expl(2 * score);
  52. }
  53.  
  54. int my_at (int i) {
  55. const Factory &g = pWorld->factories[i];
  56. int ans = 0;
  57. forn (j, 1024) {
  58. const Robot &r = pWorld->robots[j];
  59. if (r.id != -1 && r.owner == playerIndex) {
  60. if (dist(r.position, g.position) < g.radius) {
  61. ans++;
  62. }
  63. }
  64. }
  65. return ans;
  66. }
  67.  
  68. int enemy_at (int i) {
  69. const Factory &g = pWorld->factories[i];
  70. int ans = 0;
  71. forn (j, 1024) {
  72. const Robot &r = pWorld->robots[j];
  73. if (r.id != -1 && r.owner == 1 - playerIndex) {
  74. if (dist(r.position, g.position) < g.radius) {
  75. ans++;
  76. }
  77. }
  78. }
  79. return ans;
  80. }
  81.  
  82. int enemy_near (int i) {
  83. const Factory &g = pWorld->factories[i];
  84. int ans = 0;
  85. forn (j, 1024) {
  86. const Robot &r = pWorld->robots[j];
  87. if (r.id != -1 && r.owner == 1 - playerIndex) {
  88. if (dist(r.position, g.position) < g.radius * 4) {
  89. ans++;
  90. }
  91. }
  92. }
  93. return ans;
  94. }
  95.  
  96. char buff[10240];
  97.  
  98. bool operator < (const point &a, const point &b) {
  99. return 0;
  100. }
  101.  
  102. int submit[7];
  103.  
  104. pair<string, string> Program(int robotIndex) {
  105. const Robot &cur_r = pWorld->robots[robotIndex];
  106.  
  107. int cur_id = 0;
  108. forn (i, 7) {
  109. if (dist(cur_r.position, pWorld->factories[i].position) < dist(cur_r.position, pWorld->factories[cur_id].position)) {
  110. cur_id = i;
  111. }
  112. }
  113.  
  114. const Factory &cur_f = pWorld->factories[cur_id];
  115.  
  116. if (!LOG) {
  117. sprintf(buff, "PlayerLog_%d.txt", playerIndex);
  118. LOG = fopen(buff, "w");
  119. }
  120. ld prAttack[7];
  121. forn (i, 7) {
  122. const Factory &f = pWorld->factories[i];
  123. if (f.owner == playerIndex) {
  124. prAttack[i] = 0;
  125. continue;
  126. }
  127. prAttack[i] = factAttackPrior(i);
  128. if (f.owner == 1 - playerIndex) {
  129. prAttack[i] /= 100;
  130. }
  131. }
  132. ld sum = 0;
  133. forn (i, 7) {
  134. sum += prAttack[i];
  135. }
  136. ld rd = (ld)rand() / RAND_MAX * sum;
  137. int num = 0;
  138. while (rd >= 0) {
  139. rd -= prAttack[num++];
  140. }
  141. num--;
  142. prAttack[num] = 1e20l;
  143.  
  144. if (enemy_near(cur_id) > 0) {
  145. prAttack[cur_id] = 1e21l;
  146. }
  147.  
  148. vector<pair<ld, point> > points;
  149. forn (i, 7) {
  150. points.push_back(make_pair(prAttack[i], pWorld->factories[i].position));
  151. }
  152. sort(points.begin(), points.end());
  153. reverse(points.begin(), points.end());
  154. int bufs = 0;
  155. sprintf(buff, "path = {}\n");
  156. forn (i, 7) {
  157. sprintf(buff + strlen(buff), "path[%d] = {x = %lf, y = %lf}\n", i, double(points[i].second.x), double(points[i].second.y));
  158. }
  159. fputs(buff, stderr);
  160.  
  161. // if ((double)rand() / RAND_MAX < 1. - (double)my_at(cur_id) / 3 && pWorld->currentTime > 600) {
  162. // num = cur_id;
  163. // }
  164. // sprintf(buff, "capture = {x = %lf, y = %lf}", pWorld->factories[num].position.x, pWorld->factories[num].position.y);
  165.  
  166. return make_pair("", string(buff));
  167. }
  168.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:22: fatal error: Solution.h: No such file or directory
 #include "Solution.h"
                      ^
compilation terminated.
stdout
Standard output is empty