10215 - The Largest/Smallest Box ...

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

Moderator: Board moderators

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo »

Try this..


PS) Remove you code after AC.. :-)
Last edited by helloneo on Tue Feb 26, 2008 5:03 am, edited 1 time in total.
fR0D
New poster
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am
Contact:

Post by fR0D »

thnx very much...
hasib_bd
New poster
Posts: 14
Joined: Wed Apr 30, 2008 12:39 pm

Re: 10215 - The Largest/Smallest Box...

Post by hasib_bd »

Hi Jan,
Don't know whether you'll notice this post on this old fat issue. This is my first posting in this forum. Thanks a million for your info on eps without which i possibly could never get the problem accepted.
sijal
New poster
Posts: 9
Joined: Fri Jul 18, 2008 12:10 pm
Location: Iran-shiraz
Contact:

Re: 10215 - The Largest/Smallest Box...

Post by sijal »

add results to epsilon and then print them
thanks jan
Learn to swim.
cyclops_kun
New poster
Posts: 4
Joined: Mon Dec 08, 2008 11:03 am

I got AC in UVa judge, but i got WA in Programming-challenge

Post by cyclops_kun »

Please Help..
I got AC in UVa judge, but why i got WA in http://www.programming-challenges.com judge? I don't understand..
I'm sorry posting my AC code here :-? , but, for me it's still WA :cry: , coz it's WA in programming-challenges, please help..thanks in advance.. :)

Here is my code, for anyone who got AC, please try at http://www.programming-challenges.com and please tell me why i got WA there?

Code: Select all

#include<iostream>
#include<iomanip>
#include<cmath>
#define eps 1e-7
using namespace std;

int main()
{
    double L, W, min, max, vol1, vol2, x, a;
    
    cout<<fixed<<showpoint<<setprecision(3);
    while(cin>>L>>W)
    {
        if(W>L)
        {
           a=W;
           W=L;
           L=a;
        }
        min=(L+W-sqrt(L*L+W*W-L*W))/6;
        max=(L+W+sqrt(L*L+W*W-L*W))/6;
        vol1=(L-2*min)*(W-2*min)*(min);
        vol2=(L-2*max)*(W-2*max)*(max);
        if(vol1>vol2)
           x=min;
        else
           x=max;
        
        cout<<x+eps<<" 0.000 "<<(W/2.0)+eps<<endl;
    }    
    
    return 0;
}

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10215 - The Largest/Smallest Box...

Post by Obaida »

Some one please tell me where is my wrong..

Code: Select all

shame!!!
Last edited by Obaida on Mon Feb 09, 2009 5:49 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 10215 - The Largest/Smallest Box...

Post by newkid »

@obaida
please see the previous post of sijal. and please read the existing posts first before posting your code.
hmm..
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10215 - The Largest/Smallest Box...

Post by Obaida »

Thank you very much.... :)
m sorry for my previous post. I always read and check the input outputs. But this time i posted cause i thought it was a different method. So didn't tried with that post :oops: :oops: :oops:
try_try_try_try_&&&_try@try.com
This may be the address of success.
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10215 - The Largest/Smallest Box...

Post by plamplam »

Thanks a lot jan....forgot to add 1e-8 before :x :x
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
facug91
New poster
Posts: 6
Joined: Sat Apr 26, 2014 10:32 pm

Re: 10215 - The Largest/Smallest Box ...

Post by facug91 »

Can't this be solve with ternary search? I've made it in that way, and all the test cases I've proved pass perfectly. Anyway, I'm getting WA over and over. Here's my code:

Code: Select all

#include <bits/stdc++.h>
#define EPS 1e-9
using namespace std;

double l, w;

double f (double x) {
	return x*(l-x-x)*(w-x-x);
}
double ternary_search () {
	double lo = EPS, hi = (((l<w)?l:w)/2.0)-EPS, mid1, mid2;
	for (int i=0; i<100; i++) {
		mid1 = lo + (hi-lo)/3.0;
		mid2 = hi - (hi-lo)/3.0;
		if (f(mid1) > f(mid2)) {
			hi = mid2;
		} else if (f(mid1) < f(mid2)) {
			lo = mid1;
		} else {
			hi = mid2;
			lo = mid1;
		}
	}
	return hi;
}

