Answer the question
In order to leave comments, you need to log in
Can you explain the solution of the Olympiad problem?
Good day!
I really ask for explanations from smart and resourceful "Olympiads" on the problem from the last Olympiad.
Problem conditions:
Artem creates an interactive sensor for playing dice. The sensor is built into the table and can count the
total number of points on the edges of all rolled dice adjacent to the sensor (that is, on the
bottom edges). Later, Artem realized that for the game you need to calculate the sum not on the lower, but on the
upper faces. Artem wants to write a program that, given the sum on the lower faces, can
find the number of different possible sums on the upper faces. But since Artem is not good at
programming, he entrusts this task to you.
The sensor outputs a number s equal to the total number of dots on the lower faces of the dice.
All thrown dice are six-sided and satisfy the condition of a regular dice, that is, the
sum of the points on opposite sides of the die is seven (1 and 6, 2 and 5, 3 and 4). You need to
find the number of possible sums on the top faces of the cubes.
Input data format:
The first line of the input file contains the number s sum on the lower faces of the bones.
Output data format:
Print one number: the number of different possible sums on the upper faces of the die
Examples:
Input: 2 | Output: 2
Input: 4 | Output: 4
Solution in C++:
#include <fstream>
using namespace std;
int main() {
ifstream fin("sensor.in");
ofstream fout("sensor.out");
int s, ans;
fin >> s;
ans = s - (s + 5) / 6 + 1; // (1)
fout << ans << endl;
}
Answer the question
In order to leave comments, you need to log in
The problem is reduced to finding out how many cubes (not ways, but precisely cubes) can be given the initial sum (inferior faces).
For example, 1 can only be given by the 1st die, the answer is 1
2 can be given by either the 1st or 2dice, the answer is 2
3 can be given by the 1st, 2nd or 3rd dice , the answer is 3.
Consider 4. Can be given from 1 to 4 cubes. Those. the answer is 4. Consider the case of 2 cubes. These can be combinations of 2 + 2 or 1 + 3, but both of them will give the same sum of upper bounds: 6 + 6 - (2 + 2) or 6 + 6 - (1 + 3), which is clearly the same .
For different numbers of cubes, the sum is different, since the number of 6-k (the largest numbers) is different.
So, we need to find out how many cubes can be used to set the sum s. It is clear that if s ≤ 6, then any number from 1 to s. But if s > 6, then one cube can no longer be specified. If s > 12 (6 * 2), then you can't even set two.
Those. if s > 6, subtract 1; if s > 12, subtract 2; if s > 18, then subtract 3.
Or, in other words, if s > 6k, subtract k. k can be calculated as (s - 1) / 6 (integer division). As soon as s becomes greater than 6k, i.e. becomes 6k + 1, we get (6k + 1 - 1) / 6 = k. If s = 6k, then (6k - 1) / 6 = k - 1, which is what we need.
That. result: s - (s - 1) / 6 which is equivalent to your formula since
(s + 5) / 6 = (s - 1) / 6 - 1
(s + 5) / 6 - 1 = (s - 1 ) / 6
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question