zoukankan      html  css  js  c++  java
  • hdu 4104 Discount

    http://acm.hdu.edu.cn/showproblem.php?pid=4104

    一开始还以为这题是背包,然后优化下这个背包,但是一直都优化不出来。

    然后题解是直接模拟而已,唉

    先从小到大排序后

    设【L, R】表示前i个数能组合成这个区间里面的任何一个数。

    那么,枚举一个数a[i + 1]进来的时候,他就能表示【a[i + 1], a[i + 1] + R】中的所有数字,

    关键是R和a[i + 1]是否能合并而已。

    判断一下就好,。注意这题p有可能是0

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    #include <bitset>
    const int maxn = 1e3 + 20;
    vector<int>a;
    int n;
    void work() {
        a.clear();
        a.push_back(0);
        for (int i = 1; i <= n; ++i) {
            int x;
            scanf("%d", &x);
            if (x == 0) continue;
            a.push_back(x);
        }
        sort(a.begin(), a.end());
        if (a.size() == 1 || a[1] != 1) {
            printf("1
    ");
            return;
        }
        int L = 1, R = a[1];
        for (int i = 2; i < a.size(); ++i) {
            int newL = a[i];
            int newR = a[i] + R;
            if (R + 1 >= newL) {
                R = newR;
            } else {
                cout << R + 1 << endl;
                return;
            }
        }
        cout << R + 1 << endl;
    }
    
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        while (scanf("%d", &n) != EOF) work();
        return 0;
    }
    View Code
  • 相关阅读:
    elasticsearch + fluentd + kibana 日志收集
    redis-dump数据导入导出
    zabbix 存储数据清理
    etcd集群部署
    yum安装zabbix4.2
    U盘启动安装CentOS 7出现 -dracut initqueue timeout
    About && 友链
    红队-C2 Server基础构建
    从0学习WebLogic CVE-2020-2551漏洞
    代码审计-phpok框架5.3注入漏洞
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6270808.html
Copyright © 2011-2022 走看看