HDUOJ-4104 Discount
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
2011 Alibaba-Cup Campus Contest
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;满足,所以终止,输出;
依据这一原理:
代码如下:
1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #define maxn 1001
5 using namespace std;
6 int value[maxn];
7 int main()
8 {
9 int n,i,sum;
10 while(~scanf("%d",&n))
11 {
12 for(i=0;i<n;i++)
13 scanf("%d",value+i);
14 sort(value,value+n);
15 sum=0;
16 for(i=0;i<n;i++)
17 {
18 if(sum+1<value[i])
19 break;
20 sum+=value[i];
21 }
22 cout<<sum+1<<endl;
23 }
24 return 0;
25 }
- HUST 1588 辗转数对
- HUST 1584 摆放餐桌
- HUST 1585 排队
- 【QQ/微信个人号变身机器人】炸群+远程监控个人PC的尝试
- HUST 1583 长度单位
- FZU 2167 大王叫我来巡山呐
- HDU 1021 Fibonacci Again
- Hadoop数据分析平台实战——180Oozie工作流使用介绍离线数据分析平台实战——180Oozie工作流使用介绍
- 博弈论及算法实现
- Hadoop数据分析平台实战——160Sqoop介绍离线数据分析平台实战——160Sqoop介绍
- HDU 2186 悼念512汶川大地震遇难同胞——一定要记住我爱你
- Hadoop数据分析平台实战——150Flume介绍离线数据分析平台实战——150Flume介绍
- Codeforces 714A Meeting of Old Friends
- Code forces 719A Vitya in the Countryside
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 基于rest风格对Neo4j进行调用访问之———httpClient
- spring boot + mybatis 访问 neo4j
- window下通过ELK框架进行大型日志线下的可视化分析
- 一句话解释ThreadLocal类
- ElasticsSearch 之 倒排索引
- tomcat返回cookie有双引号问题
- 利用辗转相除法求最大公约数以及最小公倍数-Java
- 网络爬虫的风险
- git 使用小结大全
- Elasticsearch:search template
- 模仿echo命令学习BIO——Java实现
- 模仿echo命令学习NIO——Java实现
- Java 7 种阻塞队列详解
- protocol buffers 序列化数据
- dubbo的Failed to save registry store file问题