UVA 12124 Assemble(贪心 二分)

结合qtdesigner,用pyqtgraph在界面上绘制波形图(一) 思路:先画图,然后在qtdesigner上放一个容器,给这个容器添加一个布局,然后把图当作一个Widget放入布局中。二、PyUIC把test.ui转换成test.py,再新建一个load_test.py写脚本。就这么简单,基础部分就完成了。也可以给它添加样式,我知道的样式不算多,但会继续写。一、随便拖进来一个容器控件,我拖了一个Widget。要想把波形图显示在界面上,核心思想其实很简单。三、load_test.py的代码。 阅读详情
题目大意:

你有b块钱,想要组装一台电脑。给出n个配件各自的种类、品质因子和价格,要求每种类型的配件各买一个,总价格不超过b,且“品质最差配件”的品质因子应尽量大。
【输入格式】
输入的第一行为测试数据组数T(T≤100)。每组数据的第一行为两个正整数n(1≤
n≤1 000)和b(1≤b≤109),即配件的数目和预算;以下n行每行描述一个配件,依次为种类、名称、价格和品质因子。其中,价格为不超过106的非负整数;品质因子是不超过109的非负整数(越大越好);种类和名称则由不超过20个字母、数字和下划线组成。输入保证总是有解。
【输出格式】
对于每组数据,输出配件最小品质因子的最大值。

分析:

在《入门经典》一书中,我们曾提到过,解决“最小值最大”的常用方法是二分答案。假设答案为x,如何判断这个x是最小还是最大呢?删除品质因子小于x的所有配件,如果可以组装出一台不超过b元的电脑,那么标准答案ans≥x,否则ans<x。
如何判断是否可以组装出满足预算约束的电脑呢?很简单,每一类配件选择最便宜的一个即可。如果这样选都还超预算的话,就不可能有解了。

import java.util.*;

public class Main {
    static int cnt ,n, b;
    static HashMap<String,Integer> id = new HashMap<String,Integer>();
    static ArrayList<ArrayList<Component>> comps = null;
    static Integer ID(String s) {
        int res=0;
        if(id.containsKey(s)) {
            res=id.get(s);
        }else {
            id.put(s, cnt);
            res = cnt;
            cnt++;
        }
        return res;
    }
    static void init() {
        cnt = 0;
        id.clear(); //初始化id
        comps = new ArrayList<ArrayList<Component>>();
        for(int i=0;i <= n;i++) {
            ArrayList<Component> tmp =new ArrayList<Component>();
            comps.add(tmp);
        }
    }
    static boolean judge(int q) {
        int sum = 0;
        for(int i = 0; i < cnt; i++) {
            int cheapest = b + 1;
            for(int j = 0; j < comps.get(i).size(); j++) {
                if(comps.get(i).get(j).quality >= q)
                    cheapest = Math.min(cheapest, comps.get(i).get(j).price);
            }
            if(cheapest == b + 1) {
                return false;
            }
            sum += cheapest;
            if(sum > b) {
                return false;
            }
        }
        return true;
    }
    public static void main(String []args) {
        Scanner cin = new Scanner(System.in);
        int T;
        T = cin.nextInt();
        while(T-- > 0) {
            n = cin.nextInt();
            b = cin.nextInt();

            init();
            int maxq = Integer.MIN_VALUE , minq = Integer.MAX_VALUE;
            String type, name;
            int p , q;
            for(int i = 0; i < n; i++) {
                type = cin.next();
                name = cin.next();
                p = cin.nextInt();
                q = cin.nextInt();
                maxq = Math.max(maxq,q);
                minq = Math.min(minq,q);
                int num = ID(type);
                comps.get(num).add(new Component(p,q));
            }
            int left = minq , right = maxq;
            while(left < right) {
                int mid = left + (right - left + 1) / 2;
                if(judge(mid)) {
                    left = mid;
                }else {
                    right = mid - 1;
                }
            }
            System.out.printf("%d\n", left);
        }
    }
}

