justaninactivealt's blog

By justaninactivealt, history, 2 years ago, In English

My submission gives WA without using cout<<fixed<<setprecision. Since the median needs atmost 1 decimal place of precision, this feels weird. Any explanations?

Code which will give WA on removing fixedprecision
| Write comment?
»
2 years ago, # |
Rev. 3   Vote: I like it -13 Vote: I do not like it

if the length of rest is odd than you have to add middle element

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The expression (rest[(k - 1) / 2] + rest[k / 2]) / 2.0 gives the median regardless. Give it a try.

    • »
      »
      »
      2 years ago, # ^ |
      Rev. 3   Vote: I like it -13 Vote: I do not like it

      Oh actually you are getting WA because you didn't added the case where M == N. the rest array will be empty

      • »
        »
        »
        »
        2 years ago, # ^ |
          Vote: I like it +6 Vote: I do not like it

        The rest vector will still have 1 element in it in that case as i<(n-m+1) so i<1 in the for loop while inserting elements in rest

        • »
          »
          »
          »
          »
          2 years ago, # ^ |
          Rev. 2   Vote: I like it -13 Vote: I do not like it

          i don't understood than why this code got AC

          AC
»
2 years ago, # |
  Vote: I like it +21 Vote: I do not like it

Faced the same issue.

»
2 years ago, # |
  Vote: I like it +6 Vote: I do not like it

I think it's because your code doesn't always print decimal point(.). See section "How does Kick Start handle real numbers? "

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

i also faced same issue

»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it

bad question

»
2 years ago, # |
  Vote: I like it +20 Vote: I do not like it

Okay, you have put the code with setprecision included, this may cause some confusion I think. If you have a piece of code giving WA, i think it d be better to put the version that gives WA to not cause confusion.

About WA, this may be because of scientific notation. Without setprecision if the answer is 10^9 it ll output "1e+09", instead of the desired 1000000000 because its type is double.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by justaninactivealt (previous revision, new revision, compare).

»
2 years ago, # |
  Vote: I like it +12 Vote: I do not like it

Without fixed in C++ your program often prints results in scientific notation:

	double ans = 123456789;
	cout << ans << "\n";
        // will print 1.23457e+08
	cout << fixed << ans << "\n";
        // will print 123456789.000000

The first one differs from the expected answer by 211 (123457000-123456789).