Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:生成小规模随机测试数据的脚本, 助你解决WA~

Posted by chichina at 2020-04-21 17:46:06 on Problem 1904
In Reply To:生成小规模随机测试数据的脚本, 助你解决WA~ Posted by:lddlinan at 2020-04-21 15:07:41
> # 前提是已经有一个正确但是TLE的代码可以计算出每组测试数据的正确答案
> from random import randint, shuffle
> 
> def gen(mm):
>     n = randint(1, 1000)
>     b = list(range(1, n+1))
>     shuffle(b)
>     nei = [None]*(n+1)
>     for i in range(1, n+1):
>         nei[i] = set()
>         nei[i].add(b[i-1])
>     m = randint(1000, 10000)
>     for i in range(m):
>         ia = randint(1, n)
>         ib = randint(1, n)
>         nei[ia].add(ib)
>     r = []
>     r.append(str(n)+"\n")
>     for i in range(1, n+1):
>         r.append(str(len(nei[i])))
>         for ib in nei[i]: r.append(str(ib))
>         r.append("\n")
>     for i in range(n):
>         r.append(str(b[i]))
>     r.append("\n")
>     with open("%03d" % mm, "w") as f:
>         f.write(" ".join(r))
> 
> for i in range(1):
>     gen(i)

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator