Source code for submission s750

Go to diff to previous submission

rhino.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int RankToInt(char c)
  5. {
  6. switch(c)
  7. {
  8. case 'A': return 12;
  9. case 'K': return 11;
  10. case 'Q': return 10;
  11. case 'J': return 9;
  12. case 'X': return 8;
  13. default: return c - '2';
  14. }
  15. }
  16.  
  17. int SuitToInt(char c)
  18. {
  19. switch(c)
  20. {
  21. case 'h': return 0;
  22. case 'd': return 13;
  23. case 's': return 26;
  24. default: return 39;
  25. }
  26. }
  27.  
  28. int Make(int a, int q = 0, int w = 0, int e = 0, int r = 0, int t = 0)
  29. {
  30. return (a << 20)
  31. | (q << 16)
  32. | (w << 12)
  33. | (e << 8)
  34. | (r << 4)
  35. | (t << 0);
  36. }
  37.  
  38. int FindRank(int* r, int a, int prev = 13)
  39. {
  40. for(int i = prev - 1; 1; i--)
  41. {
  42. if(r[i] == a)
  43. {
  44. return i;
  45. }
  46. }
  47. }
  48.  
  49. int Assess(int a[5])
  50. {
  51. int r[13], rr[13];
  52. for(int i = 0; i < 13; i++)
  53. {
  54. r[i] = 0;
  55. rr[i] = 0;
  56. }
  57.  
  58. for(int i = 0; i < 5; i++)
  59. {
  60. r[a[i] % 13]++;
  61. }
  62.  
  63. for(int i = 0; i < 13; i++)
  64. {
  65. rr[r[i]]++;
  66. }
  67.  
  68. int flush = 1;
  69. for(int i = 1; i < 5; i++)
  70. {
  71. if(a[i] / 13 != a[0] / 13)
  72. {
  73. flush = 0;
  74. break;
  75. }
  76. }
  77.  
  78. int q, w, e, u, t;
  79. for(int i = 12; i >= 3; i--)
  80. {
  81. int ok = 1;
  82. for(int j = 9; j <= 13; j++)
  83. {
  84. if(!(r[(i + j) % 13]))
  85. {
  86. ok = 0;
  87. break;
  88. }
  89. }
  90.  
  91. if(ok)
  92. {
  93. return Make((flush) ? 8 : 4, i);
  94. }
  95. }
  96.  
  97.  
  98. if(rr[4])
  99. {
  100. q = FindRank(r, 4);
  101. w = FindRank(r, 1);
  102. return Make(7, q, w);
  103. }
  104.  
  105. if((rr[3]) && (rr[2]))
  106. {
  107. q = FindRank(r, 3);
  108. w = FindRank(r, 2);
  109. return Make(6, q, w);
  110. }
  111.  
  112. if(rr[3])
  113. {
  114. q = FindRank(r, 3);
  115. w = FindRank(r, 1);
  116. e = FindRank(r, 1, w);
  117. return Make(3, q, w, e);
  118. }
  119.  
  120. if(rr[2] == 2)
  121. {
  122. q = FindRank(r, 2);
  123. w = FindRank(r, 2, q);
  124. e = FindRank(r, 1);
  125. return Make(2, q, w, e);
  126. }
  127.  
  128. if(rr[2])
  129. {
  130. q = FindRank(r, 2);
  131. w = FindRank(r, 1);
  132. e = FindRank(r, 1, w);
  133. t = FindRank(r, 1, e);
  134. return Make(1, q, w, e, t);
  135. }
  136.  
  137. q = FindRank(r, 1);
  138. w = FindRank(r, 1, q);
  139. e = FindRank(r, 1, w);
  140. t = FindRank(r, 1, e);
  141. u = FindRank(r, 1, t);
  142.  
  143. return Make((flush) ? 5 : 0, q, w, e, t, u);
  144. }
  145.  
  146. int Player[20][2];
  147. int Table[5];
  148. char s[10];
  149. int Septuple[20][7];
  150. int a[5];
  151. int choose[5];
  152. int Value[20];
  153.  
  154. int Next()
  155. {
  156. int i;
  157. for(i = 4; i >= 0; i--)
  158. {
  159. choose[i]++;
  160. if(choose[i] < 3 + i)
  161. {
  162. break;
  163. }
  164. }
  165.  
  166. if(i == -1)
  167. {
  168. return 0;
  169. }
  170.  
  171. for(i++; i < 5; i++)
  172. {
  173. choose[i] = choose[i - 1] + 1;
  174. }
  175.  
  176. return 1;
  177. }
  178.  
  179. int main()
  180. {
  181. int n;
  182. while(scanf("%d", &n) > 0)
  183. {
  184. for(int i = 0; i < 5; i++)
  185. {
  186. scanf("%s", s);
  187. Table[i] = RankToInt(s[0]) + SuitToInt(s[1]);
  188. }
  189.  
  190. for(int i = 0; i < n; i++)
  191. {
  192. for(int j = 0; j < 2; j++)
  193. {
  194. scanf("%s", s);
  195. Player[i][j] = RankToInt(s[0]) + SuitToInt(s[1]);
  196. }
  197. }
  198.  
  199. for(int i = 0; i < 20; i++)
  200. {
  201. Value[i] = 0;
  202. }
  203.  
  204. for(int i = 0; i < n; i++)
  205. {
  206. for(int j = 0; j < 5; j++)
  207. {
  208. Septuple[i][j] = Table[j];
  209. }
  210.  
  211. Septuple[i][5] = Player[i][0];
  212. Septuple[i][6] = Player[i][1];
  213. }
  214.  
  215. /*for(int i = 0; i < 5; i++)
  216. {
  217. printf("%d ", Table[i]);
  218. }
  219.  
  220. printf("\n");
  221.  
  222. for(int i = 0; i < n; i++)
  223. {
  224. for(int j = 0; j < 2; j++)
  225. {
  226. printf("%d ", Player[i][j]);
  227. }
  228.  
  229. printf("\n");
  230. }*/
  231.  
  232. for(int i = 0; i < 5; i++)
  233. {
  234. choose[i] = i;
  235. }
  236.  
  237. while(1)
  238. {
  239. /*for(int i = 0; i < 5; i++)
  240. {
  241. printf("%d ", choose[i]);
  242. }
  243. printf("\n");*/
  244.  
  245. for(int i = 0; i < n; i++)
  246. {
  247. for(int j = 0; j < 5; j++)
  248. {
  249. a[j] = Septuple[i][choose[j]];
  250. }
  251.  
  252. int as = Assess(a);
  253. if(as > Value[i])
  254. {
  255. Value[i] = as;
  256. }
  257. }
  258.  
  259. if(!(Next()))
  260. {
  261. break;
  262. }
  263. }
  264.  
  265. int max = 0;
  266. for(int i = 0; i < n; i++)
  267. {
  268. if(Value[i] > max)
  269. {
  270. max = Value[i];
  271. }
  272. }
  273.  
  274. int space = 0;
  275. for(int i = 0; i < n; i++)
  276. {
  277. if(Value[i] == max)
  278. {
  279. printf("%s%d", (space) ? " " : (space = 1, ""), i + 1);
  280. }
  281. }
  282.  
  283. printf("\n");
  284. }
  285.  
  286. return 0;
  287. }
  288.  

Diff to submission s701

rhino.cpp

--- c4.s701.cteam096.rhino.cpp.0.rhino.cpp
+++ c4.s750.cteam096.rhino.cpp.0.rhino.cpp
@@ -197,4 +197,9 @@
                 }
                 
+                for(int i = 0; i < 20; i++)
+                {
+                        Value[i] = 0;
+                }
+                
                 for(int i = 0; i < n; i++)
                 {