HDU 6544_Ticket
题意分析:
北京地铁票每月的打折规则为:本次乘车前总消费不足 100 元本次不打折,满 100 元不足 150 元本次打8 折,满 150 元不足 400 元本次打 5 折,已满 400 元后本次不打折,已知 wls 每次出行的原票价,请问实际的花费是多少?
Input
输入包含两行。第一行一个整数 n 代表 wls 将要出行的次数。第二行 n 个正整数, ai 代表每次出行的票的原价,wls 是按照输入顺序依次出行的。
0 ≤ n ≤ 1, 000
0 < ai ≤ 1, 000
Output
一行一个数,代表实际的花费,保留小数点后两位小数。
Sample Input
3
100 20 20
Sample Output
132.00
就简单的分段模拟。
算法没什么好说的。
但是注意“乘车前总消费”,这个文字游戏真的离谱。
代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#define INF 0x3f3f3f3f
#define MAX 200100
#define ll long long
#define N 10010
using namespace std;
//一看IO流又是我亲爱的队友做的。
int main() {
int n;
while (scanf("%d", &n) != EOF) {
double ans = 0;
double res = 0;
for (int i = 0; i < n; i++) {
double t;
scanf("%lf", &t);
if (ans < 100) {
res += t;
} else if (ans < 150) {
res += (double) t * 0.8;
} else if (ans < 400) {
res += t * 0.5;
} else {
res += t;
}
//cout << ans << endl;
ans += t;
}
//cout << ans << endl;
cout << fixed << setprecision(2) << res << endl;
}
}
算法没什么好说的,记得好好读题,正式比赛不要犯这种错误了!
不然还挺可惜的。以及没参与讨论的题目不要轻易否认队友的想法。我忏悔!