#!/usr/bin/env python3
import argparse
import math
import sys
from random import randint
def make_random_tree(n):
res = ""
for i in range(2, n + 1):
f = randint(1, i - 1)
res += "%d %d\n" % (f, i)
return res
# Si = T1
def make_si_e_ti(n, m):
res = "%d %d\n" % (n, m)
res += make_random_tree(n)
for i in range(n):
if randint(0, 3) is 0:
res += "0"
else:
res += "%d" % randint(0, n)
if i == n - 1: res += "\n"
else: res += " "
for i in range(m):
s = randint(1, n)
res += "%d %d\n" % (s, s)
return res
# wj = 0
def make_wj_e_0(n, m):
res = "%d %d\n" % (n, m)
res += make_random_tree(n)
for i in range(n):
res += "0"
if i == n - 1: res += "\n"
else: res += " "
for i in range(m):
s = randint(1, n)
t = randint(1, n)
res += "%d %d\n" % (s, t)
return res
# All data is randomized
# This method is deprecated, because the most of anwer will be 0 or 1.
def make_r(n, m):
res = "%d %d\n" % (n, m)
res += make_random_tree(n)
for i in range(n):
w = randint(1, n)
res += "%d" % w
if i == n - 1: res += "\n"
else: res += " "
for i in range(m):
s = randint(1, n)
t = randint(1, n)
res += "%d %d\n" % (s, t)
return res
def make_link_tree(n):
res = ""
for i in range(2, n + 1):
res += "%d %d\n" % (i - 1, i)
return res
# The tree becomes a link
def make_l(n, m):
res = "%d %d\n" % (n, m)
res += make_link_tree(n)
l2r_count = m // 3
r2l_count = m // 3
rnd_count = m - l2r_count - r2l_count
W = [0 for i in range(n + 1)]
paths = []
s = randint(1, n)
W[s + (n - s) // 2] = (n - s) // 2
for i in range(l2r_count):
if randint(0, math.floor(math.sqrt(l2r_count))) == 0:
s = randint(1, n // 10)
W[s + (n - s) // 2] = (n - s) // 2
t = randint(s, n)
paths.append((s, t))
s = randint(1, n)
W[n - s // 2] = s // 2
for i in range(r2l_count):
if randint(0, math.floor(math.sqrt(r2l_count))) == 0:
s = randint(n - n // 10, n)
W[n - s // 2] = s // 2
t = randint(1, s)
paths.append((s, t))
for i in range(rnd_count):
s = randint(1, n)
t = randint(1, n)
paths.append((s, t))
for i in range(1, n + 1):
if W[i] == 0:
W[i] = randint(0, n)
for i in range(1, n + 1):
res += "%d" % W[i]
if i == n: res += "\n"
else: res += " "
for s, t in paths:
res += "%d %d\n" % (s, t)
return res
def make_mum_tree(n, start = 0):
res = ""
stem_count = n // 2
leaves_count = n // 2 - n // 10
for i in range(2, stem_count + 1):
res += "%d %d\n" % (i - 1 + start, i + start)
# f = stem_count
for i in range(stem_count + 1, stem_count + leaves_count + 1):
if randint(0, 10000) == 0:
f = randint(1, n)
else:
f = (i - stem_count) // 2 + stem_count
res += "%d %d\n" % (f + start, i + start)
for i in range(stem_count + leaves_count + 1, n + 1):
f = randint(1, i - 1)
res += "%d %d\n" % (f + start, i + start)
return res
def make_2mum_tree(n):
mum1_count = n // 2
mum2_count = n - mum1_count
res = make_mum_tree(mum1_count)
res += make_mum_tree(mum2_count, start = mum1_count)
res += "1 %d\n" % (mum1_count + 1,)
return res
def make_2mum(n, m):
res = "%d %d\n" % (n, m)
res += make_2mum_tree(n)
leaves_1 = (n // 4, n // 2)
leaves_2 = (n // 4 * 3, n)
#print(leaves_1)
for i in range(1, n + 1):
w = randint(1, n)
if i <= n // 2:
if i not in leaves_1 and randint(0, 10):
w = n // 4 - i
if randint(0, 4) == 0:
w = i + n // 2
w += randint(-1, 8)
else:
if i not in leaves_2 and randint(0, 10):
w = n - i - n // 4
if randint(0, 4) == 0:
w = i - n // 4
w += randint(-1, 8)
#print("i = %d w = %d\n" % (i, w))
if w <= 1:
w = randint(1, n)
w = min(w, n)
res += "%d" % w
if i == n: res += "\n"
else: res += " "
for i in range(m):
s = randint(1, n)
t = randint(1, n)
if randint(0, 10):
s = randint(*leaves_1)
t = randint(*leaves_2)
if randint(0, 1):
s, t = t, s
res += "%d %d\n" % (s, t)
return res
def make_s_e_1(n, m):
res = "%d %d\n" % (n, m)
res += make_mum_tree(n)
for i in range(1, n + 1):
w = i - 1
if randint(0, 5) == 0:
w = randint(1, n)
res += "%d" % w
if i == n: res += "\n"
else: res += " "
for i in range(n):
s = 1
t = 0
if randint(0, 3):
t = randint(n // 2, n)
else:
t = randint(1, n)
res += "%d %d\n" % (s, t)
return res
def make_t_e_1(n, m):
res = "%d %d\n" % (n, m)
res += make_mum_tree(n)
for i in range(1, n + 1):
w = randint(1, n)
if randint(0, 10) and i < n // 2:
w = n // 2 - i
w += randint(-3, 3)
w = min(w, n)
if w < 1:
w = randint(1, n)
res += "%d" % w
if i == n: res += "\n"
else: res += " "
for i in range(n):
s = 0
t = 1
if randint(0, 3):
s = randint(n // 2, n)
else:
s = randint(1, n)
res += "%d %d\n" % (s, t)
return res
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = "Data maker of running.")
parser.add_argument("type", type = str, help = "Data type.")
parser.add_argument("N", type = int)
parser.add_argument("M", type = int)
args = parser.parse_args()
data = ""
if args.type == "sieti":
data = make_si_e_ti(args.N, args.M)
elif args.type == "wje0":
data = make_wj_e_0(args.N, args.M)
elif args.type == "r":
data = make_r(args.N, args.M)
elif args.type == "l":
data = make_l(args.N, args.M)
elif args.type == "se1":
data = make_s_e_1(args.N, args.M)
elif args.type == "te1":
data = make_t_e_1(args.N, args.M)
elif args.type == "2mum":
data = make_2mum(args.N, args.M)
else:
print("Please indicate proper data type!")
sys.exit(-1)
print(data)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
NOIP2016复赛数据 (395个子文件)
earthworm20.ans 1.87MB
earthworm19.ans 1.83MB
earthworm18.ans 1.5MB
earthworm16.ans 1.5MB
earthworm14.ans 1.43MB
magic20.ans 1.38MB
earthworm12.ans 1.33MB
earthworm13.ans 1.29MB
earthworm15.ans 1.28MB
earthworm10.ans 1.15MB
earthworm11.ans 1.15MB
earthworm8.ans 1020KB
earthworm9.ans 1020KB
earthworm17.ans 870KB
running20.ans 691KB
earthworm3.ans 673KB
magic19.ans 666KB
port19.ans 464KB
port17.ans 464KB
port16.ans 464KB
port18.ans 464KB
port20.ans 464KB
port15.ans 463KB
running10.ans 358KB
running11.ans 358KB
running9.ans 358KB
running12.ans 358KB
magic18.ans 317KB
running17.ans 281KB
running19.ans 281KB
running18.ans 280KB
running15.ans 272KB
running14.ans 271KB
running13.ans 271KB
running16.ans 270KB
running6.ans 196KB
running8.ans 196KB
running7.ans 196KB
magic17.ans 145KB
magic16.ans 50KB
problem20.ans 40KB
problem16.ans 36KB
problem18.ans 36KB
problem12.ans 27KB
problem14.ans 22KB
magic15.ans 22KB
problem10.ans 22KB
earthworm7.ans 21KB
earthworm5.ans 20KB
problem6.ans 19KB
problem2.ans 17KB
magic14.ans 15KB
problem8.ans 14KB
earthworm6.ans 12KB
problem4.ans 10KB
magic13.ans 10KB
earthworm2.ans 7KB
earthworm4.ans 6KB
magic12.ans 6KB
magic11.ans 4KB
magic10.ans 3KB
magic9.ans 2KB
running5.ans 2KB
running3.ans 2KB
running4.ans 2KB
running2.ans 2KB
running1.ans 2KB
port10.ans 2KB
port9.ans 2KB
port14.ans 2KB
port12.ans 2KB
port11.ans 2KB
port13.ans 2KB
magic8.ans 2KB
magic7.ans 1KB
magic6.ans 837B
magic5.ans 518B
magic4.ans 324B
magic3.ans 228B
port8.ans 191B
port6.ans 189B
port7.ans 182B
port5.ans 181B
magic2.ans 144B
magic1.ans 96B
angrybirds6.ans 60B
angrybirds11.ans 60B
angrybirds14.ans 60B
angrybirds13.ans 60B
angrybirds2.ans 60B
angrybirds12.ans 60B
angrybirds4.ans 60B
angrybirds15.ans 30B
angrybirds17.ans 30B
angrybirds16.ans 30B
port3.ans 27B
port4.ans 26B
angrybirds1.ans 20B
angrybirds3.ans 20B
angrybirds8.ans 20B
共 395 条
- 1
- 2
- 3
- 4
资源评论
kevin_khb
- 粉丝: 15
- 资源: 27
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功