class Component {
    int price;
    int quality;
    Component(int p,int q) {
        this.price = p;
        this.quality = q;
    }
}
手把手教你学 GPU SoC 芯片(9.3)--GPU SOC 功耗和热管理的动态电压和频率调整(DVFS) 通过动态电压和频率调整(DVFS),可以有效地管理GPU SoC的功耗和热管理。合理的DVFS策略不仅可以节省功耗,提高能效,还可以延长设备的使用寿命。 阅读详情

相关推荐

Type-C连接中的CC引脚:Rp与Rd电阻的识别与供电模式选择

本文深入解析Type-C接口中CC引脚的核心功能,包括Rp与Rd电阻的识别原理及供电模式选择机制。通过详细的分压计算和实战案例,揭示Type-C设备如何通过CC引脚实现方向检测、角色识别和供电协商,为硬件设计提供关键指导。

weixin_30616969的博客 342

hdu5313 求构成完全二分图需要的最多的边数 染色+背包求最小差异

首先通过0,1染色找到联通分支,保存左右两边的差值,然后使左右两边的节点数目尽可能相差尽可能的小,用背包 (容量为sum/2) 求最小差异 ,这时边数最多,967MS险过 #include #include #include #include #include #include #include #include using namespace std; const int N=1e4+10;

zjck1995的专栏 824

新手也能玩转!用Panosim+MATLAB/Simulink搭建你的第一个智能驾驶仿真场景(保姆级图文)

本文为新手提供了使用Panosim和MATLAB/Simulink搭建智能驾驶仿真场景的详细教程。从环境准备、基础场景创建到仿真模型构建,一步步指导用户完成第一个智能驾驶仿真项目,帮助零基础用户快速上手并体验智能驾驶仿真的乐趣。

weixin_29090089的博客 183

UVA 12124 UVAlive 3971 Assemble(二分 + 贪心)

Problem A - Assemble Time limit: 2 seconds Recently your team noticed that the computer you use to practice for programming contests is not good enough anymore. Therefore, you decide to buy a new

Remilia's 1619

python等级考试——一级知识点汇总(不包含turtle画图)

本篇文章是针对中国电子学会青少年编程等级考试的,适合初学者以及青少年编程学习者

weixin_65350557的博客 9032

HUMAnN 3.0 (alpha)安装及使用

文章目录简介安装数据库下载运行参考 简介 安装 conda install humann humann_test (~1 minute) 数据库下载 humann_databases --download chocophlan full /path/to/databases --update-config yes humann_databases --download uniref uniref90_diamond /path/to/databases --update-config yes humann_

dys的博客 9505

POJ3497 UVA12124 Assemble(二分 + 贪心)

Assemble Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3361   Accepted: 1070 Description Recently your team noticed that the computer you use to practice

蒻菜_羊羊羊的专栏 582

QT+OSG/osgEarth编译之七十六:gltf+Qt编译(一套代码、一套框架,跨平台编译,版本:osgEarth-3.3插件库osgdb_gltf)

通过一套gltf代码和框架,实现osgdb_gltf跨平台编译。 在Qt环境下,集成头文件、库文件,构建跨平台编译的pro文件。 通过构建的一套配置工程,基于Qt Creator IDE,完成跨平台的编译实践。 在Windows、Linux、MacOS等操作系统上进行测试,成功编译,形成的成果(头文件、库文件等)可在不同系统下调用或使用,从而更好地构建跨平台解决方案。 采用的是osgEarth3.3版本。 读者可参考博客中的集成原理,构建不同版本的osgdb_gltf跨平台包。

LuckyHanMo的博客 1802

Uva 12124 Assemble

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3276 题目大意:有b块的预算,要组装一台电脑,给出n个配件,每个配件标明种类,名称,品质和价格,要求每种配件各买一个,从价格不超过b,且品质最低的配件的品质尽可能大。输出最小品质配件的品质。

独行闹市无人问,青灯剑影响素琴 817

