OJ_摘录

一、        OJ结果代码:

1.         const int OJ_WAIT       = 0; //OK 等待 waiting[1]

2.         const int OJ_Judging[2]

3.         const int OJ_AC         = 1; //OK 接受 accepted[3]

4.         const int OJ_PE         = 2; //OK 格式错误? Presentation error[4]

5.         const int OJ_TLE        = 3; //OK 超时 time limit Exceeded[5]

6.         const int OJ_MLE        = 4; //OK 超内存 memory limit Exceeded[6]

7.         const int OJ_WA         = 5; //OK 结果错误 wrong answer[7]

8.         const int OJ_OLE        = 6; //OK 输出限制 output limit Exceeded[8]

9.         const int OJ_CE         = 7; //OK 编译出错 compile error[9]

10.     const int OJ_NSP                       //OK 未知错误 No Such Problem[10]

11.     const int OJ_RE_SEGV    = 8; //OK 运行错误Runtime ERROR

12.     const int OJ_RE_FPE     = 9; //OK

13.     const int OJ_RE_BUS     = 10;//OK

14.     const int OJ_RE_ABRT    = 11;//OK

15.     const int OJ_RE_UNKNOWN = 12;//OK

16.     const int OJ_RF         = 13;//OK

17.     const int OJ_SE         = 14;//System Error

二、        退出代码:

1.         const int EXIT_OK               =   0;

2.         const int EXIT_BAD_USAGE        =   2;

3.         const int EXIT_BAD_ARG          =   2;

4.         const int EXIT_BAD_TIME_LIMIT   =   4;

5.         const int EXIT_BAD_LANG         =   5;

6.         const int EXIT_BAD_MEM_LIMIT    =   6;

7.         const int EXIT_BAD_OUT_LIMIT    =   8;

8.         const int EXIT_BAD_FORK         =   10;

9.         const int EXIT_SETRLIMIT_TIME   =   12;

10.     const int EXIT_SETRLIMIT_MEM    =   14;

11.     const int EXIT_SETRLIMIT_STACK =   16;

12.     const int EXIT_SETRLIMIT_FSIZE =   17;

13.     const int EXIT_CHDIR            =   18;

14.     const int EXIT_FREOPEN_IN       =   20;

15.     const int EXIT_FREOPEN_OUT      =   22;

16.     const int EXIT_FREOPEN_ERR      =   24;

17.     const int EXIT_SETITIMER        =   26;

18.     const int EXIT_PTRACE_TRACEME   =   28;

19.     const int EXIT_EXECL            =   30;

20.     const int EXIT_PTRACE_GETREGS   =   32;

21.     const int EXIT_PTRACE_SYSCALL   =   34;

22.     const int EXIT_FILEREADER_OPEN =   36;

23.     const int EXIT_FILEREADER_READ =   38;

24.     const int EXIT_FILEREADER_CLOSE =   40;

25.     const int EXIT_WAIT4            =   42;

26.     const int EXIT_SPJ_POPEN        =   44;

27.     const int EXIT_SPJ_PCLOSE       =   46;

28.     const int EXIT_SPJ_TIMEOUT      =   48;

29.     const int EXIT_SPJ_FSCANF       =   50;

30.     const int EXIT_SPJ_UNKNOWN      =   52;

31.     const int EXIT_UNKNOWN          =   64;

