#42547: 答案


yp11351100@yphs.tp.edu.tw (701裡最聰明的辣個人)

學校 : 臺北市私立延平高級中學
編號 : 276234
來源 : [203.72.178.1]
最後登入時間 :
2024-09-12 17:29:03
m397. 烤肉 (BBQ) -- TOI練習賽202310新手組第2題 | From: [203.72.178.1] | 發表日期 : 2024-10-01 17:38

#include<bits/stdc++.h>
using namespace std ;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) ;

    int n, m, x, y, ans = -1 ; // ans 是最後找出的豬肉串數

    cin >> n >> m >> x >> y ;

    for (int i=0;i<=m;i++) {
        if (x*i+y*(m-i) == n) // 店家收的錢正確
            ans = i ;         // 紀錄有幾串豬肉
    }
    if (ans == -1) // 收錯錢
        cout << "-1 -1" ;
    else            // 輸出正確的串數
        cout << ans << ' ' << m-ans ;

    return 0 ;
}

 
ZeroJudge Forum