ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1550. Dean's Pyramid 3

WA with cout AC with printf
Posted by jagatsastry 24 Nov 2007 01:28
This is terribly hilarious people. No precision details have been given in the question. Yet printf("%.5f",val); worked but cout<<val; didnt(WA#4).

BTW the method i followed is:
Find the volume of the pyramid vol(h,w)=hw*w/3 (i got it by integrating the squares at heights from 0 to h)
Find the volume of the truncated cylinder using the method given in
http://mathworld.wolfram.com/CylindricalSegment.html
subtract the second from the first.
C++ and Java
Posted by Santa (Volgograd SU ) 24 Nov 2007 05:17
I couldnt accept this task in C++.

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
   double w,h,x,y,r,t;
   cin >> w >> h >> x >> y >> r;
   x = fabs(x);
   y = fabs(y);
   if ( y > x ) x = y;
   printf("%.5lf", h * w * w / 3.0 - h * 3.14159265358979 * r * r * ( w/2 - x ) / (w/2));
   return 0;
}

take WA3, but analogical



import java.io.*;
import java.util.*;

public class Problem1550 {

 /**
  * @param args
  */
 public static void main(String[] args)
 throws IOException
 {
  Scanner in=new Scanner(System.in);
  //Scanner in=new Scanner(new File("input.txt"));
  PrintWriter out=new PrintWriter(System.out);
  double h,w,x,y,r;
  h=in.nextDouble();
  w=in.nextDouble();
  x=in.nextDouble();
  y=in.nextDouble();
  r=in.nextDouble();
  x=Math.abs(x);
  y=Math.abs(y);
  if(y>x)x=y;
  w=h*w*w/3-(Math.PI*r*r*(h*(w/2-x)/(w/2)));
  out.println(Double.toString(w));
  out.flush();
 }
}

in Java - accepted. I hate this problem!
Re: C++ and Java
Posted by vav 9 Apr 2008 21:08
there is mistake in c++ code

Edited by author 09.04.2008 21:14
Re: C++ and Java
Posted by SHY 9 Apr 2008 21:12
Here is a very fool mistake in C++ code but Java code is alright. I made this mistake in my Pascal code but then i read the problem attentively and found it.
Re: C++ and Java
Posted by Oleg Strekalovsky [Vologda SPU] 11 May 2009 21:51
Santa (Volgograd SU ) wrote 24 November 2007 05:17
import java.io.*;
import java.util.*;

public class Problem1550 {

 /**
  * @param args
  */
 public static void main(String[] args)
 throws IOException
 {
  Scanner in=new Scanner(System.in);
  //Scanner in=new Scanner(new File("input.txt"));
  PrintWriter out=new PrintWriter(System.out);
  double h,w,x,y,r;
  h=in.nextDouble();
  w=in.nextDouble();
  x=in.nextDouble();
  y=in.nextDouble();
  r=in.nextDouble();
  x=Math.abs(x);
  y=Math.abs(y);
  if(y>x)x=y;
  w=h*w*w/3-(Math.PI*r*r*(h*(w/2-x)/(w/2)));
  out.println(Double.toString(w));
  out.flush();
 }
}
Your solution is not right.
I use
out.printf(Locale.US,"%.4f",(piramideVolume-cylindricalSegmentVolume));

to get AC!
Re: C++ and Java
Posted by 198808xc 11 Oct 2010 15:25
In Santa's code above, change
cin>>w>>h
to
cin>>h>>w
will be OK.

That's really a small but serious bug.