三、         输入: 命令行参数(如果某参数包含空格,记得用引号:

1.         -e 需要执行的程序(如果是java,则需要包含完整的java ooox命令行)

2.         -l 语言类型(0 = C, 1 = C++, 2 = pascal, 3 = Java)

3.         -d 临时文件夹 (用于存储程序输出)

4.         -I 输入文件 (data/1001/test.in)

5.         -O 输出文件 (data/1001/test.out)

6.         -t 时间限制,毫秒为单位(默认为1000ms)

7.         -m 内存限制,KB 为单位(默认为65536KB)

8.         -o 输出大小限制,KB 为单位(默认为8192KB)

9.         -s SPJ程序命令行,如不提供则表示不是SPJ

10.     -j -? 显示此提示

四、        评判过程

    系统评判过程完全符合程序设计解决实际问题的过程。用户先在自己的计算机上编写好程序,经过运行,测试后,将程序源代码提交到在线评判服务器。在服务器端,系统按照一定的规则从缓冲区中选取一个题目进行评判。首先对源程序进行编译,如果程序存在语法错误,则返回语法错误信息(警告信息不算错误信息),否则,评判系统将运行编译通过后的可执行程序,在用户程序运行过程中,对程序运行所需的系统资源进行严格的限制,防止恶意程序的攻击。在程序运行正常结束后,对运行的结果进行测试,如果是结果正确,则更新用户的排名信息、答题数量、答题时间、问题列表的答题统计信息等。

    整个系统的大致工作过程如图1所示,其中图上省略了系统各阶段的数据库操作说明部分。

1 评判流程

五、        系统模块图

2 系统模块

    后端 Judge 服务器模块包括:程序运行器、守护进程、编译接口、用例测试器。

    前端 Web 服务器模块包括:系统管理员、用户验证、排名统计、问题浏览、提交、查看运行状态。

    系统管理员模块:只提供给系统管理员对比赛日程计划的控制,题库录入,参赛队员信息管理,比赛期间系统管理员没有任何的操作控制权限。

    用户验证:维护用户比赛过程中各个页面操作的权限控制,身份验证。

    排名统计:根据竞赛规则(如前)对用户进行排名。

    问题浏览,提交,查看运行状态:各种界面设计

    程序运行器:程序运行器执行编译产生的可执行代码,并事先设置该程序的权限和运行限制,准备输入输出重定向,然后产生解答输出。 判断程序运行的状态。其中要保证被执行的程序不能危害系统的安全,不能访问非授权信息,不能占用超过规定量的资源。

    程序运行器是实现自动评判和保证系统安全的关键模块。如何自动限制用户程序的资源占用,获取用户程序执行信息,以及防止恶意用户的破坏都是值得重视的问题。

    守护进程:管理比赛例程,监控 Judge 服务器的运行状态,帮助程序运行器完成对用户进程的监控,必要时终止用户进程。守护进程还负责与数据库耦合,取出数据库中尚未评判的程序,然后将程序的评判结果信息写回数据库。

    编译模块:用于统一多个编译器的编译调用过程,支持多种程序设计语言,负责检查用户提交的程序语法,并编译产生可执行代码。如果编译器发现源程序语法错误,需要立即指出,不再继续该题的评判工作。

    用例测试器:用例测试器对产生的解答输出对比标准测试数据进行测试,给出评判结论。

    用例测试器需要注意的一个重要问题是,如何合理区分结果错误和格式错误。通常认为,只是空白字符的不同,以及字母大小写的不同就是格式错误,其它的就是结果错误。

    数据库:用户基本信息表、答题进度表、答题结果表,题目列表,测试数据等。

六、        前端 Web 系统模型

    前端 Web 系统:即给每个用户使用的客户端,负责接受用户的命令,将程序提交给服务器,并将服务器返回的结果显示给用户。对于这种类型的应用来说,有两种模式可以选择,一为客户/服务器(C/S)模式,二为浏览器/服务器(B/S)模式。

    C/S 模式有很多优点,比如能够实现更丰富的用户操作方式,给用户更加丰富的用户体验。但它也存在很根本的缺点,即非常不容易管理,需要在每一个客户端安装程序。相对来说,B/S 模式就要方便很多,只需要客户端有一个浏览器就行。在线评判系统的目标是要在校园网上开展大型的练习或竞赛,同时,用户的复杂性操作的需求不显著,所以 B/S 模式是在线评判系统的最佳选择,其系统模型如图3所示。

3 前端 Web 系统模型

七、        后端 Judge 服务器系统模型

    评判模块对用户提交的解答进行评判。在目前的设计中,包含了两大类的评判器:

    1)本地评判器。本地评判器和评判系统框架执行在同一个机器上。

    2)远程评判器。远程评判器可以运行在不同的机器上,形成一个由多台计算机组成的集群,以大大提高系统的可伸缩性。

    服务器在评判过程中,不管是编译阶段,程序运行阶段,还是用例测试阶段,其工作量是相当大的。特别是当程序提交数量很多时,可能会造成提交的问题需长时间的等待才能够给予评判,这不仅影响了评判进度,还会影响前端 Web 服务器的执行速度。解决该问题的一种方案是提升服务器的硬件性能指标,如使用工作站,甚至巨型机当服务器,或分布式系统计算机。另一种解决方案是利用基于网络的多服务器系统并行执行。不管采用哪一种方案,在 Judge 服务器设计过程中,应尽量提高评判过程中的并行执行特性,如多线程,多进程,多服务器,流水线系统结构等。

    并行执行的系统结构:并行执行的系统结构是通过多线程,多进程或多 Judge 服务器并行执行一个程序评判的全过程。多个 Judge 服务器通过缓冲区与评判系统的前端 Web 服务器耦合。缓冲区是一个临界资源,必须采取相应的机制(信号量,互斥锁)使得多Judge服务器的同步与互斥。其参考模型如图4所示。

 

