Editorial for Tam giác cân (THT TP 2018)
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
\(\color{red}{\text{Spoiler Alert}_{{}_{{}^{{}^{v2.0}}}}}\)
\(\color{red}{\text{Khuyến khích bạn đọc trước khi đọc phần lời giải xin hãy thử code ra thuật của mình dù nó có sai hay đúng}}\)
\(\color{red}{\text{Sau đó từ phần bài giải và thuật toán trước đó mà đối chiếu, rút nhận xét với thuật của mình và thu được bài học (không lãng phí thời gian đâu).}}\)
\(\color{orange}{\text{Hint <Implementation>}}\)
- Đề yêu cầu tìm tam giác cân nên phải có ít nhất 2 cạnh bằng nhau
Có 2 cách chọn, ta thử từng cách và xuất kết quả có diện tích lớn nhất
Dễ thấy diện tích càng lớn khi 1 cạnh càng lớn nên ta sẽ chọn cạnh lớn nhất mà làm tam giác cân
\(\color{green}{\text{Preference AC Code }}\): Implementation
\(^{^{\color{purple}{\text{Complexity : }} O(1)\ \color{purple}{\text{time}}\ ||\ O(1)\ \color{purple}{\text{memory}}}}\)
C++
int main()
{
int x, y;
cin >> x >> y;
cout << max(x, y);
return 0;
}
\(\color{green}{\text{Preference AC Code }}\): Implementation
\(^{^{\color{purple}{\text{Complexity : }} O(1)\ \color{purple}{\text{time}}\ ||\ O(1)\ \color{purple}{\text{memory}}}}\)
C++
int readInt() { int x; return cin >> x, x; }
int main()
{
cout << max(readInt(), readInt());
return 0;
}
Comments (1)