Code: Select all
PS) Remove you code after AC..
![:-)](./images/smilies/icon_smile.gif)
Moderator: Board moderators
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;
}
Code: Select all
shame!!!
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;
}
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
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