10725 - Triangular Square

All about problems in Volume 107. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post by w k »

Hi,

Could somebody post more I/O? I'm still getting WA.

Thanks

Wojciech
w k
Learning poster
Posts: 74
Joined: Wed Apr 14, 2004 11:14 pm

Post by w k »

OK!

I got it.

Wojciech
pureza
New poster
Posts: 1
Joined: Tue Feb 22, 2005 7:47 am
Location: South Korea

10725...WA.. Help~~~

Post by pureza »

Code: Select all

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
        int T[3],i,t;
        double l1,l2,m,h,s,p,r;

        cin >> t;
        while ( t-- )
        {
                cin >> T[0] >> T[1] >> T[2];

                p = (T[0]+T[1]+T[2]) / 2.0;
                s = sqrt( p*(p-T[0])*(p-T[1])*(p-T[2]) );

                // r  - Maximum Triangle Edge
                r = 0;
                for ( i = 0 ; i < 3 ; i++ )
                {
                        h = 2.00*s / (double)T[i];
                        m = T[i]*h / (double)(T[i]+h);

                        l1 = sqrt(T[(i+1)%3]*T[(i+1)%3] - (h*h));
                        l2 = sqrt(T[(i+2)%3]*T[(i+2)%3] - (h*h));

                        // If it is Obtuse Triangle..
                        // Reduce R by l1, l2
                        if ( l1 > T[i] )
                                m = T[i]*h / (h+l1);
                        else if ( l2 > T[i] )
                                m = T[i]*h / (h+l2);

                        r = max(r,m);
                }
                printf("%.6lf\n",(r*r));
        }
}
[/code]
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho »

Could someone please verify this I/O ?

INPUT

Code: Select all

6
500 500 500
881 855 30
868 866 3
999 998 2
990 993 7
992 991 2
OUTPUT

Code: Select all

53847.577293
210.276309
4.962898
2.986635
39.376414
2.986541
Thanks in advance!
schindlersp
New poster
Posts: 28
Joined: Tue Aug 03, 2004 8:11 pm
Contact:

10725

Post by schindlersp »

My AC:

53847.577293
210.276309
4.962898
2.986635
39.376414
2.986541
Cosmin.ro
Learning poster
Posts: 95
Joined: Thu Aug 21, 2003 12:02 am

Post by Cosmin.ro »

I solved the problem some time ago assuming that one edge of the square is on one edge of the triangle, but I can't prove this ... Does anyone have a proof?
sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo »

First, observe that the largest square must have at least a corner on all 3 sides of the triangle, then using proper parametrization, we can show using calculus that the only local maxima are when at least a side of the square lies on triangle.
Post Reply

Return to “Volume 107 (10700-10799)”