[Written online programming step on the pit] --- OJ FAQ

introduction

Recently participated in several written tests, may be insufficient to prepare for it, is subject to a number of input and output stumbled, wasting a lot of time, and even some direct questions by 0 test cases, but their own algorithms and code absolutely no problems, down review information, carefully combed share some common questions about the inputs and outputs for everyone.

Bull-off network

I am sure you small cattle off network partners are familiar with it, "to entry, online customer cow net", top with a contest on inputs and outputs, I feel very good, especially for someone like me Programming "white" to said useful exercise common input-output problem! ! !
Cattle off network input and output practice (click to enter: https: //ac.nowcoder.com/acm/contest/320)
Here Insert Picture Description

OJ concept

online judge, referred to as OJ, is sentenced to an online question system. Users can submit online a variety of program code (such as: C, C ++, Java, Python, etc.), the system source code is compiled and executed, and to verify the correctness of the program source code, test cases through pre-designed. Now widely used around the world university students' program of training designed to automatically submit judge, as well as various competitions (such as ACM) and other operations.

OJ principle

Program submitted by users in the OJ systems will be subject to more stringent restrictions when performing, including run-time constraints, memory usage restrictions and security restrictions. The results of the user program execution will be captured and saved OJ systems, then transfer to a referee program. The difference between whether the referee or the program compares the user program and the output data of the standard sample output, or to verify the user program output data satisfies a certain logic conditions. Finally, the system returns to the user a state: through, wrong answer, overtime, exceeds the output limit, super memory, runtime errors, malformed, or not compile, use and return to the program memory, run time and other information.

Input and output processing cycle Frequently Asked Questions

1. Why do we need the input-output cycle : Generally OJ For each question there .in and .out files, respectively, the input and output test data. If all data are only some programming problems in a .in and a .out, so it will become more than a set of tests, so the loop processing code requires submission.

2, treatment : In fact, this problem can be avoided, the programming problem is the background of each sample to make a corresponding set of .in and .out files so that it becomes a single set of tests, the code does not require treatment cycle, but the usual practice subject of varying quality, this problem will occur. Code inside the loop process that even a single set of tests will be no problems, so in order to be lazy, you can write a full treatment cycle.

3, pit : If multiple sets of test data, but you happen to need some code inside tag array, map, set, etc., within the loop must remember to empty, or may occur in front of the test sample affects the answer to the follow-up data .

For some basic knowledge of various languages

1, the question people often use C / C ++ to write standard process, the data also manufactured by standard processes, so use the same people with the topic of language would be more secure

2, C / C ++ efficiency is relatively high, generally speaking generally OJ for a topic time limit distinguishes between C / C ++ and other languages, typically approach is assumed that C / C ++ limit is 1s, other languages ​​will give twice the time, even more.

3、About cin cout and scanf printf. Do question when to make use of scanf printf. Here to tell a little common sense, do not be surprised: in the case of large amount of data cin cout lot slower than scanf printf. Once the large amount of data encountered, it is possible to read in just kneeling out. You may be able to use std :: ios :: sync_with_stdio (false); This statement cin and scanf turn off synchronization, speed up efficiency. But even so cin slower, and once we have this statement, scanf and cin mix might cause some strange errors

4, Java-related: Java is probably the overall efficiency of more than two times slower than C / C ++, but written in Java programming that is also no problem, mainly to deal with the situation of the various inputs and outputs.

5, python, etc. in other languages, the programming problem must first do their own method of reading practice more different data formats on the platform, there is the efficiency may be low, there are some other languages ​​too rich package of features that code the final code for a variety of functions performed, written or official interviewer for algorithm study does not want to see this code.

6、The array is preferably open space data range subject to the requirements, there may cause a runtime error, if the depth is too deep code recursion stack space may cause critical runtime error。

About output format

1, the end of the line space: for example, I output need to print more than the required number separated by spaces, we recycle printf ( "% d", x ); this will be very convenient, but it will lead to the end of the line more than one space, back-office systems will be stricter than for your output and .out file, it will also convicted of error
2, line problems, for each sample, it is recommended after complete output will wrap it. For some problems, probably not wrap has led to the back of the input data dislocation, it will not be possible before.

About the time complexity analysis

Generally speaking general system 1s algorithm can run the order is less than 1e8, so do problems when the evaluation algorithm efficiency is very important, directly determine your approach will be passed, of course, this is the C / C ++ standard, others take a language of their own time multiplier. .

For example, topics such as n = 1e5, then I know I can be very sensitive to the algorithm requires a O (n) or O (nlogn). The complexity of the square directly timeout!

About "I'm a local pass, to pay up is wrong."

Submitted unsuccessful, generally two situations :

  1. Code syntax problem, resulting in different compiled
    a. more to brush the question, the common mistakes accumulated
    b. Avoid using some odd function, or a function associated with the platform
    c. vs best not to use to write the algorithm, vs is the default mode under Windows, General OJ The compiler may not be recognized
  2. The code compiles successfully, submitted unsuccessful
    a. See unsuccessful information output, the output format does not pass a test or
    b. For the test can not be adopted, usually can not be used by the embodiment shown, and then provide a program output according to the output, the output and test results, check the code wrong piece.
    c. It does not check out, one by one test process
  3. The compiler can perform yourself, but not by OJ
    If some students will say, in their own compiler you can run through the code, but can not be submitted in the OJ on top of the reasons for that? There are such problems
    many, such as no legitimate argument passed inspection, such as: null pointer is no sentence and so on. This problem is mostly a problem of these boundaries

Incorporated herein by reference from (https://www.nowcoder.com/discuss/8632)

Published 57 original articles · won praise 301 · views 40000 +

Guess you like

Origin blog.csdn.net/L19002S/article/details/105069436