HDU 2600 -- War

Source: Internet
Author: User

Looking at the time and memory, I thought I was going to use some storage structures. The results were circled, and finally I solved it with simple knowledge such as sorting .. Sometimes it is good to be optimistic ..


[Cpp]
# Include <iostream>
# Include <cstring>
# Include <string>
# Include <algorithm>
Using namespace std;
 
Class war
{
Public:
Int starttime;
Int endtime;
Bool vis;
};
 
Bool cmp (war a, war B)
{
If (a. endtime! = B. endtime)
Return B. endtime> a. endtime;
Else
Return a. starttime> B. starttime;
}
 
War tar [150];
 
Int main ()
{
Int testcase;

While (cin> testcase)
{
Memset (tar, 0, sizeof (tar ));
String tmp;
Int res = 0;
Int flag = 0;
Int stp, edp;
Cin> stp> edp;
For (int I = 0; I <testcase; I ++)
{
Cin> tar [I]. starttime> tar [I]. endtime;
Getline (cin, tmp );
Tar [I]. vis = 0;
}
Sort (tar, tar + testcase, cmp );
If (tar [0]. endtime <edp)
{
Cout <edp <endl;
Continue;
}
For (int I = 0; I <testcase; I ++)
{
If (tar [I]. endtime> = res)
{
If (res> = tar [I]. starttime)
Res = tar [I]. starttime;
}
Else
{
Flag = 1;
Break;
}
}
If (flag = 1)
Cout <res-1 <endl;
Else
Cout <"Badly! "<Endl;


}
Return 0;
}

# Include <iostream>
# Include <cstring>
# Include <string>
# Include <algorithm>
Using namespace std;

Class war
{
Public:
Int starttime;
Int endtime;
Bool vis;
};

Bool cmp (war a, war B)
{
If (a. endtime! = B. endtime)
Return B. endtime> a. endtime;
Else
Return a. starttime> B. starttime;
}

War tar [150];

Int main ()
{
Int testcase;
 
While (cin> testcase)
{
Memset (tar, 0, sizeof (tar ));
String tmp;
Int res = 0;
Int flag = 0;
Int stp, edp;
Cin> stp> edp;
For (int I = 0; I <testcase; I ++)
{
Cin> tar [I]. starttime> tar [I]. endtime;
Getline (cin, tmp );
Tar [I]. vis = 0;
}
Sort (tar, tar + testcase, cmp );
If (tar [0]. endtime <edp)
{
Cout <edp <endl;
Continue;
}
For (int I = 0; I <testcase; I ++)
{
If (tar [I]. endtime> = res)
{
If (res> = tar [I]. starttime)
Res = tar [I]. starttime;
}
Else
{
Flag = 1;
Break;
}
}
If (flag = 1)
Cout <res-1 <endl;
Else
Cout <"Badly! "<Endl;


}
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.