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. NFV/SDN驱动OSS转型

  2. [转]聊聊技术选型 - Angular2 vs Vue2

    转载:https://juejin.im/post/58cab85b44d9040069f38f7a "Come, and take choice of all my library, An ...

  3. pytorch 学习问题

    https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html#sphx-glr-beginner-blitz-n ...

  4. JQuery巧妙利用CSS操作打印样式

    一.添加打印样式 1. 为屏幕显示和打印分别准备一个css文件,如下所示:  用于屏幕显示的css: <link rel="stylesheet" href="cs ...

  5. 以AVL树为例理解二叉树的旋转(Rotate)操作

    树旋转是在二叉树中的一种子树调整操作, 每一次旋转并不影响对该二叉树进行中序遍历的结果. 树旋转通常应用于需要调整树的局部平衡性的场合. 树旋转包括两个不同的方式, 分别是左旋转和右旋转. 两种旋转呈 ...

  6. 为什么好多人说win8不好用?

    2012年8月就開始接触win8了,那时win8已经出来半年了:自从用了win8之后就感觉他比xp.win7桌面更绚丽.我就喜欢绚丽的桌面.至今使用win8已经两年了,可发现身边好多人都说win8不好 ...

  7. 王立平-- android:layout_weight

    效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQyNTUyNw==/font/5a6L5L2T/fontsize/400/fill/I0 ...

  8. 在Fedora10上安装MySQL5.0.18,告捷!

    又一次安MySQL了,为什么又呢,因为前面成功那次算配置,即配置Fedora10自带的MySQL,这个还不算自己安装的,所以有必要再安装一次,以后还装也有可能,换操作系统,换MySql版本都可能这样做 ...

  9. 【Android 百度地图实战】1.构建一个基础的地图页面

    虽然很简单,但是还是有些细节要注意的,小错误搞死人啊,具体步骤官网API已提供,地址在这. 效果图如下: 主要代码: package yc.example.yc_ebaidumap; import a ...

  10. 如何使用屏幕取色工具ColorPixl

    ColorPix可以屏幕取色,假如现在想要取色桌面徽标键的颜色,按任意键可以锁定这个区域(press any key to lock)这样我们就可以在放大的区域更清楚的取色,加号按钮可以设置该软件是否 ...