4 并行系统结构

    其中每台 Judge 服务器都相对独立的执行一个程序的评判全过程(即编译,运行和测试)。

    流水线式系统结构:流水线式系统结构借鉴计算机组成原理中的流水线式系统设计模式。它是将一个任务分成相对独立的几个阶段,系统同时运行各个阶段,每个任务连续的从第一个阶段流向最后一个阶段完成一个任务的整体。

    该评判系统后端Judge服务器分为两个阶段:编译系统模块,运行和测试系统模块。各个模块通过缓冲区衔接过度,其中个缓冲区也是临界资源。系统参考模型如图5所示。

5 流水线系统结构

    从图中可以看出,每个系统相对独立地执行一个程序评判过程的相应阶段,但是一个题目的评判有可能编译或运行没有正常通过,因此并不一定流过该评判系统流水线的每一个阶段。

八、        数据库设计

    数据库是连接该系统前端Web服务器与后端Judge服务器的桥梁,因此良好的数据库设计至关重要。

    数据库中主要有用户注册信息表(userRegister),赛题表(problemLib),用户排名表(rankList),评判状态表(status)。各表的属性及表之间的联系如图6,图中每个加粗字体的属性为相应实体的主键。

6 E-R

九、        面向对象的系统设计

    对于面向对象的软件系统来说,如何尽量提高系统的可维护性是一个核心的问题。实践证明,一个软件开发可能只需要半年的时间,而维护则需要花费很多年。一个软件项目在其生命周期之内花费在维护上的费用是花在原始开发上的费用的两倍甚至更多。

    软件系统和硬件系统有很多不同之处。通常,硬件系统在开发完成之后,不会做太大的修改和扩展,其维护工作主要是保证硬件系统的正常运行,解决一些存在的错误和缺陷。但是,通常赋予软件系统的维护的含义却要大得多,软件的维护就是软件的再生。用户希望一个软件系统在其生命周期之内能够不断满足自己需求的变化。一个好的软件设计,必须能够允许新的设计要求以较为容易和平稳的方式加入到已有的系统中去,从而使这个系统能够不断焕发出青春。

    什么样的系统设计才是好的系统设计?这个问题一直困扰着软件工程师们。一个好的系统设计应该满足的三条性质:可扩展性(extensibility)、灵活性(Flexibility)、可插入性(Pluggability)。这三条性质就是一个系统设计应当达到的目标。

    1)可扩展性。新的性能可以很容易的加入到系统当中去,就是可扩展性。

    2)灵活性。可以允许代码修改平稳的发生,而不会波及到其他模块,就是灵活性。

3)可插入性。可以很容易的将一个类抽出去,同时将另一个有同样接口的类加入进来,就是可插入性。

十、        /PROC文件系统

The Linux implementation of /proc also clones that of Plan 9. Under Linux, /proc includes a directory for each running process (including kernel processes) at /proc/PID, containing information about that process, notably including:

1.         /proc/PID/cmdline, which contains the command which originally started the process.

2.         /proc/PID/cwd, a symlink to the current working directory of the process.

3.         /proc/PID/environ, a file containing the names and contents of the environment variables that affect the process.

4.         /proc/PID/exe, a symlink to the original executable file, if it still exists (a process may continue running after its original executable has been deleted or replaced).

5.         /proc/PID/fd, a directory containing a symbolic link for each open file descriptor.

6.         /proc/PID/root, a symlink to the root path as seen by the process. For most processes this will be a link to / unless the process is running in a chroot jail.

7.         /proc/PID/status, a file containing basic information about a process including its run state and memory usage.

8.         /proc/PID/task, a directory containing hard links to any tasks that have been started by this (i.e.: the parent) process.

9.         /proc/PID/maps, the memory map showing which addresses currently visible to that process are mapped to which regions in RAM or to files.

10.     It also includes non-process-related system information, although in the 2.6 kernel much of that information moved to a separate pseudo-file system, sysfs, mounted under /sys:

11.     depending on the mode of power management (if at all), either directory, /proc/acpi or /proc/apm, which predate sysfs and contain various bits of information about the state of power management.

12.     /proc/bus, containing directories representing various buses on the computer, such as input/PCI/USB. This has been largely superseded by sysfs under /sys/bus which is far more informative.

13.     /proc/fb, a list of the available framebuffers

