天天看點

2019年ccpc女生賽重制賽題解A

2019年ccpc女生賽重制賽題解A

題目:

Ticket

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 0 Accepted Submission(s): 0

Problem Description

北京地鐵票每月的打折規則為:本次乘車前總消費不足 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

思路:簽到題。維護字首和,對于每一個位置的計算需要根據字首和的大小來判斷乘多少。

AC代碼:

#include<bits/stdc++.h>
#define INF 0x3F3F3F3F
#define endl '\n'
#define pb push_back
#define css(n) cout<<setiosflags(ios::fixed)<<setprecision(n); 
#define sd(a) scanf("%d",&a)
#define sld(a) scanf("%lld",&a)
#define m(a,b) memset(a,b,sizeof a)
#define p_queue priority_queue
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n,m;
int t;
int arr[1005];
int sum[1005];
int main()
{
	sd(n);
	for(int i=1;i<=n;i++)
	{
		sd(arr[i]);
		sum[i]=sum[i-1]+arr[i];
	}
	double fin=0;
	for(int i=1;i<=n;i++)
	{
		if(sum[i-1]<100||sum[i-1]>=400)
		{
			fin+=arr[i]*1.0;
		}
		if(sum[i-1]>=100&&sum[i-1]<150)
		{
			fin+=arr[i]*1.0*0.8;
		}
		if(sum[i-1]>=150&&sum[i-1]<400)
		{
			fin+=arr[i]*1.0*0.5;
		}
	}
	printf("%.2lf\n",fin);
	return 0;
}