置頂

我的 VPython 教學文件 (HackMD 版本)

VPython 教學文件目錄 安裝及測試 基本語法 等速度直線運動 自由落下 終端速度 水平抛射 使用For迴圈計算水平抛射資料 斜向抛射 圓周運動 簡諧運動 單擺 木塊彈簧系統分離 重力及簡諧 行星運動 相疊木塊 雙重簡諧運動 一維彈性碰撞 ...

熱門文章

2026年1月23日 星期五

ZeroJudge 解題筆記:c006. 10550 - Combination Lock

作者:王一哲
日期:2026年1月23日


ZeroJudge 題目連結:c006. 10550 - Combination Lock

解題想法


刻度差 1 要轉 9 度,順時鐘方向轉刻度減少,逆時鐘方向轉刻度增加。

Python 程式碼


使用時間約為 8 ms,記憶體約為 2.8 MB,通過測試。
import sys

for line in sys.stdin:
    if line.rstrip() == "0 0 0 0":
        break
    a, b, c, d = map(int, line.split())
    tot = 360*3
    tot += 360 - (9*b + 360 - 9*a) % 360
    tot += (9*c + 360 - 9*b) % 360
    tot += 360 - (9*d + 360 - 9*c) % 360
    print(tot)


C++ 程式碼


使用時間約為 1 ms,記憶體約為 76 kB,通過測試。
#include <cstdio>

int main() {
    int a, b, c, d;
    while(scanf("%d %d %d %d", &a, &b, &c, &d) != EOF) {
        if (a == 0 && b == 0 && c == 0 && d == 0) break;
        int tot = 360*3;
        tot += 360 - (9*b + 360 - 9*a) % 360;
        tot += (9*c + 360 - 9*b) % 360;
        tot += 360 - (9*d + 360 - 9*c) % 360;
        printf("%d\n", tot);
    }
    return 0;
}


沒有留言:

張貼留言