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. 《Windows核心编程》第五章——作业

    #include <windows.h> #include<iostream> #include <tchar.h> using namespace std; ty ...

  2. 如何使用C++回调函数

         程序猿经常须要实现回调.本文将讨论函数指针的基本原则并说明怎样使用函数指针实现回调.注意这里针对的是普通的函数,不包含全然依赖于不同语法和语义规则的类成员函数(类成员指针将在另文中讨论). ...

  3. Android图片加载框架最全解析(五),Glide强大的图片变换功能

    大家好,又到了学习Glide的时间了.前段时间由于项目开发紧张,再加上后来又生病了,所以停更了一个月,不过现在终于又可以恢复正常更新了.今天是这个系列的第五篇文章,在前面四篇文章的当中,我们已经学习了 ...

  4. 集合 数组 定义 转换 遍历 Arrays API MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  5. Javascript开发笔记:不完整的继承

    Javascript的继承和标准的oop继承有很大的区别,Javascript的继承是采用原型链的技术,每个类都会将“成员变量”和“成员函数”放到 prototype 上,Js++都过supercla ...

  6. Java基础(十一):接口

    一.接口: 接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是 ...

  7. Android的硬件抽象层模块编写规范

    硬件抽象层模块编写规范 ​ Android系统的硬件抽象层以模块的形式来管理各个硬件訪问接口.每个硬件模块都相应有一个动态链接库文件.这些动态链接库文件的命令须要符合一定的规范.同一时候,在系统内部. ...

  8. GO语言基础之reflect反射

    反射reflection 1. 反射可以大大的提高程序的灵活性,使得 interface{} 有更大的发挥余地 2. 反射使用 TypeOf 和 ValueOf 函数从接口中获取目标对象信息 3. 反 ...

  9. Android 如何修改默认输入法

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  10. 免费的HTML商业模板-Hidayah

    在线演示 在线演示 本地下载 在这款模板中,你可以随意缩放大小,适合笔记本.平板电脑或手机,非常方便阅读.