Codeforces 853D 贪心
来源:互联网 发布:淘宝店如何退货 编辑:程序博客网 时间:2024/05/16 15:52
原题链接:http://codeforces.com/problemset/problem/853/D
大致题意:有n个物品,每个物品的价格是1000或者2000,每次不用积分以全额买下一个物品可以累积10%*商品价格的积分。积分可以在后面的购物中用积分来抵消等同积分的花费。问依次买下这n个物品的最小花费是多少。
先考虑物品价格只有1000的情况,显然每购买10个物品就可以用1000积分来买1个物品,最后剩下不足11物品时,除了最后一个物品用积分抵扣花销,其他的都是全额购买的方案是最优的。因为这种方案用掉了最多的积分。
再考虑加入价格为2000的物品的情况。对于所有的物品,每总价格为2200的分为一组,显然在每一组中都可以用除最后一个物品的其他物品来累计积分从而以0花费得到最后一个价格2000的物品或是最后2个价格为1000的物品。然后除了最后一组物品的总价格不满2200,其他组都可以贡献2000积分用来抵消价格。
对于最后一组,则除了一个价格为2000的物品使用积分其他的全额购买,则可以贡献总价格S * 10 div 11 的积分使用量。
但是要特判当所有物品总价格不超过11000时,最后一个物品价格为2000的情况。
还有就是当所有物品价格为2000时,最后一组的总价格S * 10 div 11的积分为(2*k+1)*100时应该改为2*k*100积分。
代码:
#include <bits/stdc++.h>using namespace std;inline void read(int &x){ char ch; bool flag=false; for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true; for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); x=flag?-x:x;}inline void read(long long &x){ char ch; bool flag=false; for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true; for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); x=flag?-x:x;}inline void write(int x){ static const int maxlen=100; static char s[maxlen]; if (x<0) { putchar('-'); x=-x;} if(!x){ putchar('0'); return; } int len=0; for(;x;x/=10) s[len++]=x % 10+'0'; for(int i=len-1;i>=0;--i) putchar(s[i]);}const int MAXN = 410000;int a[ MAXN ];int n;int main(){ read(n); int sum=0; int ans=0; int tot=0; for (int i=1;i<=n;i++) { read(a[i]); sum+=a[i]/1000; if ( a[i]==1000) tot++; } int tmp = 10*sum/11; if ( sum <= 11 ) tmp = sum - a[n] /1000; if ( ( !tot ) && ( tmp % 2 ==1 ) ) tmp--; printf("%d\n",sum*1000-tmp*100); return 0;}
阅读全文
0 0
- Codeforces 853D 贪心
- CodeForces 545D贪心
- codeforces 276D 贪心
- CodeForces-748D 贪心
- Codeforces 758D 贪心
- Codeforces 767D 贪心
- CodeForces 825D(贪心)
- codeforces 116D Lawnmowe 贪心
- Codeforces 534D Handshakes(贪心)
- Codeforces 609D 贪心+二分
- CodeForces 101D Castle (贪心)
- CodeForces 623D Birthday (贪心)
- 【Codeforces 534D】【贪心】Handshakes
- codeforces 732D (二分 贪心)
- 【codeforces 732D】【二分+贪心】
- Codeforces #732D 二分 贪心
- CodeForces 363D 【二分+贪心】
- codeforces - 276D【贪心+数学】
- Maven使用注解联合查询
- LintCode-两数之和
- Linux命令
- 51Nod 1003 阶乘后面0的数量
- 表空间管理
- Codeforces 853D 贪心
- MongoDB实战-分片集群的管理
- 第六课 Tensorflow Cifar10 CNN 卷积神经网络
- 次短路(hdu 6181)
- 生活小记7
- 互斥锁 自旋锁 读写锁的区别
- mybatis开发模式
- java实现从网上下载文件到本地
- SpringMVC原理及SpringMVC搭建详解