Блог пользователя T--o_o--T

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

Problem Link ,my code here Why I got WA? Please anyone can explain?

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

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

Have you tried the following:

  • Write a very naive and simple solution to the problem (maybe exponential complexity) (if you can, you may also just copy someone else's solution)
  • Write a program to generate thousands of small (!) test cases
  • Using those two, find a test case where your program gives the wrong answer
  • Use print statements or a debugger to see where exactly your program does the wrong thing.

98% of WAs and REs can be resolved this way. People here don't have the time to delve into every code posted here, it's much harder to debug somebody else's code and being able to debug your own code is a valuable skill. It is also a very routine process that can be learned much faster than problem solving and algorithms.


Also, the ideone link is missing ':' in the URL.

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

    Sir, I agree with this process...but many a time it becomes very hard to generate test cases like when the input is a graph ....what to do then?

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

      Generating graphs is not that bad: if I want a connected graph, I usually generate a tree and then randomly add edges until I have the desired number of edges. It may be a bit tedious, but it's not too bad. If you have trouble implementing it fast, I suggest preparing a small library for that. Or use existing libraries, but don't ask me for recommendations because I haven't used any.

      If you have something more difficult, like a graph with some special property or something, I would generate inputs randomly until an input has the required property. Remember that you don't need anything super fancy or fast, you don't need uniform distribution or anything like that. Just a quick-and-dirty program that might reasonably generate any small input if you run it a few thousand times.

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

      You might be interested in jngen.h. If you've used testlib.h in Polygon before, it's the same syntax for most of the functions. In particular, with this library it becomes really easy to add extra modifiers like guaranteeing connected, acyclic, etc.