#45387: 95% #14測資錯 救救我


s311207@stu.tcssh.tc.edu.tw (hehe boyyyyy)

學校 : 國立臺中第二高級中學
編號 : 285820
來源 : [61.224.147.50]
最後登入時間 :
2025-04-05 22:15:01
o711. 1. 裝飲料 -- 2024年10月APCS | From: [114.38.79.163] | 發表日期 : 2025-02-23 07:36

#include<bits/stdc++.h>

using namespace std;

int main(){
    int max_high = 0;
    int step,w1,w2,h1,h2;
    cin >> step>> w1>> w2>> h1>> h2;
    int vOfA= w1*w1*h1 , vOfB = w2*w2*h2 ;
    bool out = false;
    int nowV = 0 , k = 0;

    for(int i = 1; i <= step ; i++){
        //cout << k;

        int b;

        cin >> b;

        nowV += b;

        if(out == false && nowV <= vOfA){
            k = b/(w1*w1);
            if(k > max_high){
                max_high = k;
            }
            k = 0;

        }
        else if (out == true && nowV <= vOfA + vOfB){
            k = b/(w2*w2);
            if(k > max_high){
                max_high = k;
            }
            k = 0;
        }
        else if(out == false && (nowV > vOfA  && (nowV <= vOfA+vOfB) ) ){
            int g = nowV - vOfA;
            k =  g / (w2*w2);
            k += (b-g) / (w1*w1);
            if(k > max_high){
                max_high = k;
            }
            k = 0 ;
            out = true;
        }
        else if (out == true||b < nowV){
            int g = nowV - (vOfA + vOfB);
            k =  (b - g) / (w2*w2);
            if(k > max_high){
                    max_high = k;
            }
            k = 0 ;
        }
        else{
            max_high = h1 + h2;
        }
    }
    cout << max_high;
}
 
#45390: Re: 95% #14測資錯 救救我


leeguanhan0909@gmail.com (李冠翰)

學校 : 高雄市苓雅區復華高級中學國中部
編號 : 276558
來源 : [36.238.153.220]
最後登入時間 :
2025-04-05 17:05:47
o711. 1. 裝飲料 -- 2024年10月APCS | From: [36.238.140.196] | 發表日期 : 2025-02-23 18:18

#include

using namespace std;

int main(){
    int max_high = 0;
    int step,w1,w2,h1,h2;
    cin >> step>> w1>> w2>> h1>> h2;
    int vOfA= w1*w1*h1 , vOfB = w2*w2*h2 ;
    bool out = false;
    int nowV = 0 , k = 0;

    for(int i = 1; i <= step ; i++){
        //cout << k;

        int b;

        cin >> b;

        nowV += b;

        if(out == false && nowV <= vOfA){
            k = b/(w1*w1);
            if(k > max_high){
                max_high = k;
            }
            k = 0;

        }
        else if (out == true && nowV <= vOfA + vOfB){
            k = b/(w2*w2);
            if(k > max_high){
                max_high = k;
            }
            k = 0;
        }
        else if(out == false && (nowV > vOfA  && (nowV <= vOfA+vOfB) ) ){
            int g = nowV - vOfA;
            k =  g / (w2*w2);
            k += (b-g) / (w1*w1);
            if(k > max_high){
                max_high = k;
            }
            k = 0 ;
            out = true;
        }
        else if (out == true||b < nowV){
            int g = nowV - (vOfA + vOfB);
            k =  (b - g) / (w2*w2);
            if(k > max_high){
                    max_high = k;
            }
            k = 0 ;
        }
        else{
            max_high = h1 + h2;
        }
    }
    cout << max_high;
}

else if (out == true||b < nowV)
這行有誤

out==true在這裡才執行代表裝超過了,且是從第二杯開始裝。

b<nowV在這裡成立時代表還沒到第二杯,但是裝超過了,且它是第二個體積。所以要先算第一杯剩多少高度。

參考答案

 
ZeroJudge Forum