Test instructions: Three items each have a B C (a<=b<=c), and now each item is selected to be combined. Requires each of the most and most occurrences. The total number of combinations of any two items required in all three combinations must not exceed N.
Ask for a scheme that allows us to generate the largest number of combinations.
Analysis:
First, we can simply deal with a situation, that is, the situation of c<=n.
Because we cite all the combinations, the maximum number of occurrences of the two items will not exceed C, because each pair of a and B will appear in the C, and the remaining two combinations appear less frequently.
So this situation must not exceed N, we just need to enumerate all the combinations.
However, for the case of c>n, if we enumerate n times for each AB item pair,
We must reasonably allocate the corresponding C items to these ab pairs, otherwise the AC or BC item pairs are likely to surpass N times. So the problem is not very simple to solve.
No matter how we enumerate, our total number of combinations cannot exceed axbxn. Otherwise, some AB items will inevitably appear more than N.
And because a B is less than C, A*b*n is the upper bound of the answer we seek.
Now there is a construction method to ensure that for any c>n situation, a a*b*n legal combination number is constructed.
The method is to construct a cube with a length-width height of ABC, which is stacked by the 1x1x1 small cube, each of which corresponds to a three-item combination.
We're going to pick the most squares from them.
The limit of n can be expressed as the number of squares selected in each x, Y, and z-axis direction cannot exceed N.
Let us first construct this planar cube of the a=1. In the C-cube of this line of b=1, we select the 1~n (n<c) to add the answer.
As b grows, we translate this selection interval to the right. B=x x~ (n+x)%c. Because of the b<c, this interval completes at most one translation cycle.
For a=1 this plane, each row does not have more than n selected per column.
Next we'll build the plane of each b=x, with a plane like B.
For each plane, the method is the same as before, for a row of a=1 we select the 1~n interval, and the interval is shifted as a grows.
For a=y this line, the selection interval is y~ (n+y)%c. In the same vein as before, it must be legal.
Now ensure that all C-direction lines are selected with a quantity less than or equal to N. The number of rows in a direction is less than or equal to N. But in the B-direction line, we only guarantee the less than or equal to N in the a=1 plane.
But don't worry, because the rest of the B-direction is legal, because our method of construction is equivalent to translating the plane of A=1 into a B-direction as a grows.
In this way, the construction is completed, and the coordinates of the selected cube are found so that the output can be achieved.
#include <cstdio>#include<algorithm>using namespacestd;intA, B, C, n;voidWork () {if(c <=N) {printf ("%d\n", A * b *c); for(inti =1; I <= A; i++) for(intj =1; J <= B; J + +) for(intK =1; K <= C; k++) printf ("%d%d%d\n", I, J, K); return; } printf ("%d\n", A * b *N); for(inti =0; i < A; i++) for(intj =0; J < b; J + +) for(intK = i + j; K < i + j + N; k++) {printf ("%d%d%d\n", i +1, J +1, K% c +1); }}intMain () {intT; scanf ("%d", &t); intCase_num =0; while(t--) {Case_num++; printf ("Case #%d:", Case_num); scanf ("%d%d%d%d", &a, &b, &c, &N); Work (); } return 0;}View Code
Google Code Jam Round 1C C