Page 1 of 1
10351 - Cutting Diamonds
Posted: Fri Aug 30, 2002 10:14 am
by Chung Ha, Yun
Sample outputs are Perfect.
But, I recieve WA, again.
My Solution is wrong?
[cpp]#include<stdio.h>
#define PI 3.14159265358979323846
double sqr(double a);
typedef struct _Coordinate
{
int x;
int y;
int z;
} Coordinate;
int main()
{
Coordinate Box[3], Diamond[3];
int i, j, count = 1;
bool first;
float min, result;
while(scanf("%d%d%d%d%d%d", &Box[0].x, &Box[0].y, &Box[0].z, &Diamond[0].x, &Diamond[0].y, &Diamond[0].z) > 0)
{
Box[2].z = Box[1].x = Box[0].y;
Box[2].x = Box[1].y = Box[0].z;
Box[2].y = Box[1].z = Box[0].x;
Diamond[2].z = Diamond[1].x = Diamond[0].y;
Diamond[2].x = Diamond[1].y = Diamond[0].z;
Diamond[2].y = Diamond[1].z = Diamond[0].x;
first = false;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(Box.x < Diamond[j].x && ((Box.y >= Diamond[j].y && Box.z >= Diamond[j].z) ||
(Box.y >= Diamond[j].z && Box.z >= Diamond[j].y)))
{
result = PI * (Diamond[j].y / 2.0) * (Diamond[j].z / 2.0) * (1 - sqr(Box.x - Diamond[j].x / 2.0) / sqr(Diamond.x / 2.0));
if(first == false)
{
min = result;
first = true;
}
else if(min > result)
min = result;
}
printf("Set #%d\n", count++);
printf("%.6f\n", min);
}
return 0;
}
double sqr(double a)
{
return a*a;
}[/cpp]
Judge Server is very Stupid...
Posted: Fri Aug 30, 2002 11:31 am
by Chung Ha, Yun
This source is Accept...
Very similar Code, But compare parameter(i, j) is different.
Judge Server is very very stupid..!!!
[cpp]
#include<stdio.h>
#define PI 3.14159265358979323846
double sqr(double a);
typedef struct _Coordinate
{
int x;
int y;
int z;
} Coordinate;
int main()
{
Coordinate Box[3], Diamond[3];
int i, j, count = 1;
bool first;
double min, result;
while(scanf("%d%d%d%d%d%d", &Box[0].x, &Box[0].y, &Box[0].z, &Diamond[0].x, &Diamond[0].y, &Diamond[0].z) > 0)
{
Box[2].z = Box[1].x = Box[0].y;
Box[2].x = Box[1].y = Box[0].z;
Box[2].y = Box[1].z = Box[0].x;
Diamond[2].z = Diamond[1].x = Diamond[0].y;
Diamond[2].x = Diamond[1].y = Diamond[0].z;
Diamond[2].y = Diamond[1].z = Diamond[0].x;
first = false, min = 0, result = 0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
if(Box[j].x < Diamond.x &&
((Box[j].y == Diamond.y && Box[j].z == Diamond.z) ||
(Box[j].y == Diamond.z && Box[j].z == Diamond.y)))
{
result = PI *
(Diamond[j].y / 2.0) *
(Diamond[j].z / 2.0) *
(1 - sqr(Box[j].x - Diamond.x / 2.0) / sqr(Diamond.x / 2.0));
if(first == false)
{
min = result;
first = true;
}
else if(min > result)
min = result;
}
printf("Set #%d\n", count++);
printf("%.6lf\n", min);
}
return 0;
}
double sqr(double a)
{
return a*a;
}
[/cpp]
Posted: Fri Aug 30, 2002 11:37 am
by Adrian Kuegel
You are only lucky to get Accepted with your second version, because you shouldn't minimize the cut-area in this problem (the direction of box and diamond cannot be changed), and if I understand your algorithm, you are doing it.
Posted: Mon Jun 28, 2004 9:19 am
by htl
Could someone give some critical data? I can't figure out what's wrong with my program. Btw, can I swap the only different pair
(6 7 4 6 8 4 -> 7 6 4 8 6 4) to solve in a convenient way?
Posted: Tue Jul 05, 2005 8:18 pm
by minskcity
Can anybody see what's wrong with this code? I'm getting WA....
Code: Select all
#include <iostream>
#include <math.h>
using namespace std;
typedef long double ld;
int a, b, c, aa, bb, cc;
ld getcut(ld mx, ld a, ld b, ld c){
ld d = abs(mx - a/2);
b *= 0.5*sqrt(1 - 4*d*d/(a*a));
c *= 0.5*sqrt(1 - 4*d*d/(a*a));
return 2*acos((ld)0.0)*c*b;
}
int main(){
cout.setf(ios::fixed);
cout.precision(6);
int test = 1;
while(cin >> a >> b >> c >> aa >> bb >> cc){
cout << "Set #" << test++ << endl;
if(aa > a) cout << getcut(a, aa, bb, cc) << endl;
else if(bb > b) cout << getcut(b, bb, aa, cc) << endl;
else if(cc > c) cout << getcut(c, cc, aa, bb) << endl;
else cout << 0.0 << endl;
}
return 0;
}
For the input
Code: Select all
7 6 4 8 6 4
4 8 8 8 8 8
17 18 19 17 18 19
16 18 19 17 18 19
17 17 19 17 18 19
17 18 18 17 18 19
15 18 19 17 18 19
17 16 19 17 18 19
17 18 17 17 18 19
14 18 19 17 18 19
17 15 19 17 18 19
17 18 16 17 18 19
1 18 19 17 18 19
17 1 19 17 18 19
17 18 1 17 18 19
7 18 19 17 18 19
17 8 19 17 18 19
17 18 9 17 18 19
8 18 19 17 18 19
17 9 19 17 18 19
17 18 6 17 18 19
My program gives:
Code: Select all
Set #1
8.246681
Set #2
50.265482
Set #3
0.000000
Set #4
59.483720
Set #5
53.242238
Set #6
47.933220
Set #7
111.531974
Set #8
100.220684
Set #9
90.540526
Set #10
156.144764
Set #11
140.935337
Set #12
127.821919
Set #13
59.483720
Set #14
53.242238
Set #15
47.933220
Set #16
260.241274
Set #17
250.551710
Set #18
239.666099
Set #19
267.676739
Set #20
253.683607
Set #21
207.710619
Can anybody who got AC verify it for me?
Posted: Sat Dec 31, 2005 6:33 pm
by daveon
Hi,
I get the same output as you.
Posted: Thu Jan 05, 2006 3:55 am
by Emilio
To minskcity:
change abs(mx - a/2) by fabs(mx - a/2) and will get AC.
Posted: Wed Sep 13, 2006 3:40 am
by minskcity
Emilio wrote:To minskcity:
change abs(mx - a/2) by fabs(mx - a/2) and will get AC.
Thanks! Changing math.h to cmath also helps

