|
|
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.htmlsubtract the second from the first. 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! there is mistake in c++ code Edited by author 09.04.2008 21:14 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. 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! In Santa's code above, change cin>>w>>h to cin>>h>>w will be OK. That's really a small but serious bug. double res = w*w*h/3-h*3.14159265*r*r*(w-2*fabs((((y >= x && y >= -x) || (y < x && y < -x)) ? y : x)))/w; The task is to find a volume of Piramid - volume of cylindr ? CAn you tell me the FORMULA? It is very easy))) double res = sqr(w)*h/3-h*pi*sqr(r)*(w-2*fabs((((y >= x && y >= -x) || (y < x && y < -x)) ? y : x)))/w; What procedure fabs does? abs (absolute value) for float. How can you solve it so easy? It is very easy))) double res = sqr(w)*h/3-h*pi*sqr(r)*(w-2*fabs((((y >= x && y >= -x) || (y < x && y < -x)) ? y : x)))/w; Why is minus? ..w-2*fabs.. Can you give me some test data? I just finding volume of the pyramid and deducting volume of truncated cylinder, but getting WA (4 test). Can anyone to give me a prompting (not solving :)), please? I found mistake! I took PI=3.1415926535 instead 3.14159 and get AC :) Hello. I know this topic hasn't any connection with problem 1550, but it is the only way to post my request. I am interested if there's a way to get the "Tuymaada", Yakutsk (I'm sorry if I did not spell it right) task from 2000 to 2006 (at computer science, of course). I would be very grateful if someone could help me with this problem. My email is fireatmyself@yahoo.com. Thank you very much, Bogdan A. Stoica Edited by author 30.05.2007 22:16 I've got the trace of 2000, 2001 and 2002 subjects. Only need from 2003 to 2006. Thanks again :) CAn You give me 2 test. I have WA test #2. |
|
|