1 条题解
-
0
练17.2 公园门票
解题思路
购票数达到 30 时全部票价为每张 48,否则每张 50,选择单价后乘人数。
正确性说明
数量条件确定唯一适用单价,所有票按该单价收费。
易错点
30 张含在优惠中;人数可很大,总价用 long long。
复杂度
输入规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; cout << n * (n >= 30 ? 48 : 50) << "\n"; return 0; }
- 1