Блог пользователя justaninactivealt

Автор justaninactivealt, история, 4 года назад, По-английски

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
  • Проголосовать: нравится
  • +66
  • Проголосовать: не нравится

»
4 года назад, скрыть # |
← Rev. 3  
Проголосовать: нравится -13 Проголосовать: не нравится

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

  • »
    »
    4 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      4 года назад, скрыть # ^ |
      ← Rev. 3  
      Проголосовать: нравится -13 Проголосовать: не нравится

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

      • »
        »
        »
        »
        4 года назад, скрыть # ^ |
         
        Проголосовать: нравится +6 Проголосовать: не нравится

        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

        • »
          »
          »
          »
          »
          4 года назад, скрыть # ^ |
          ← Rev. 2  
          Проголосовать: нравится -13 Проголосовать: не нравится

          i don't understood than why this code got AC

          AC
»
4 года назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

Faced the same issue.

»
4 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i also faced same issue

»
4 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

bad question

»
4 года назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

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.

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

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).