当前位置:网站首页>Hustoj SPJ example
Hustoj SPJ example
2022-06-29 05:45:00 【Hard working Lao Zhou】
What is? SPJ
SPJ yes Special Judge It means .
When to use SPJ
When there is more than one answer to the question , We have to use SPJ.
How to use SPJ
Open... In the title SPJ
First , We need to work out the questions , increase SPJ Options , As shown in the figure below .
After the title is saved , It shows that SPJ, As shown in the figure below .
To write SPJ Program
SPJ Program , It's a standard C perhaps C++ Program , According to the requirements of the topic , Read the test file (*.in), Standard output file (*.out), User output file (user.out), Compare .
Use input with parameters .
SPJ Template code
//
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
const int AC=0;
const int WA=1;
int main(int argc,char *args[]) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// Read three files , Be careful arg Order cannot be changed
ifstream f_in;
f_in.open(args[1]);
ifstream f_out;
f_out.open(args[2]);
ifstream f_user;
f_user.open(args[3]);
int ret=AC;
/************** Write the logic of the problem **************/
/************************************/
f_in.close();
f_out.close();
f_user.close();
return 0;
}
Upload spj.cc Go to the corresponding topic directory
Suppose our title is 6387 6387 6387, Then the corresponding path is /home/judge/data/6387. take spj.cc Upload to the corresponding directory , Here's the picture .
spj.cc The file name can be named arbitrarily .
compile spj Executable file
perform
g++ -o spj 6387_spj.cpp -std=c++14
In this way, we can get the corresponding executable file spj.
Modify owner
take spj The owner is changed to www-data.
sudo chown www-data:judge spj
The permissions are set as shown in the following figure .
Set executable
sudo chmod +x spj
test
Build a user.out file .
./spj sample.in sample.out user.out
View the execution results
echo $?
Here's the picture .
Show 0 0 0 The result is correct . Display non-zero is generally 1 1 1 Indicates that the result failed .
SPJ Write sample
SPJ The difficulty of writing lies in the logical judgment of the topic .
We use MYOJ Question no 6387 6387 6387 As an example .
This problem is a topological sequence of digraphs , Is to give a directed graph , Output the corresponding topology sequence . If it's a D A G DAG DAG Output any reasonable sequence , If not D A G DAG DAG Output − 1 -1 −1.
Scenario analysis
No D A G DAG DAG
We should output − 1 -1 −1. The user may have two kinds of errors .
Situation 1 : Output − 1 2... -1\ 2 ... −1 2.... The user output − 1 -1 −1, But it also outputs multiple data .
Situation two : Output − 2 -2 −2. User output non − 1 -1 −1.
yes D A G DAG DAG
We read the user's output , Then, according to the properties of topological sorting , Analyze the legitimacy of each output .
The user may have two kinds of errors .
Situation 1 : Is not a legitimate topological sort . That is, output to a vertex u u u When , The summit u u u The degree of penetration is not 0 0 0.
Situation two : The user has output a ratio n n n More vertices .
Sample code
//
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
const int AC=0;
const int WA=1;
const int N=1e5+10;
LL h[N], in[N];
LL ans[N];
const int M=2e5+10;
LL e[M], ne[M], idx;
LL que[M];
LL hh, tt;
LL n;
void add(LL a, LL b) {
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
// Update penetration
in[b]++;
}
int main(int argc,char *args[]) {
#if 1
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
ifstream f_in;
f_in.open(args[1]);
ifstream f_out;
f_out.open(args[2]);
ifstream f_user;
f_user.open(args[3]);
int ret=AC;
/************** Write the logic of the problem **************/
memset(h, -1, sizeof h);
LL m;
f_in>>n>>m;
for (LL i=1; i<=m; i++) {
LL a,b;
f_in>>a>>b;
add(a,b);
}
LL cnt=0;
LL u;
while (f_user>>u) {
//cout<<"u="<<u<<"\n";
++cnt;
if (cnt>n) {
return WA+6;
}
if (u>0) {
if (in[u]!=0) {
return WA+1;
}
// Traverse u All sides of
for (LL i=h[u]; i!=-1; i=ne[i]) {
LL v=e[i];
in[v]--;
}
} else if (u!=-1) {
return AC+2;
}
}
if (cnt!=n) {
return WA+5;
}
/************************************/
f_in.close();
f_out.close();
f_user.close();
return 0;
}
边栏推荐
- The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
- The first in China! CICA technology database antdb appears at the performance test tool conference of China Academy of communications technology
- Regular expressions for shell script values
- Set column width in jitter - set column width in jitter
- 开启生态新姿势 | 使用 WordPress 远程附件存储到 COS
- 2022 recommended quantum industry research industry development planning prospect investment market analysis report (the attachment is a link to the online disk, and the report is continuously updated
- Is it safe to open a securities account? Is there any danger
- HTTP Caching Protocol practice
- Analysis report on the investment market of the development planning prospect of the recommended NFT industry research industry in 2022 (the attachment is a link to the online disk, and the report is
- [chromium] win10 vs2019 environment chromium configuration and compilation.
猜你喜欢
![[high concurrency] deeply analyze the callable interface](/img/42/43d1f0b894f2632f2c7f1bfe970708.jpg)
[high concurrency] deeply analyze the callable interface
![[CV] wuenda machine learning course notes Chapter 13](/img/83/583d9ef852cf398ff8ed730bda0eab.jpg)
[CV] wuenda machine learning course notes Chapter 13

Cipher

How to use thread stack location

Sailing with karmada: multi cluster management of massive nodes

To learn more about Yibo Hongmeng development

Software architecture final review summary
![[high concurrency] deeply analyze the callable interface](/img/dc/174f97fdd27180ed210d76768cc345.jpg)
[high concurrency] deeply analyze the callable interface

Analysis report on the investment market of the development planning prospect of the recommended NFT industry research industry in 2022 (the attachment is a link to the online disk, and the report is

Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u
随机推荐
嵌入式RTOS
Analysis report on the investment market of the development planning prospect of the recommended NFT industry research industry in 2022 (the attachment is a link to the online disk, and the report is
3 frequently tested SQL data analysis questions (including data and code)
Tcapulusdb Jun · industry news collection (VI)
Use typescript compiler parameter 'skiplibcheck' - usage of the typescript compiler argument'skiplibcheck'
Private project practice sharing gtlab+jenkins architecture construction and document reference
C语言用 printf 打印 《爱心》《火星撞地球》等,不断更新
Review of MySQL knowledge points
Why Houdini made the pyside2 plug-in crash
Plugin
Parsing rshub document auto generation API
February 14 institutional dragon and tiger list and operation of well-known hot money
Set column width in jitter - set column width in jitter
Signal slot mechanism
[high concurrency] deeply analyze the callable interface
The translation of those exquisite lines in the eighth season of the big bang
Skills of writing test cases efficiently
轻松入门自然语言处理系列 专题7 基于FastText的文本分类
C語言用 printf 打印 《愛心》《火星撞地球》等,不斷更新
2022 recommended prefabricated construction industry research report industry development prospect market analysis white paper (the attachment is a link to the network disk, and the report is continuo