Posted: Thu Aug 09, 2007 12:40 pm
by sohel
This code gets wrong answer!!
- There is no correction program written for this problem, so I am guessing precision problem!!
- I also get correct output for the input posted above.
- I tried using long double too, but no luck!
Code: Select all
--x Code removed x--
Though unnecessary!!! AC code is posted above. :P
Edit:: no problem with precision.
Posted: Thu Aug 09, 2007 2:04 pm
by little joey
Quite strange indeed. I created an exhaustive test file containing all possible legal cases this way:
Code: Select all
#include <stdio.h>
int main(){
int i1,i2,i3,j1,j2,j3;
for(j1=1;j1<20;j1++){
for(j2=1;j2<20;j2++){
for(j3=1;j3<20;j3++){
for(i1=1;i1<=j1;i1++) printf("%d %d %d %d %d %d\n",i1,j2,j3,j1,j2,j3);
for(i2=1;i2<=j2;i2++) printf("%d %d %d %d %d %d\n",j1,i2,j3,j1,j2,j3);
for(i3=1;i3<=j3;i3++) printf("%d %d %d %d %d %d\n",j1,j2,i3,j1,j2,j3);
}
}
}
return 0;
}
and then ran both our codes with it. Guess what: no differences.
So maybe the judge input contains illegal cases like "0 3 6 2 3 6" and "1 2 3 2 3 4" or even "1 2 3 1 2 2"? Should be easy to check with assert.
If the judge input is indeed rotten, and you feel like it, you could write a new one. I could PM you my accepted code. The approach is somewhat different, but the results should be the same.
:-?
Posted: Fri Aug 10, 2007 1:47 pm
by sohel
Just got Accepted!!!
It seems that there are some inputs in which [:: x_box > x_diamond | y_box > y_diamond | z_box > z_diamond ::]
Output for those cases should be '0.000000'.
After rereading the problemstatement, it doesn't say that the box can't be bigger than the diamond. So, I guess, the data is correct.
