You are not logged in. Please login at www.codechef.com to post your questions!

×

What is wrong with my code for long challenge problem Appy and Balloons?

Problem Link

Previous solution link

My above solution is running for some cases i.e., it was partially accepted , I made a small change in the code in Line 54: temp+=(Math.ceil( ((float) (C[i]-mid))/(float)B[i]));

changed to

temp=temp-(mid/B[i])+A[i];

After doing this I got AC for all cases

New solution link

Please can anyone tell me why is this happening

asked 22 Oct '18, 13:09

deermen001's gravatar image

3★deermen001
484
accept rate: 9%


In C/C++ , ceil() uses "double" type as its argument and returns "double" as well.Here, the value which is the argument of ceil() (c[i]-mid) can be as large as 10^18 which exceeds the range of "double". Hence,ceil() returns unexpected value and you got WA for large numbers (The case is same in Java)

link

answered 22 Oct '18, 14:13

utkarsh911's gravatar image

5★utkarsh911
9518
accept rate: 0%

I tried it for 10^18 in c++ it's returning 1e+09 when i use ceil and 1000000000 when i am using other approach

(24 Oct '18, 02:19) deermen0013★

Can you share your code? Anyway,

#include <bits/stdc++.h>
using namespace std;

int main()

{

long double c=1000000000000000000.76;

cout << ceil(c) <<endl;

}

This won't output 1000000000000000001. Instead will output 1000000000000000000 (1e+18)

PS: Don't trust floating point numbers. They can't be stored/represented accurately and they betray when you need them the most :/

(25 Oct '18, 12:36) utkarsh9115★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×376
×202

question asked: 22 Oct '18, 13:09

question was seen: 235 times

last updated: 25 Oct '18, 12:41