作為 Nasty Hacks Inc. 的 CEO,你面臨一個經典的商業決策:是否投放廣告以最大化利潤。分析師提供了三個關鍵數據:不投放廣告的預期收入 r、投放廣告的預期收入 e 以及廣告成本 c。你的任務是根據這些數據,判斷「投放廣告」、「不投放廣告」還是「無差異」。
實際上,這是一道典型的「水題」。只需比較兩種情況下的淨收益:
re - c根據比較結果輸出決策:
r > e - c → do not advertiser < e - c → advertiser == e - c → does not matter第一行為測試用例數 n,隨後 n 行每行包含三個整數 r, e, c。對每組數據輸出一行決策結果。
Sample Input:
3
0 100 70
100 130 30
-100 -70 40
Sample Output:
advertise
does not matter
do not advertise
第一組:0 < 100-70=30 → 投放;第二組:100 == 130-30 → 無差異;第三組:-100 > -70-40=-110 → 不投放。
#include <iostream>
using namespace std;
int main() {
int n, r, e, c;
cin >> n;
while (n--) {
cin >> r >> e >> c;
int net = e - c;
if (r > net) cout << "do not advertise";
else if (r < net) cout << "advertise";
else cout << "does not matter";
if (n) cout << endl;
}
return 0;
}
時間複雜度 O(n),空間複雜度 O(1),極其高效。
這道題考察的就是基本的條件判斷與輸入處理,適合作為入門練習。關鍵在於正確理解「預期收入」與「廣告成本」的關係,並注意輸出字串的精確拼寫。