結果

問題 No.648  お や す み 
ユーザー Yuki_UtaaiYuki_Utaai
提出日時 2018-05-27 23:23:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,798 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 9,448 KB
最終ジャッジ日時 2023-09-12 19:52:23
合計ジャッジ時間 71,338 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 776 ms
9,412 KB
testcase_01 WA -
testcase_02 AC 771 ms
9,208 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 807 ms
9,260 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 784 ms
9,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 786 ms
9,216 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 785 ms
9,416 KB
testcase_24 WA -
testcase_25 AC 794 ms
9,216 KB
testcase_26 AC 1,771 ms
9,220 KB
testcase_27 AC 780 ms
9,296 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 775 ms
9,212 KB
testcase_34 WA -
testcase_35 AC 802 ms
9,220 KB
testcase_36 AC 779 ms
9,220 KB
testcase_37 AC 774 ms
9,416 KB
testcase_38 AC 773 ms
9,272 KB
testcase_39 AC 778 ms
9,212 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 804 ms
9,208 KB
testcase_45 WA -
testcase_46 AC 797 ms
9,272 KB
testcase_47 AC 784 ms
9,224 KB
testcase_48 AC 778 ms
9,276 KB
testcase_49 WA -
testcase_50 AC 856 ms
9,216 KB
testcase_51 AC 814 ms
9,292 KB
testcase_52 AC 842 ms
9,340 KB
testcase_53 WA -
testcase_54 AC 822 ms
9,380 KB
testcase_55 AC 808 ms
9,352 KB
testcase_56 AC 808 ms
9,208 KB
testcase_57 AC 840 ms
9,300 KB
testcase_58 WA -
testcase_59 AC 849 ms
9,208 KB
testcase_60 AC 809 ms
9,260 KB
testcase_61 AC 790 ms
9,208 KB
testcase_62 WA -
testcase_63 AC 826 ms
9,276 KB
testcase_64 AC 811 ms
9,284 KB
testcase_65 WA -
testcase_66 WA -
testcase_67 AC 818 ms
9,256 KB
testcase_68 AC 829 ms
9,424 KB
testcase_69 AC 808 ms
9,276 KB
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 806 ms
9,200 KB
testcase_73 AC 809 ms
9,288 KB
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 AC 853 ms
9,336 KB
testcase_78 WA -
testcase_79 AC 842 ms
9,420 KB
testcase_80 AC 824 ms
9,280 KB
testcase_81 AC 852 ms
9,292 KB
testcase_82 WA -
testcase_83 AC 840 ms
9,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import random

#--------粒 子 群 最 適 化------------------------------

#評価関数: 
def criterion(x, y):
    z=-abs(k-(x*(x+1))/2)
    return z

#粒子の位置の更新を行う関数
def update_position(x, y, vx, vy):
    new_x = x + vx
    new_y = y + vy
    return new_x, new_y

#粒子の速度の更新を行う関数
def update_velocity(x, y, vx, vy, p, g, w=0.5, ro_max=1):
    #パラメーターroはランダムに与える
    ro1 = random.uniform(0, ro_max)
    ro2 = random.uniform(0, ro_max)
    #粒子速度の更新を行う
    new_vx = w * vx + ro1 * (p[0] - x) + ro2 * (g[0] - x)
    new_vy = w * vy + ro1 * (p[1] - y) + ro2 * (g[1] - y)
    return new_vx, new_vy

def main():
    N = 600  #粒子の数
    x_min, x_max = 0, k
    y_min, y_max = 0, 0
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [[random.uniform(x_min, x_max), random.uniform(y_min, y_max)] for i in range(N)]
    vs = [[0.0, 0.0] for i in range(N)]

    personal_best_positions = list(ps)
    personal_best_scores = [criterion(p[0], p[1]) for p in ps]
    best_particle = personal_best_scores.index(max(personal_best_scores))
    global_best_position = personal_best_positions[best_particle]



    T = 300  #世代数(ループの回数)
    for t in range(T):
        for n in range(N):
            x, y = ps[n][0], ps[n][1]
            vx, vy = vs[n][0], vs[n][1]
            p = personal_best_positions[n]

            #粒子の位置の更新を行う
            new_x, new_y = update_position(x, y, vx, vy)
            ps[n] = [new_x, new_y]

            #粒子の速度の更新を行う
            new_vx, new_vy = update_velocity(new_x, new_y, vx, vy, p, global_best_position)
            vs[n] = [new_vx, new_vy]

            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x, new_y)
            if score > personal_best_scores[n]:
                personal_best_scores[n] = score
                personal_best_positions[n] = [new_x, new_y]

        #グローバルベストの更新を行う
        best_particle = personal_best_scores.index(max(personal_best_scores))
        global_best_position = personal_best_positions[best_particle]

    #最適解

#    print(max(personal_best_scores), global_best_position)
    return max(personal_best_scores), global_best_position[0], global_best_position[1]
#--------------------------------------------------------------

k=int(input())
best=100000000000000
xx=0
yy=0
for i in range(3):
    kouho_best, kouho_x, kouho_y=main()
    if best>kouho_best:
        best=kouho_best
        xx=kouho_x
        yy=kouho_y
 
#print(best)
if best>-0.000000000001:
    print("YES")
    print(int(xx))
else:
    print("NO")
0