14.     /proc/cmdline, giving the boot options passed to the kernel

15.     /proc/cpuinfo, containing information about the CPU, such as its vendor (and CPU family, model and model names which should allow users to identify the CPU) and its speed (CPU clockspeed), cache size, number of siblings, cores, and CPU flags. It contains a value called "bogomips", frequently misunderstood as measure CPU-speed like a benchmark, while it doesn't actually measure any sensible (for end-users) value at all. It occurs as a side-effect of kernel timer calibration and yields highly varying values depending on CPU type, even at equal clock speeds.

16.     /proc/crypto, a list of available cryptographic modules

17.     /proc/devices, a list of character and block devices sorted by device ID but giving the major part of the /dev name too

18.     /proc/diskstats, giving some information (including device numbers) for each of the logical disk devices

19.     /proc/filesystems, a list of the file systems supported by the kernel at the time of listing

20.     /proc/interrupts, /proc/iomem, /proc/ioports and the directory /proc/irq, giving some self-explanatory details about the devices (physical or logical) using the various system resources

21.     /proc/meminfo, containing a summary of how the kernel is managing its memory.

22.     /proc/modules, one of the most important files in /proc, containing a list of the kernel modules currently loaded . It gives some indication ( not always entirely correct) of dependencies.

23.     /proc/mounts, a symlink to self/mounts which contains a list of the currently mounted devices and their mount points (and which file system is in use and what mount options are in use).

24.     /proc/net, a directory containing a lot of really useful information about the network stack, in particular nf_conntrack which lists existing network connections (particularly useful for tracking routing when iptables FORWARD is used to redirect network connections).

25.     /proc/partitions, a list of the device-numbers, their size and /dev names which the kernel has identified as existing partitions (for example if /dev/sda contains a partition table, then /dev/sda1 and others will appear as available partitions). Note that if a partition isn't listed in this file, then a patched version of losetup is around which can essentially mount the partition and connect /dev/loop[n] devices to the various partitions (though it is not certain if these will then appear in /proc/partitions).

26.     /proc/scsi, giving information about any devices connected via a SCSI or RAID controller

27.     a symbolic link to the current (traversing) process at /proc/self (i.e. /proc/PID/ where PID is that of the current process).

28.     /proc/slabinfo, listing statistics on the caches for frequently-used objects in the Linux kernel

29.     /proc/swaps, a list of the active swap partitions, their various sizes and priorities

30.     Access to dynamically-configurable kernel options under /proc/sys. Under /proc/sys appear directories representing the areas of kernel, containing readable and writable virtual files.

31.     For example, a commonly referenced virtual file is /proc/sys/net/ipv4/ip_forward, because it is necessary for routing firewalls or tunnels. The file contains either a '1' or a '0': if it is 1 then the IPv4 stack will forward packets not meant for the local host, if it is 0 then it will not.

32.     /proc/sysvipc, containing memory sharing and IPC information.

33.     /proc/tty, containing information about the current terminals; /proc/tty/driver looks to be a list of the different types of tty available each of which is a list of those of each type

34.     /proc/uptime, the length of time the kernel has been running since boot and spent in idle mode (both in seconds)

35.     /proc/version, containing the Linux kernel version, distribution number, gcc version number (used to build the kernel) and any other pertinent information relating to the version of the kernel currently running

36.     other files depending on various hardware, module configurations, and changes to the kernel.

The basic utilities that use /proc under Linux come in the procps (/proc processes) package, and only function in conjunction with a mounted /proc.

The procfs plays an important role in moving functionality from kernel space to user space. For example the GNU version of ps operates entirely in user mode, using the procfs to obtain its data.

 



[1] The judge is so busy that it can't judge your submit at the moment, usually you just need to wait a minute and your submit will be judged.

[2] The judge is judging your problem now

[3] OK! Your Answer is correct!

[4] Your output format is not exactly the same as the judge's output, although your answer to the problem is correct. Check your output for spaces, blank lines, etc. against the problem output specification

[5] Your program tried to run during too much time

[6] Your program tried to use more memory than the judge default settings.

[7] Correct solution not reached for the inputs. The inputs and outputs that we use to test the programs are not public (it is recommendable to get accustomed to a true contest dynamic).

[8] output limit Exceeded

[9] The compiler could not compile your program. Of course, warning messages are not error messages. Click the link at the judge reply to see the actual error message.

[10] Either you have submitted a wrong problem ID or the problem is unavailable.

posted @ 2010-03-02 14:26  灰鸽子  阅读(1251)  评论(1编辑  收藏  举报