Discount

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 984    Accepted Submission(s): 591

Problem Description

All the shops use discount to attract customers, but some shops doesn’t give direct discount on their goods, instead, they give discount only when you bought more than a certain amount of goods. Assume a shop offers a 20% off if your bill is more than 100 yuan, and with more than 500 yuan, you can get a 40% off. After you have chosen a good of 400 yuan, the best suggestion for you is to take something else to reach 500 yuan and get the 40% off.
For the customers’ convenience, the shops often offer some low-price and useful items just for reaching such a condition. But there are still many customers complain that they can’t reach exactly the budget they want. So, the manager wants to know, with the items they offer, what is the minimum budget that cannot be reached. In addition, although the items are very useful, no one wants to buy the same thing twice.
 
Input
The input consists several testcases.
The first line contains one integer N (1 <= N <= 1000), the number of items available.
The second line contains N integers Pi (0 <= Pi <= 10000), represent the ith item’s price.

 
Output
Print one integer, the minimum budget that cannot be reached.
 
Sample Input
4 1 2 3 4
 
Sample Output
11
 
Source
 
Recommend
lcy
 
       这道题,开始以为是母函数,后来觉得数据处理貌似不行。又改为背包,内存直接爆掉了!!,我勒个去,没得办法,之后去了一趟度娘那,
  才发现是一道.....貌似不能归于哪一类,就是杂谈吧!
       方法是这样的...先进行排序(由小到大)也就是升序....然后用他后面n-1一项的和加1来与当前这项比较,如果当前这项小于前者之和加1,那么就是这个数
      ,是不能被组合出来的...
       就拿 1 2 3 4 这组数据来讲吧.... 开始 sum=0; sum+1<1 ,不满足,所以跳到下一个数,此时sum=1; sum+1<2.。又不满足,所以继续...依次-----最后..还是不满足。
      所以就输出 sum+1( 注意此时的sum=1+2+3+4=10),所以 输出的是10.
      再比如 1 3 4 5  begin sum=0; sum+1<1 不满足,继续...sum+=1;sum+1<3;满足,所以终止,输出;
     依据这一原理:
     代码如下:

 #include<iostream>
#include<cstdio>
#include<algorithm>
#define maxn 1001
using namespace std;
int value[maxn];
int main()
{
int n,i,sum;
while(~scanf("%d",&n))
{
for(i=;i<n;i++)
scanf("%d",value+i);
sort(value,value+n);
sum=;
for(i=;i<n;i++)
{
if(sum+<value[i])
break;
sum+=value[i];
}
cout<<sum+<<endl;
}
return ;
}

要成为高手千万不要复制

 

HDUOJ-4104 Discount的更多相关文章

  1. HDU 4104 Discount(n个数不能构成的最小值)

    http://acm.hdu.edu.cn/showproblem.php?pid=4104 题意:给出n个数,每个数最多只能用一次,每次可以选任意个数相加,求不能相加得到的最小值是多少. 思路: 先 ...

  2. hdu 4104 Discount

    http://acm.hdu.edu.cn/showproblem.php?pid=4104 一开始还以为这题是背包,然后优化下这个背包,但是一直都优化不出来. 然后题解是直接模拟而已,唉 先从小到大 ...

  3. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  4. 【BZOJ 4104】【Thu Summer Camp 2015】解密运算

    http://www.lydsy.com/JudgeOnline/problem.php?id=4104 网上题解满天飞,我也懒得写了 #include<cstdio> #include& ...

  5. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  6. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  7. Discount Diesel Time 9150-1 Quartz Wrist watch [WAT022]- US$4.49

    Discount Diesel Time 9150-1 Quartz Wrist watch [WAT022]- US$4.49 Diesel Time 9150-1 Quartz Wrist wat ...

  8. hdu-oj 1874 畅通工程续

    最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...

  9. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  10. C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...

随机推荐

  1. Derby安装,创建数据库,在Java程序中使用Derby

    1,下载并安装Derby: 下载地址:http://db.apache.org/derby /derby_downloads.html,下载最新版本. 我用的是10.5.3.0. 解压缩到任意文件夹, ...

  2. CVPR14 图像检索papers

    CVPR14年关于图像检索方面的papers,汇总成一个list,方便阅读. 图像检索 Triangulation embedding and democratic aggregation for i ...

  3. 【屌丝程序的口才逆袭演讲稿50篇】第十三篇:爱迪生欺骗了我们!【张振华.Jack】

    演讲稿主题:<爱迪生欺骗了我们>                      --作者:张振华Jack.摘抄<马云为雅虎员工的演讲稿:爱迪生欺骗了我们> 非常多人都记得爱迪生说的 ...

  4. Python并发编程-Redis

    Redis 简介 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Remote Dictionary Server(Redis)是一个基于 key-value ...

  5. C# WinForm开发系列 - GDI+【转】

    http://blog.csdn.net/blue_sky6/article/details/53811435?locationNum=6&fps=1 C# WinForm开发系列 - GDI ...

  6. jquery 返回顶端组件

    自己写了一个基于jquery的返回页面顶端的组件. (function($) { var g; $.backtop = function(options) { extend($.backtop.con ...

  7. vue-router路由知识补充

    1.render函数 var app = new Vue({ el: '#app', router, render: h => h(App) //新添加的函数操作 }) 我们新加了render: ...

  8. Transform开发cube模型权限处理之不同用户数据的过滤

    ========================此文不再详细的说transform的开发过程====================================================== ...

  9. 向量的表示及协方差矩阵 (PCA的理论基础)

    原文:http://blog.csdn.net/songzitea/article/details/18219237 引言 当面对的数据被抽象为一组向量,那么有必要研究一些向量的数学性质.而这些数学性 ...

  10. 在简化版Fedora8上安装jdk-7u25-linux-i586.rpm的过程

    台式机的操作系统重新换回了Fedora8,遵从一些大牛的建议,把很多附件去了,尽量让系统保持最简化.这样能熟悉每个软件的安装配置过程,也能减少版本间的冲突. 进入控制台后,查查有没有Java存在系统中 ...