# j123. 2. 運貨站 ###### tags: `APCS` * 這題的概念不難,但判斷比較麻煩。基本上把所有情形列出來就會對。 * 開一個大小為 $r$ 的一維陣列,代表每一列( row ),其中的數字代表現在的最大長度,且最大長度不能超過 column。 * 特別要注意編號 $D$ 和 $E$,會有特殊情形。 ```C++= #include<bits/stdc++.h> using namespace std; int r,c,n,ind; string type; int blanks; int discard = 0; int loc_max; void check(vector<int> &mock){ if (type=="A"){ loc_max = max({mock[ind],mock[ind+1],mock[ind+2],mock[ind+3]}); if (loc_max+1<=c ){ mock[ind]=loc_max+1; mock[ind+1]=loc_max+1; mock[ind+2]=loc_max+1; mock[ind+3]=loc_max+1; blanks -= 4; //cout<<type<<endl; } else discard++; } else if (type == "B"){ if (mock[ind]+3<=c) { mock[ind]+=3; blanks -= 3; //cout<<type<<endl; } else discard++; } else if (type == "C"){ loc_max = max({mock[ind],mock[ind+1]}); if (loc_max+2<=c ){ mock[ind]=loc_max+2; mock[ind+1]=loc_max+2; blanks -= 4; //cout<<type<<endl; } else discard++; } else if (type == "D"){ // 特殊情形 1 if (mock[ind]-mock[ind+1]>=2 && mock[ind]+1<=c){ mock[ind]++; mock[ind+1] = mock[ind]; blanks-=4; } // 特殊情形 2 else if (mock[ind]-mock[ind+1]==1 && mock[ind]+2<=c){ mock[ind]+=2; mock[ind+1] = mock[ind]; blanks-=4; } else { loc_max = max({mock[ind],mock[ind+1]}); if (loc_max+3<=c ){ mock[ind]=loc_max+3; mock[ind+1]=loc_max+3; blanks -= 4; //cout<<type<<endl; } else discard++; } } else if (type == "E"){ // 特殊情形 if (mock[ind]-mock[ind+1]>=1 && mock[ind]-mock[ind+2]>=1 && mock[ind]+1<=c){ mock[ind]++; mock[ind+1] = mock[ind]; mock[ind+2] = mock[ind]; blanks-=5; } else { loc_max = max({mock[ind],mock[ind+1],mock[ind+2]}); if (loc_max+2<=c){ mock[ind]=loc_max+2; mock[ind+1]=loc_max+2; mock[ind+2]=loc_max+2; blanks-=5; //cout<<type<<endl; } else discard++; } } } int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>r>>c>>n; vector<int> mock(r,0); blanks = r*c; while(n--){ cin>>type>>ind; check(mock); //for (auto i:mock) cout<<i<<" "; cout<<endl; } cout<<blanks<<" "<<discard; } ```