ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1550. Пирамида декана 3

WA with cout AC with printf
Послано jagatsastry 24 ноя 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
Послано Santa (Volgograd SU ) 24 ноя 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
Послано vav 9 апр 2008 21:08
there is mistake in c++ code

Edited by author 09.04.2008 21:14
Re: C++ and Java
Послано SHY 9 апр 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
Послано Oleg Strekalovsky [Vologda SPU] 11 май 2009 21:51
Santa (Volgograd SU ) писал(a) 24 ноября 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
Послано 198808xc 11 окт 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.