F.A.Qs Home ProblemSet Status Ranklist Contest LoginRegister
大视野在线测评-欢迎您
[ New Thread ]
Problem 5025 >> 提供SPJ
sjw2018 @ 2019-12-04 19:14:21
[ Quote ] [ Edit ] [ Delete ] 1#
rt

@lavendir

//尚不清楚OJ的SPJ接口,下面写的是Hustoj默认的SPJ方式

#include<fstream>
#include<string>
int x[555555],y[555555],z[555555],n,m,d;
using std::string;
using std::ifstream;
using std::ofstream;
ifstream fin,fout,fstd;
ofstream fscore,freport;
#define closeall fout.close(),fstd.close(),fscore.close(),freport.close(),fin.close()
void quit()
{closeall;}
int main(int argc,char *argv[])
{
//SPJ Begin
fin.open(argv[1]); //InputData
fstd.open(argv[2]); //OutputData
fout.open(argv[3]); //UserOutput
freport.open(argv[4]); //ErrorMessage
fscore.open(argv[5]); //Score

fin>>n;
m=(n*(n-1))>>1;
register int i,ii;
for(i=1;i<n;i++)
for(ii=i+1;ii<=n;ii++)
{
if(!(fout>>d))return quit(),-1;
if(d<1||d>m)return quit(),-1;
if(x[d])return quit(),-1;
x[d]=i,y[d]=ii;
}


for(i=1;i<=m;i++)
z[x[i]]++,z[y[i]]++,z[x[i]]^=(z[y[i]]^=(z[x[i]]^=z[y[i]]));

for(i=1;i<=n;i++)
if(z[i]>=n)return quit(),-1;

return quit(),0;
}
jiangnaihui @ 2019-12-06 09:30:05
[ Quote ] [ Edit ] [ Delete ] 2#
太强了
lavendir @ 2019-12-07 12:12:05
[ Quote ] [ Edit ] [ Delete ] 3#
可参考这个帖https://www.lydsy.com/JudgeOnline/wttl/thread.php?tid=218
谢谢。
sjw2018 @ 2020-01-15 18:51:42
[ Quote ] [ Edit ] [ Delete ] 4#
@lavendir

已按照SPJ规范重写。

#include<fstream>
#include<string>
int x[555555],y[555555],z[555555],n,m,d;
using std::string;
using std::ifstream;
using std::ofstream;
ifstream fin,fout,fstd;
#define closeall fout.close(),fstd.close(),fin.close()
void quit()
{closeall;}
#define WA 1
#define AC 0
int main(int argc,char*argv[])
{
fin.open(argv[1]); //InputData
fstd.open(argv[2]); //OutputData
fout.open(argv[3]); //UserOutput

fin>>n;
m=(n*(n-1))>>1;
register int i,ii;
for(i=1;i<n;i++)
for(ii=i+1;ii<=n;ii++)
{
if(!(fout>>d))return quit(),WA;
if(d<1||d>m)return quit(),WA;
if(x[d])return quit(),WA;
x[d]=i,y[d]=ii;
}


for(i=1;i<=m;i++)
z[x[i]]++,z[y[i]]++,z[x[i]]^=(z[y[i]]^=(z[x[i]]^=z[y[i]]));

for(i=1;i<=n;i++)
if(z[i]>=n)return quit(),WA;

return quit(),AC;
}
[Top] [Previous Page] [Next Page]

HOME Back