This question is actually not difficult. I wa it during the game yesterday and asked my teammates about it. It turned out to be a rectangular cut.
Problem 3634 62 Ms 224 K
The idea of this question: Use the endpoint of the rectangle as the intersection to split all the rectangles into small rectangles. The vertices here must not be repeated and in ascending order. It is very convenient to use set (equivalent to discretization ).
Then, sort the original rectangle in descending order of values, color all the rectangle blocks covered by each rectangle that have not been colored, and calculate the sum of values, that is, the result.
You can use two points to find the small rectangular block covered by a rectangle. However, if the data size of this question is small, you can use linear scanning.
In addition, I initially defined the result as long type and submitted WA with G ++. Then, define the result as _ int64, use C ++, and shine the AC!
# Include < Iostream >
# Include < Set >
Using Namespace STD;
Struct Rect {
Int X1, Y1, X2, Y2, V;
} R [ 22 ];
Set < Int > Col [ 2 ];
Int Map [ 50 ] [ 50 ], Xcol [ 50 ], Ycol [ 50 ], Xnum, ynum;
Int CMP ( Const Void * A, Const Void * B)
{
Struct Rect * AA = ( Struct Rect * );
Struct Rect * Bb = ( Struct Rect * ) B;
Return Bb -> V - AA -> V;
}
Int Findx ( Int A)
{
For ( Int I = 0 ; I < Xnum; I ++ )
If ( = Xcol [I])
Return I;
}
Int Findy ( Int A)
{
For ( Int I = 0 ; I < Ynum; I ++ )
If ( = Ycol [I])
Return I;
}
Int Main ()
{
Int CAS, CA, N, I, J, K;
_ Int64 ans;
Int SX, Sy, ex, ey;
Scanf ( " % D " , & CAS );
For (CA = 1 ; CA <= CAS; CA ++ )
{
Col [ 0 ]. Clear ();
Col [ 1 ]. Clear ();
Scanf ( " % D " , & N );
For (I = 0 ; I < N; I ++ )
{
Scanf ( " % D " , & R [I]. X1, & R [I]. Y1, & R [I]. X2, & R [I]. Y2, & R [I]. V );
Col [ 0 ]. Insert (R [I]. X1); Col [ 0 ]. Insert (R [I]. x2 );
Col [ 1 ]. Insert (R [I]. Y1); Col [ 1 ]. Insert (R [I]. Y2 );
}
Qsort (R, n, Sizeof (R [ 0 ]), CMP );
Memset (map, 0 , Sizeof (MAP ));
Xnum = Ynum = 0 ;
Set < Int > : Iterator it;
For (It = Col [ 0 ]. Begin (); it ! = Col [ 0 ]. End (); it ++ )
Xcol [xnum ++ ] = * It;
For (It = Col [ 1 ]. Begin (); it ! = Col [ 1 ]. End (); it ++ )
Ycol [ynum ++ ] = * It;
/* For (I = 0; I <xnum; I ++)
Printf ("% d", xcol [I]);
Puts ("");
For (I = 0; I <ynum; I ++)
Printf ("% d", ycol [I]);
Puts (""); */
Printf ( " Case % d: " , CA );
Ans = 0 ;
For (I = 0 ; I < N; I ++ )
{
SX = Findx (R [I]. X1); Ex = Findx (R [I]. x2 );
Sy = Findy (R [I]. Y1); ey = Findy (R [I]. Y2 );
// Printf ("% d \ n", Sx, xcol [SX], Sy, ycol [sy]);
// Printf ("% d \ n", ex, xcol [Ex], ey, ycol [ey]);
// Printf ("% LLD \ n", (_ int64) (R [I]. V ));
For (J = SX; j < Ex; j ++ )
{
For (K = Sy; k < Ey; k ++ ){
If (Map [J] [k] = 0 )
{
Map [J] [k] = 1 ;
Ans + = (_ Int64) (xcol [J + 1 ] - Xcol [J]) * (_ Int64) (ycol [K + 1 ] - Ycol [k]) * (_ Int64) (R [I]. V );
// Printf (" // % D \ n ", (xcol [J + 1]-xcol [J]), (ycol [k + 1]-ycol [k]), (R [I]. v), ANS );
}
}
}
}
Printf ( " % I64d \ n " , ANS );
}
Return 0 ;
}
Yesterday's competition was conducted on multiple schools (19th) and ended in a tragedy! Give me the general meaning of each question, and I will recall it later ......
3632 duel question DP
3635. The simplest question of the query set
3636 optimal search
3637 find a denominator and the smallest number of fractional numbers in the interval
3638 you should also use search to solve it. The view of the monster will move and bite the pen ......
3639 graph-based connection problem of an e catching chicken