当前位置:网站首页>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;
}
边栏推荐
- 2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin (no2tdmpp) H2) /5,10,15,20-tetra (4-methylphenyl) porphyrin (TMPP) H2) Qiyue porphyrin products
- Summary of redis basic knowledge points
- 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
- How to insert pseudo code into word documents simply and quickly?
- Domain name hack
- Quickly write MVVM code using source generators
- Direct derivation of Bessel function with MATLAB
- C語言用 printf 打印 《愛心》《火星撞地球》等,不斷更新
- Research on heuristic intelligent task scheduling
- gan semi conductor
猜你喜欢

β- Tetraphenyl nickel porphyrin with all chlorine substitution| β- Thiocyano tetraphenyl porphyrin copper| β- Dihydroxy tetraphenyl porphyrin 𞓜 2-nitroporphyrin | supplied by Qiyue

Mvcc principle in MySQL

51 single chip microcomputer learning notes 7 -- Ultrasonic Ranging

Cipher

ES6 Modularization: export /import

2022 recommended trend toy blind box industry research report industry development prospect market analysis white paper (the attachment is a link to the network disk, and the report is continuously up

Software architecture final review summary

Robot reinforcement learning - transferring end-to-end videomotor control from simulation to realworld (curl 2017)

Service grid ASM year end summary: how do end users use the service grid?

Introduction to Photoshop (the first case)
随机推荐
Robot reinforcement learning -- first person vs third person
Love that can't be met -- what is the intimate relationship maintained by video chat
Introduction to Photoshop (the first case)
How to hand over complex legacy systems?
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
Signal slot mechanism
Cipher
HTTP Caching Protocol practice
Private project practice sharing gtlab+jenkins architecture construction and document reference
In 2022, I haven't found a job yet. I have been unemployed for more than one year. What is the "old tester" for eight years?
Use VS to create a static link library Lib and use
Conditional test, if and case conditional test statements of shell script
Regular expressions for shell script values
Top ten Devops best practices worthy of attention in 2022
Testing grpc service with grpcui
Difference between parametric continuity and geometric continuity
使用VS创建静态链接库.lib并使用
How to insert pseudo code into word documents simply and quickly?
[high concurrency] deeply analyze the callable interface
Le langage C imprime "Love", "Mars hit Earth" et ainsi de suite en utilisant printf, qui est constamment mis à jour