lencinasalejo

codeforces_1_exercises

Apr 19th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | Software | 0 0
  1. /*------------------- DIE ROLL -------------------*/
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <map>
  5.  
  6. using namespace std;
  7. map<float, string> fraction =
  8. {
  9.     {6.0/6.0, "1/1"},
  10.     {5.0/6.0, "5/6"},
  11.     {4.0/6.0, "2/3"},
  12.     {3.0/6.0, "1/2"},
  13.     {2.0/6.0, "1/3"},
  14.     {1.0/6.0, "1/6"}
  15. };
  16.  
  17. int main()
  18. {
  19.     int max_dice_num = 6;
  20.     int y, w;
  21.     cin >> y >> w;
  22.     if (y == 1 && w == 1)
  23.     {
  24.         cout << "1/1";
  25.         return 0;
  26.     }
  27.     int max_points = y > w? y : w;
  28.     int cant_possible_points = max_dice_num - max_points + 1;
  29. //    cout << cant_possible_points << " ";
  30. //    cout << max_dice_num << " ";
  31.     string prob = fraction[(float)cant_possible_points / (float)max_dice_num];
  32.     //string prob = fraction[(3.0 / 6.0)];
  33.     //cout << fixed << setprecision(2) << prob;
  34.     cout << prob;
  35.     return 0;
  36. }
  37. /*------------------- FIN DIE ROLL -------------------*/
  38. /*------------------- TRIANGULAR NUMBERS -------------------*/
  39. #include <iostream>
  40.  
  41. using namespace std;
  42.  
  43. int main()
  44. {
  45.     /*
  46.     Me voy fijando si el número de input es igual a la suma de todos los números (empezando desde 1) hasta n,
  47.     empezando con n = 1. Si es igual imprimo YES, si supero el número imprimo NO.
  48.     */
  49.  
  50.     int input_num;
  51.     cin >> input_num;
  52.     if(input_num == 0 || input_num == 1)
  53.     {
  54.         cout << "YES";
  55.         return 0;
  56.     }
  57.     long long sum = 3;
  58.     int i = 1;
  59.     while(sum < input_num)
  60.     {
  61.         sum = (i * (i + 1)) / 2;
  62.         i++;
  63.     }
  64.  
  65.     if(input_num == sum)
  66.     {
  67.         cout << "YES";
  68.     } else
  69.     {
  70.         cout << "NO";
  71.     }
  72.  
  73.     return 0;
  74. }
  75. /*------------------- FIN TRIANGULAR NUMBERS -------------------*/
  76. /*------------------- DOMINO PILING -------------------*/
  77. #include <iostream>
  78.  
  79. using namespace std;
  80.  
  81. int main()
  82. {
  83.     int m, n;
  84.     cin >> m >> n;
  85.     cout << (m*n)/2;
  86.     return 0;
  87. }
  88. /*------------------- FIN DOMINO PILING -------------------*/
  89. /*------------------- BLACKJACK -------------------*/
  90. #include <iostream>
  91. #include <map>
  92.  
  93. using namespace std;
  94. map<int, int> values =
  95. {
  96.     {1, 4},
  97.     {2, 4},
  98.     {3, 4},
  99.     {4, 4},
  100.     {5, 4},
  101.     {6, 4},
  102.     {7, 4},
  103.     {8, 4},
  104.     {9, 4},
  105.     {10, 15},
  106.     {11, 4}
  107. };
  108.  
  109. int main()
  110. {
  111.     int points;
  112.     cin >> points;
  113.     if(points < 11)
  114.     {
  115.         cout << 0;
  116.         return 0;
  117.     }
  118.     cout << values[points - 10];
  119.     return 0;
  120. }
  121. /*------------------- FIN BLACKJACK -------------------*/
  122. /*------------------- PLAYING WITH DICE -------------------*/
  123. #include <iostream>
  124.  
  125. using namespace std;
  126.  
  127. int main()
  128. {
  129.     int a, b;
  130.     cin >> a >> b;
  131.     int a_wins = 0, draw = 0, b_wins = 0;
  132.     int a_dist = 0, b_dist = 0, dif = 0;
  133.     for (int i = 1; i <= 6; i++)
  134.     {
  135.         a_dist = abs(a - i);
  136.         b_dist = abs(b - i);
  137.         dif = a_dist - b_dist;
  138.         if (dif < 0)
  139.         {
  140.             a_wins++;
  141.         } else if(dif > 0)
  142.         {
  143.             b_wins++;
  144.         } else
  145.         {
  146.             draw++;
  147.         }
  148.     }
  149.  
  150.     cout << a_wins << " " << draw << " " << b_wins;
  151.  
  152.     return 0;
  153. }
  154. /*------------------- FIN PLAYING WITH DICE -------------------*/
Add Comment
Please, Sign In to add comment