DeepSmote:一种深度SMOTE方法

DeepSmote 一种全新的将深度学习与Smote相结合的过采样方法! 目前在许多领域已经被使用,值得大家关注学习!

走在深度学习前沿的小宋 1447

【Claude Code 源码解析教程】总体大纲

本教程旨在深入解析 Anthropic Claude Code 项目的源码架构和实现细节。Claude Code 是一个基于 TypeScript + Bun 构建的 AI 编程助手 CLI 工具,代号 "Tengu",具有复杂的多模块架构和丰富的功能特性。本教程基于Claude Code 的源码分析来生成,将帮助您全面掌握 Claude Code 的源码架构和实现细节,为开发类似 AI 编程助手工具奠定坚实基础。

rengang66的博客 387

uva 12124 Assemble 模拟+二分

题意:有一个人有b元,要去买零件,有n个零件,零件有不同的种类,名称,价格,质量,要求每种零件买一个,不超过b元钱,让最差质量尽量好,问最差质量是多少。

关于完全听不懂神犇在说什么的事 407

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

uva12124-Assemble

题意: 有b块钱,n个配件及其种类,质量,价格,让你每种类型的配件各买一个,总价不超过b元,让品质最差的配件质量最好,求最小品质的质量最大值 思路: 二分最小质量的最大值,再用贪心的思想判断该质量是否可行,即排序每种配件的价格,判断时按价格从低到高扫描,选择到符合该质量的即可。 代码: #include #include #include using names

不要皱眉 401

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

UVA - 12124 Assemble

题意:你有b块钱,给出n个配件各自的种类,品质因子和价格,要求每种类型的都要买一个,总价格不超过b,且品质最差配件的品质因子要尽量大 思路:二分,设答案是x,删除品质因子小于x的所有配件,如果可以组装出不超过b的电脑,那么答案>=x,否则答案 #include #include #include #include #include #include using namespace

那些年 883

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

UVA之12124 - Assemble

【题目】 Problem A - Assemble Time limit: 2 seconds Recently your team noticed that the computer you use to practice for programming contests is not good enough anymore. Therefore, you decide to bu...

SmartSi 515

UVA - 10057 A mid-summer night's dream.

Problem C A mid-summer night�s dream Input: standard input Output: standard output   This is year 2200AD. Science has progressed a lot in two hundred years. Two hundred years is mentioned here

小G的ACM之路 1315

UVA - 714 Copying Books(二分+贪心)

Copying Books  Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been

小G的ACM之路 1196

UVA - 10905 Children's Game(贪心)

4thIIUCInter-University Programming Contest, 2005 A Children�s Game Input: standard input Output: standard output Problemsetter: Md. Kamruzzaman There

小G的ACM之路 1143

UVA - 311 Packets(贪心)

Packets  A factory produces products packed in square packets of the same height h and of the sizes  ,  ,  ,  ,  ,  . These products are always delivered to customers in the square parc

小G的ACM之路 1127

UVA - 10954 Add All(贪心+优先队列)

Problem F Add All Input: standard input Output: standard output Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++

小G的ACM之路 1076

UVA - 10706 Number Sequence(贪心)

Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A single positive integer iis given. Write a program to find the digit located in the position iin

小G的ACM之路 1060

UVA - 10400 Game Show Math(回溯)

题目大意:给定n个数字,问能否

小G的ACM之路 1032

UVA - 270 Lining Up(贪心)

Lining Up  ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was not facing an easy task. She had to drop packages at specific points scattered in a d

小G的ACM之路 1014

UVA - 10132 File Fragmentation(贪心)

Question 2: File Fragmentation The Problem Your friend, a biochemistry major, tripped while carrying a tray of computer files through the lab. All of the files fell to the ground and broke. Your f

小G的ACM之路 1007
上一篇: UVA 10795 A Different Task(递归 状态转移)
下一篇: hdu 5167 Fibonacci(dfs)
HelloWorld10086
博客等级 码龄12年 88粉丝 614原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值