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

Автор Big_Integer, история, 6 лет назад, По-английски

Hello, I have been trying to solve this problem for some time but getting WA.

The Problem This is a simple task for you.You have to write a simple code that can take three input a, b and c which are the length of the three sides of a Pythagorean triangle and check the triangle is valid or invalid.

The Input

The input file contains several lines. Each line contains three positive integers a, b, c < 100 which indicates the three sides of a triangle. Input is terminated by EOF.

The Output

For each input lines print a comment. Which contains if the triangle is right then “Valid.”, if the triangle is not right then “Invalid.” (Quote for clarification) in a separate line.

Sample Input

6 9 4 13 5 12

Sample Output

Invalid. Valid.

My code

But this approaches are not working out for me. I keep getting WA. I checked both of this code against this triplets and they checked out correctly.

original problem link : http://school.outsbook.com/problems/problemdetails/363

Please provide me some thoughts or error that is causing WA.

Thank you.

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

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

I tried solving it myself and got several WAs too. I would bet on a bug in the checker or that the problem statement is incomplete.

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

You made a mistake in your code: (a[0]<1||a[0]<1||a[0]<1)

The correct version is (a[0]<1||a[1]<1||a[2]<1)

But I am not sure that this correction gets AC as you sort the array initially

»
6 лет назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

Both old and new versions output Invalid. to the test case

0 1 1

When the smallest length is zero and both larger numbers are equal, the checker may consider such test case as a valid right triangle, and therefore produces WA verdict to you code.

The following is a slight update to your new version that outputs Valid. to the previous test case.

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a[3]; const string ans[] = { "Invalid", "Valid" };
    
    while( cin >> a[0] >> a[1] >> a[2] )
        sort( a, a + 3 ),
        cout << ans[ ( a[0] * a[0] + a[1] * a[1] ) == a[2] * a[2] ] << ".\n";
}

Hope that helps.

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

    He already had the check to discard rectangles with a side smaller than 1. This test is incorrect

    • »
      »
      »
      6 лет назад, # ^ |
      Rev. 9   Проголосовать: нравится -10 Проголосовать: не нравится

      While most sources consider that positive integers to start from 1, and that 0 is a neutral number that is neither positive nor negative, other sources consider that 0 belongs to both positive and negative integers, and that integers starting from 1 are strictly positive numbers.

      The problem statement

      " Each line contains three positive integers a, b, c < 100 which indicates the three sides of a triangle."

      does not mention that the side lengths are strictly positive integers. Furthermore, nothing is mentioned in the problem statement to restrict the two side angles of the right triangle as well as its area to be strictly positive. Therefore, this test case may be what is producing the WA verdict as mentioned before.

      UPDATE: It is not clear what would be wrong with trying to help a high school student in comprehending the possible reason for getting WA verdict, and sharing thoughts as he requested.

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

        No, look at his code: if (a<1 || b<1 || c<1) cout<<"INVALID" He already discarded your test case

        • »
          »
          »
          »
          »
          6 лет назад, # ^ |
          Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

          Yes, that's right.

          This statement may be the reason for the WA verdict if the on-line judge considers that any test case

          0 X X

          where X < 100 is a valid right triangle with angles 0, 90, and 90 degrees.

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

            Kinda misread the comment. Though, something like that should give Invalid. A triangle's condition is that a + b > c with all triples, and 0 + 90 is not larger than 90

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

              The mentioned numbers 0, 90, and 90 are the angles of right triangle boundary case. The sum of the three angles of any triangle as you probably know should always be equal to 180 degrees.

              What I am saying is that the on-line judge may be considering the boundary case

              a + b = c

              with a = 0 and b = c = X as a valid right triangle.