|
27 | 27 | "\n",
|
28 | 28 | "Think about what the problem is asking, break it down\n",
|
29 | 29 | "\n",
|
30 |
| - "The first step is determining which dice wins.\n", |
| 30 | + "First we must code up the `beats()` function.\n", |
31 | 31 | "1. Count the number of ways dice A wins.\n",
|
32 | 32 | "2. Count the number of ways dice B wins.\n",
|
33 | 33 | "3. Whoever have a larger value is the winner. If both win the same number of times, that dice are tied."
|
|
39 | 39 | "metadata": {},
|
40 | 40 | "outputs": [],
|
41 | 41 | "source": [
|
42 |
| - "\"\"\" Python solution to USACO January 2022 Bronze problem two\n", |
| 42 | + "\"\"\" Python solution to USACO January 2022 Bronze problem two.\n", |
43 | 43 | "Translated into python from my c++ solution. Below is the link to my original code.\n",
|
44 | 44 | "https://github.com/asubramanian08/USACO/blob/master/Bronze/2021-2022/JAN2022/q2.cpp \"\"\"\n",
|
45 | 45 | "\n",
|
|
57 | 57 | " bWins += A[i] < B[j]\n",
|
58 | 58 | " return aWins - bWins\n",
|
59 | 59 | "\n",
|
| 60 | + "# Get input\n", |
60 | 61 | "C = [0, 0, 0, 0] # Using 0 as place holder\n",
|
61 | 62 | "for test in range(int(input())):\n",
|
62 | 63 | " diceFaces = list(map(int, input().split(' ')))\n",
|
63 | 64 | " A = diceFaces[:SIDES]\n",
|
64 | 65 | " B = diceFaces[SIDES:]\n",
|
65 |
| - " foundAnswer = False\n", |
| 66 | + " \n", |
| 67 | + " # Unify cycle direction\n", |
66 | 68 | " winner = beats(A, B)\n",
|
67 |
| - " if winner == 0: # Tie\n", |
68 |
| - " foundAnswer = True\n", |
69 |
| - " elif winner < 0: # B won\n", |
| 69 | + " if winner < 0:\n", |
70 | 70 | " A, B = B, A\n",
|
| 71 | + " \n", |
| 72 | + " # Determine is there is a valid cycle\n", |
| 73 | + " foundAnswer = False\n", |
71 | 74 | " for C[0] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
|
72 | 75 | " for C[1] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
|
73 | 76 | " for C[2] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
|
74 | 77 | " for C[3] in range(MIN_FACE, MAX_FACE + 1, 1):\n",
|
75 | 78 | " if beats(C, A) > 0 and beats(B, C) > 0:\n",
|
76 | 79 | " foundAnswer = True # Cycle found\n",
|
| 80 | + " \n", |
| 81 | + " # Print yes when there is no tie and a cycle has been found\n", |
77 | 82 | " print(\"yes\" if (winner != 0 and foundAnswer) else \"no\")"
|
78 | 83 | ]
|
79 | 84 | }
|
|
0 commit comments