epsilon_573's blog

By epsilon_573, history, 18 months ago, In English

I have tried 20-30 times , using floor() and type casting but I can't seem to get AC. What is the problem here? Thanks for the help.

Problem : https://atcoder.jp/contests/abc169/tasks/abc169_c

// Author : Epsilon573
// If it works, don't touch it.

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

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll a; ld b;
    cin >> a >> b;

    ll c = b*100;

    cout << a*c/100LL;

    return 0;
} 
 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Floating point types have a precision, so the result of calculations is often not exact. If you want to cast to an integer type this can lead to wrong result.

In this case you can do something like ll c=(b+0.001)*100; to force kind of round-up. Or read the number as a string, and parse by hand ignoring the dot.

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

// to store floating value there is no method to to it on base 2(computer) // it store approx value simple code for this problem main(){ long long a; long double b; cout<<(long long)(a*b*100+0.5)/100; return 0; }