拼不出的数

lost.in/.out/.cpp

【问题描述】

3 个元素的集合 {5, 1, 2} 的所有子集的和分别是 0, 1, 2, 3, 5, 6, 7, 8。发 现最小的不能由该集合子集拼出的数字是 4。

现在给你一个 n 个元素的集合,问你最小的不能由该集合子集拼出的 数字是多少。

注意 32 位数字表示范围。

【输入格式】

第一行一个整数 n。

第二行 n 个正整数 a i ,表示集合内的元素。

【输出格式】

一行一个整数答案。

【样例输入】

3

5 1 2

【样例输出】

4

【数据规模和约定】

对于 30% 的数据,满足 n ≤ 15。

对于 60% 的数据,满足 n ≤ 1000。

对于 100% 的数据,满足 n ≤ 100000, 1 ≤ a i ≤ 10^9 。保证 a i 互不相同。

【限制】

时间:1S

内存:256M

水题看代码

#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long const int maxn = ;
int a[maxn];
int n,m;
int main () {
scanf("%d",&n);
for(int i=;i<=n;++i)scanf("%d",a+i);
LL sum=;
sort(a+,a+n+);
for(int i=;i<=n;++i) {
if(a[i]>sum+){
printf("%lld\n",sum+);return ;
}
sum+=a[i];
}
printf("%lld\n",sum+);
return ;
}

GRYZY #13. 拼不出的数的更多相关文章

  1. 2017.10.5 国庆清北 D5T1 拼不出的数

    题目描述 3 个元素的集合{5,1,2}的所有子集的和分别是0,1,2,3,5,6,7,8.发现最小的不能由该集合子集拼出的数字是4. 现在给你一个n个元素的集合,问你最小的不能由该集合子集拼出的数字 ...

  2. noip模拟赛 拼不出的数

    分析:如果每个数可以选任意多次,那么就是一个很普通的dp问题,这里每个数只能选一次,还是考虑dp,设f(i)表示1~i是否都能选上.考虑下一个数j,如果j > i + 1,那么i+1这个数就选不 ...

  3. 2016年12月13日 星期二 --出埃及记 Exodus 21:8

    2016年12月13日 星期二 --出埃及记 Exodus 21:8 If she does not please the master who has selected her for himsel ...

  4. 2016年11月13日 星期日 --出埃及记 Exodus 20:4

    2016年11月13日 星期日 --出埃及记 Exodus 20:4 "You shall not make for yourself an idol in the form of anyt ...

  5. 2016年10月13日 星期四 --出埃及记 Exodus 18:24

    2016年10月13日 星期四 --出埃及记 Exodus 18:24 Moses listened to his father-in-law and did everything he said.于 ...

  6. 用JAVA写一个函数,功能例如以下: 随意给定一组数, 找出随意数相加之后的结果为35(随意设定)的情况

    用JAVA写一个函数.功能例如以下:随意给定一组数,比如{12,60,-8,99,15,35,17,18},找出随意数相加之后的结果为35(随意设定)的情况. 能够递归算法来解: package te ...

  7. 【C语言】不使用大小于号,求出两数最大值

    //不使用大小于号,求出两数最大值 #include <stdio.h> #include <math.h> double Max(double a, double b) { ...

  8. 学习笔记13—python DataFrame获取行数、列数、索引及第几行第几列的值

    1. df=DataFrame([{‘A’:’11’,’B’:’12’},{‘A’:’111’,’B’:’121’},{‘A’:’1111’,’B’:’1211’}]) print df.column ...

  9. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-3 模态弹出框

    模态弹出框(Modals) 这一小节我们先来讲解一个“模态弹出框”,插件的源文件:modal.js. 右侧代码编辑器(30行)就是单独引入 bootstrap 中发布出的“modal.js”文件. 样 ...

随机推荐

  1. Bootstrap历练实例:小的按钮

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  2. Swift 编程思想 Part 4:map all the things!

    Swift 编程思想 Part 4:map all the things! 2015-10-22  837 文章目录 1. 数组 vs. 可选类型 2. 作用在可选类型上的 map() 3. 回到我们 ...

  3. windows下pycharm使用Anaconda安装包环境

    转自: https://www.cnblogs.com/heitaoq/p/8632315.html

  4. easyUI 之datagrid 在前端自定义排序

    首先先来看一下,直接从后台读取数据并展示到前端的列表,后端传回的数据是“按商品ID倒序排列” 前端源代码 $('#good_tables').datagrid({ nowrap: true, auto ...

  5. jQuery实现Ajax

    jQuery.ajax([settings]) type:类型,“POST”或“GET”,默认为GET url:发送地址 data:连同请求发送到服务器的数据 dataType:预期服务器返回的数据类 ...

  6. biological clock

    '''this application aimed to cauculate people's biological block about emotional(28), energy(23),int ...

  7. Web框架之Django_01初识(三大主流web框架、Django安装、Django项目创建方式及其相关配置、Django基础三件套:HttpResponse、render、redirect)

    摘要: Web框架概述 Django简介 Django项目创建 Django基础必备三件套(HttpResponse.render.redirect) 一.Web框架概述: Python三大主流Web ...

  8. Python9-day4 作业

    #!/usr/bin/env python# -*- coding:utf-8 -*-# Author:Timli = ["alex", "eric", &qu ...

  9. LeetCode(119) Pascal's Triangle II

    题目 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [ ...

  10. js实现一个简单的响应式双向数据绑定

    一,基本原理 我们这里使用了对象中的一个特殊属性:访问器属性,这个属性不能在对象中设置,而是必须通过defineProperty()方法单独定义. 我们首先定义一个函数: var obj = { }; ...