我的解答:
import sys
for line in sys.stdin:
if line != "\n":
N = int(line)
Nvalues = [int(i) for i in input().split()]
Target = int(input())
solves = []
if N == 5:
for i in range(int(Target//Nvalues[0])+1):
for j in range(int(Target//Nvalues[1])+1):
for k in range(int(Target//Nvalues[2])+1):
for l in range(int(Target//Nvalues[3])+1):
for m in range(int(Target//Nvalues[4])+1):
stopN = Target - (i*Nvalues[0]+j*Nvalues[1]+k*Nvalues[2]+l*Nvalues[3]+m*Nvalues[4])
if stopN == 0:
printStr = '('+str(i)+','+str(j)+','+str(k)+','+str(l)+','+str(m)+')'
print(printStr)
if N == 4:
for i in range(int(Target//Nvalues[0])+1):
for j in range(int(Target//Nvalues[1])+1):
for k in range(int(Target//Nvalues[2])+1):
for l in range(int(Target//Nvalues[3])+1):
stopN = Target - (i*Nvalues[0]+j*Nvalues[1]+k*Nvalues[2]+l*Nvalues[3])
if stopN == 0:
printStr = '('+str(i)+','+str(j)+','+str(k)+','+str(l)+')'
print(printStr)
if N == 3:
for i in range(int(Target//Nvalues[0])+1):
for j in range(int(Target//Nvalues[1])+1):
for k in range(int(Target//Nvalues[2])+1):
stopN = Target - (i*Nvalues[0]+j*Nvalues[1]+k*Nvalues[2])
if stopN == 0:
printStr = '('+str(i)+','+str(j)+','+str(k)+')'
print(printStr)
if N == 2:
for i in range(int(Target//Nvalues[0])+1):
for j in range(int(Target//Nvalues[1])+1):
stopN = Target - (i*Nvalues[0]+j*Nvalues[1])
if stopN == 0:
printStr = '('+str(i)+','+str(j)+')'
print(printStr)
if N == 1:
for i in range(int(Target//Nvalues[0])+1):
stopN = Target - (i*Nvalues[0])
if stopN == 0:
printStr = '('+str(i)+')'
print(printStr)
else:
break
送出測試:
送出解答:
資料來源:
1.高中生解題系統
2.
ZeroJudge解題
ZeroJudge python解答:a004. 文文的求婚 ZeroJudge python解答:a005. Eva 的回家作業
ZeroJudge python解答:a006. 一元二次方程式
ZeroJudge python解答:a009. 解碼器
ZeroJudge python解答:a010. 因數分解
ZeroJudge python解答:a015. 矩陣的翻轉
ZeroJudge python解答:a017. 五則運算
ZeroJudge python解答:a020. 身分證檢驗
ZeroJudge python解答:a021. 大數運算
ZeroJudge python解答:a022. 迴文
ZeroJudge python解答:a024. 最大公因數(GCD)
ZeroJudge python解答:a034. 二進位制轉換
ZeroJudge python解答:a038. 數字翻轉
ZeroJudge python解答:a040. 阿姆斯壯數
ZeroJudge python解答:a042. 平面圓形切割
ZeroJudge python解答:a044. 空間切割
ZeroJudge python解答:a053. Sagit's 計分程式
ZeroJudge python解答:a054. 電話客服中心
ZeroJudge python解答:a058. MOD3
ZeroJudge python解答:a059. 完全平方
ZeroJudge python解答:a065. 提款卡密碼
ZeroJudge python解答:a104. 排序
ZeroJudge python解答:a121. 質數又來囉
ZeroJudge python解答:a148. You Cannot Pass?!
ZeroJudge python解答:a149. 乘乘樂
ZeroJudge python解答:a215. 明明愛數數
ZeroJudge python解答:a216. 數數愛明明
ZeroJudge python解答:a224. 明明愛明明
ZeroJudge python解答:a225. 明明愛排列
ZeroJudge python解答:a244. 新手訓練 ~ for + if
ZeroJudge python解答:a248. 新手訓練 ~ 陣列應用
ZeroJudge python解答:a263. 日期差幾天
ZeroJudge python解答:a291. nAnB problem
ZeroJudge python解答:a410. 解方程
ZeroJudge python解答:a528. 大數排序
ZeroJudge python解答:a647. 投資專家
ZeroJudge python解答:a693. 吞食天地
ZeroJudge python解答:a694. 吞食天地二ZeroJudge python解答:a410. 解方程
ZeroJudge python解答:a528. 大數排序
ZeroJudge python解答:a647. 投資專家
ZeroJudge python解答:a693. 吞食天地
ZeroJudge python解答:a738. 最大公约数
沒有留言:
張貼留言