10351 - Cutting Diamonds

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

Moderator: Board moderators

Post Reply
Chung Ha, Yun
New poster
Posts: 19
Joined: Tue Jul 16, 2002 5:56 pm
Location: Seoul
Contact:

10351 - Cutting Diamonds

Post 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]

Chung Ha, Yun
New poster
Posts: 19
Joined: Tue Jul 16, 2002 5:56 pm
Location: Seoul
Contact:

Judge Server is very Stupid...

Post 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]

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post 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.

htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

Post 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?

minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post 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?

daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

Hi,

I get the same output as you.

Emilio
Experienced poster
Posts: 163
Joined: Sun Oct 17, 2004 8:31 pm
Location: Murcia, Spain

Post by Emilio »

To minskcity:
change abs(mx - a/2) by fabs(mx - a/2) and will get AC.

minskcity
Experienced poster
Posts: 199
Joined: Tue May 14, 2002 10:23 am
Location: Vancouver

Post 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 8)

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post 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.
Last edited by sohel on Fri Aug 10, 2007 1:49 pm, edited 1 time in total.

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post 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.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

:-?

Post 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. :)

Post Reply

Return to “Volume 103 (10300-10399)”