#44481: 想知道為什麼過不了全部測資 內有//補述 c++


s211103@stu.tcssh.tc.edu.tw (121_06李龍穎)

學校 : 國立臺中第二高級中學
編號 : 246604
來源 : [203.71.212.249]
最後登入時間 :
2025-09-25 11:38:57

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, w1, w2, h1, h2, V, under=0, up=0,sum=0, change=0;
    //水量
    vector <int>Siesta;
    //高度
    vector <int>siesta;
    cin >> n >> w1 >> w2 >> h1 >> h2;
    //底面積
    under=pow(w1,2);
    up=pow(w2,2);
    //輸入每次裝水量
    for(int times=0;times<n;times++)
    {
        cin >>V;
        Siesta.push_back(V);
    }
    //高度目前到哪的測試
    for(int times=0;times<n;times++)
    {
        sum=sum+Siesta[times];
        //是否有超過底下的體積
        if(under*h1>sum)
        {
            siesta.push_back(sum/under);
        }
        else if(under*h1<sum)
        {
            //如果有超過底下的體積 那是否上方也有超過
            if(sum<under*h1+up*h2)
            {
                siesta.push_back(h1+(sum-under*h1)/up);
            }
            else if(under*h1+up*h2<=sum)
            {
                siesta.push_back(h1+h2);
                break;
            }
        }
    }
    //找出水量變化量的最大值
    change=siesta[0];
    for(int times=0;times<siesta.size()-1;times++)
    {
        change=max(change,siesta[times+1]-siesta[times]);
    }
    cout <<change;
    return 0;
}

#44487: Re: 想知道為什麼過不了全部測資 內有//補述 c++


leeguanhan0909@gmail.com (李冠翰)

學校 : 高雄市苓雅區復華高級中學國中部
編號 : 276558
來源 : [36.238.189.188]
最後登入時間 :
2025-06-11 22:19:49

#include
using namespace std;
int main()
{
    int n, w1, w2, h1, h2, V, under=0, up=0,sum=0, change=0;
    //水量
    vector Siesta;
    //高度
    vector siesta;
    cin >> n >> w1 >> w2 >> h1 >> h2;
    //底面積
    under=pow(w1,2);
    up=pow(w2,2);
    //輸入每次裝水量
    for(int times=0;times    {
        cin >>V;
        Siesta.push_back(V);
    }
    //高度目前到哪的測試
    for(int times=0;times    {
        sum=sum+Siesta[times];
        //是否有超過底下的體積
        if(under*h1>sum)
        {
            siesta.push_back(sum/under);
        }
        else if(under*h1        {
            //如果有超過底下的體積 那是否上方也有超過
            if(sum            {
                siesta.push_back(h1+(sum-under*h1)/up);
            }
            else if(under*h1+up*h2<=sum)
            {
                siesta.push_back(h1+h2);
                break;
            }
        }
    }
    //找出水量變化量的最大值
    change=siesta[0];
    for(int times=0;times    {
        change=max(change,siesta[times+1]-siesta[times]);
    }
    cout <    return 0;
}


if ( under*h1>sum)

    {

       (省略)

    }

    else if(under*h1<sum)

 

 這裡未考慮到相等的情況。

    elif (under*h1<sum)