题:
-
总时间限制:
- 1000ms 内存限制:
- 65536kB
-
描写叙述
-
某网上书店举行优惠促销,现有两种优惠策略。策略一是购书总额大于100元的可享受免费送货。策略二是假设购书数量大于3本,则购书总额享受95折优惠(不包含运费)。两种优惠策略不能同一时候享受,最多可选择当中一种优惠策略。运费为20元。小明想在这个站点上买书,请帮他选择最优的优惠策略。
输入
- 有多行。第一行是买书的种类N(0 <= N <= 100),接下来的N行每行输入一种书目的购买数量M和代价P(P不一定是整数)。当N为-1时结束输入 输出
- 针对每组数据,分析怎样享受优惠策略,输出最少的购书支付金额 例子输入
-
2 2 60 3 50 -1
例子输出
-
270
解:
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
if(n==-1)
{
break;
}
double a[n],b[n];
for(int i=0;i<n;i++)
{
cin>>a[i]>>b[i];
}
int All=0;
double AllMoney=0;
double Cost1=0;
double Cost2=0;
for(int i=0;i<n;i++)
{
All+=a[i];
AllMoney+=a[i]*b[i];
}
Cost1=AllMoney;
Cost2=AllMoney;
if(All>3)
{
Cost1*=0.95;
Cost1+=20;
}
else{
Cost1+=20;
}
if(AllMoney>100)
{
}
else
{
Cost2+=20;
}
if(Cost1<Cost2)
{
cout<<Cost1<<endl;
}
else
{
cout<<Cost2<<endl;
}
}
return 0;
}