#30051: 不知道哪邊錯了,請各位幫忙,題目的範例測姿是可以的


momochien0101@gmail.com (momo chien)

學校 : 不指定學校
編號 : 147237
來源 : [36.225.106.27]
最後登入時間 :
2022-04-25 09:46:06
f312. 1. 人力分配 -- 2020年10月APCS | From: [36.225.106.27] | 發表日期 : 2022-04-25 09:47

#include<iostream>

using namespace std;

int main(){

int A1,B1,C1,A2,B2,C2,n;

int profit1,profit2;

 

 

 

cin>>A1>>B1>>C1;

cin>>A2>>B2>>C2;

cin>>n;

int max=0;

int storage[n];

 

for(int i=0;i<=n;i++){

profit1=A1*i+B1*(n-i)+C1;

profit2=A2*(n-i)+B2*i+C2;

storage[i]=profit1+profit2;

if(storage[i]>max){

    max=storage[i];

}

 

 

 

}

 

 

cout<<max;

 

return 0;

}

 
#30067: Re: 不知道哪邊錯了,請各位幫忙,題目的範例測姿是可以的


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
f312. 1. 人力分配 -- 2020年10月APCS | From: [27.246.161.196] | 發表日期 : 2022-04-25 21:46

1.

int max=0;

2.

profit1=A1*i+B1*(n-i)+C1;

profit2=A2*(n-i)+B2*i+C2;

  1.  收益可能小於0,所以max初始值不能用0
  2. 題目收益的公式看清楚,收益不是這樣算的

 

 
ZeroJudge Forum