int main () {
	
	while (scanf("%lf %lf", &l, &w) != EOF) {
		printf("%.03lf 0.000 %.03lf\n", ternary_search()+EPS, (((l<w)?l:w)/2.0)+EPS);
	}
	
	return 0;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10215 - The Largest/Smallest Box ...

Post by brianfry713 »

Input:

Code: Select all

1274.382 1730.007
2026.413 6118.988
7991.324 9829.049
5410.375 9913.369
2472.286 396.850
9434.268 4454.616
6352.057 1577.481
7499.066 4945.733
5306.623 5587.539
4135.518 2873.061
7667.054 8370.681
6616.079 577.286
152.881 1744.800
5133.932 5320.197
8991.519 8837.041
7822.370 2782.038
567.048 9848.782
8901.026 8558.372
9677.832 6827.538
987.879 4666.255
9740.524 422.147
9120.870 8608.718
4515.764 6619.936
3554.451 9822.387
4723.612 7689.969
5211.585 4906.803
8576.787 1827.665
5484.089 8729.667
6088.601 3134.158
6566.002 5080.120
1971.199 4388.372
378.295 5054.384
6753.292 1795.458
6128.893 6431.124
8622.995 7116.771
1097.379 8363.519
55.056 2734.386
9488.374 4570.819
9354.321 3042.826
6909.343 6594.070
3248.932 2120.929
1500.874 4341.856
3948.593 9501.099
3071.524 2553.331
2635.257 2153.663
149.588 7122.593
6542.034 527.882
4693.114 3295.326
2323.340 822.007
2242.587 946.335
454.915 5856.102
1825.992 509.970
8590.487 1314.366
5080.789 460.946
6873.328 1990.132
9571.153 2638.397
6627.197 3588.164
9496.390 3091.927
3089.263 2567.914
5645.257 8240.656
4721.576 5794.844
7879.386 3779.747
6322.726 2572.500
9591.210 8646.065
5910.643 4349.934
2108.537 6365.558
206.037 6450.665
6875.527 1312.661
281.169 4472.453
1773.607 7154.496
6462.585 1344.760
2309.031 5605.919
4932.923 1805.421
8697.846 538.323
6889.471 4343.103
8778.978 4127.184
137.948 9174.502
423.068 8976.810
4263.139 14.278
139.013 173.783
4364.212 2247.549
6539.340 7086.385
8698.214 5931.004
8399.045 1495.520
403.458 2688.789
8650.015 9382.179
4033.548 3475.183
4988.098 1482.608
7796.740 6202.081
2020.930 7202.348
545.185 3316.046
1329.532 3199.269
5006.685 4268.737
4692.216 9269.823
4283.014 4831.228
9443.605 1163.363
9594.913 8499.082
8249.747 8293.127
6946.224 9164.930
9788.646 7349.681
AC output:

Code: Select all

241.873 0.000 637.191
457.740 0.000 1013.207
1461.528 0.000 3995.662
1121.089 0.000 2705.188
94.908 0.000 198.425
952.392 0.000 2227.308
366.823 0.000 788.741
973.529 0.000 2472.867
906.942 0.000 2653.312
556.282 0.000 1436.531
1332.625 0.000 3833.527
141.035 0.000 288.643
37.346 0.000 76.441
870.763 0.000 2566.966
1485.546 0.000 4418.521
622.763 0.000 1391.019
139.662 0.000 283.524
1454.109 0.000 4279.186
1315.239 0.000 3413.769
232.502 0.000 493.940
104.368 0.000 211.074
1475.618 0.000 4304.359
879.539 0.000 2257.882
793.814 0.000 1777.226
949.361 0.000 2361.806
842.052 0.000 2453.402
429.956 0.000 913.833
1095.207 0.000 2742.045
658.185 0.000 1567.079
947.095 0.000 2540.060
425.432 0.000 985.600
92.737 0.000 189.148
415.042 0.000 897.729
1045.759 0.000 3064.447
1293.752 0.000 3558.386
264.749 0.000 548.690
13.694 0.000 27.528
973.365 0.000 2285.410
688.809 0.000 1521.413
1124.365 0.000 3297.035
418.790 0.000 1060.465
337.223 0.000 750.437
863.752 0.000 1974.297
462.808 0.000 1276.666
393.068 0.000 1076.832
37.199 0.000 74.794
129.200 0.000 263.941
635.802 0.000 1647.663
184.135 0.000 411.004
206.487 0.000 473.168
111.434 0.000 227.458
117.343 0.000 254.985
315.051 0.000 657.183
112.503 0.000 230.473
456.290 0.000 995.066
607.849 0.000 1319.199
744.913 0.000 1794.082
699.847 0.000 1545.964
465.463 0.000 1283.957
1098.032 0.000 2822.629
862.782 0.000 2360.788
805.585 0.000 1889.874
564.669 0.000 1286.250
1513.662 0.000 4323.033
825.871 0.000 2174.967
476.278 0.000 1054.269
51.091 0.000 103.019
310.991 0.000 656.331
69.153 0.000 140.585
412.491 0.000 886.804
316.864 0.000 672.380
505.837 0.000 1154.516
402.578 0.000 902.711
132.434 0.000 269.162
866.477 0.000 2171.552
883.137 0.000 2063.592
34.356 0.000 68.974
104.491 0.000 211.534
3.567 0.000 7.139
25.588 0.000 69.507
471.946 0.000 1123.775
1132.735 0.000 3269.670
1155.340 0.000 2965.502
355.739 0.000 747.760
96.794 0.000 201.729
1498.971 0.000 4325.008
620.559 0.000 1737.592
339.010 0.000 741.304
1144.078 0.000 3101.041
464.800 0.000 1010.465
130.229 0.000 272.593
290.836 0.000 664.766
765.647 0.000 2134.369
988.989 0.000 2346.108
755.409 0.000 2141.507
281.326 0.000 581.682
1499.560 0.000 4249.541
1378.559 0.000 4124.874
1304.932 0.000 3473.112
1385.447 0.000 3674.841
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 102 (10200-10299)”