Zoj 1093 monkeys and bananas

Source: Internet
Author: User

//////////////////////////////////////// /////////////////////////////
// Monkey and banana
// Convert each square into three. Sort them first, and then use the DP of N ^ 2.
# Include <iostream>
# Include <algorithm>
Using namespace STD;

 

Struct Block
{
Int X;
Int y;
Int height;
} BL [100];

Void maxmin (Int & A, Int & B, Int & C)
{
If (A <B & A <C)
If (B <C );
Else swap (B, c );
Else if (B <C & B <)
{
Swap (A, B );
If (B <C );
Else swap (B, c );
}
Else
{
Swap (a, c );
If (B <C );
Else swap (B, c );
}
}

Bool comp (const block & A, const block & B)
{
If (A. X! = B. X) Return (A. x <B. X );
Else return (A. Y <= A. Y );
}

Int main ()
{
Int I, j, n, a, B, c, Count = 1, Max;
While (CIN> N & n! = 0)
{
For (I = 1; I <= 3 * n; I = I + 3)
{
Cin> A> B> C;
Maxmin (A, B, C );
BL [I]. x =;
BL [I]. Y = B;
BL [I]. Height = C;

BL [I + 1]. x =;
BL [I + 1]. Y = C;
BL [I + 1]. Height = B;

BL [I + 2]. x = B;
BL [I + 2]. Y = C;
BL [I + 2]. Height =;
}
BL [0]. x = bl [0]. Y = bl [0]. Height = 0;
Sort (BL, BL + 3 * n + 1, comp );
For (I = 1; I <= 3 * n; I ++)
{
Max = 0;
For (j = 0; j <I; j ++)
{
If (BL [I]. x> BL [J]. X & BL [I]. y> BL [J]. Y & BL [J]. height> MAX)
Max = bl [J]. height;
}
BL [I]. height + = max;
}

Max = 0;
For (I = 1; I <= 3 * n; I ++)
If (BL [I]. Height> MAX)
Max = bl [I]. height;

Cout <"case" <count <": maximum height =" <max <Endl;
Count ++;
}
Return 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.