CodeForce-762B USB vs. PS/2(贪心)
USB vs. PS/2
题意:有三种电脑,分别有a、b、c个,第一种只有USB接口,第二种只有PS/2接口,第三种有两种接口,有m个鼠标,告诉你价钱和接口类型,问最多有多少电脑和鼠标可以配对,这些鼠标最少花多少钱。
Input
2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2
3 14
解题思路:将两种鼠标分类后根据价钱来排序,先处理只有USB和只有PS/2接口的,然后两种鼠标取价钱少的来处理既有USB又有PS/2接口的
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits> using namespace std; #define LL long long
int a,b,c;
int m;
LL x1[300009],x2[300009]; int main()
{
while(~scanf("%d %d %d",&a,&b,&c))
{//读取数据过多,cin超时
int sum1=0,sum2=0;
memset(x1,0,sizeof x1);
memset(x2,0,sizeof x2);
LL q,ans=0;
string p;
scanf("%d",&m);
while(m--)
{
cin>>q>>p;
if(p=="USB") x1[sum1++]=q;
else x2[sum2++]=q;
}
sort(x1,x1+sum1);
sort(x2,x2+sum2);
int aa=min(a,sum1),bb=min(b,sum2),sum=aa+bb,k=0;
while(k<c)
{
if(aa<sum1&&bb<sum2&&x1[aa]<x2[bb]) aa++;
else if(aa<sum1&&bb<sum2) bb++;
else if(aa<sum1) aa++;
else if(bb<sum2) bb++;
else break;
sum++;
k++;
}
for(int i=0;i<aa;i++)
ans+=x1[i];
for(int i=0;i<bb;i++)
ans+=x2[i];
printf("%d %lld\n",sum,ans);
}
return 0;
}
CodeForce-762B USB vs. PS/2(贪心)的更多相关文章
- Codeforces 762B USB vs. PS/2 贪心
Codeforces 762B 题目大意: 有a台只有USB接口的电脑,b台PS/2接口的电脑,c台两种接口都有的电脑.每台电脑只用装一个鼠标.给出n个鼠标及其费用,每个鼠标只能使用一遍.在最大化有鼠 ...
- 【codeforces 762B】USB vs. PS/2
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforce 609A - USB Flash Drives
排序水题 #include<iostream> #include<cstdlib> #include<cstdio> #include<algorithm&g ...
- codeforce 985C Liebig's Barrels(贪心+思维)
Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforce 588A - Duff and Meat (贪心)
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day ...
- codeforce 227D Naughty Stone Piles (贪心+递归+递推)
Description There are n piles of stones of sizes a1, a2, -, an lying on the table in front of you. D ...
- 关于键盘冲突那点事(3键冲突/7键冲突/PS2/USB的各种原理)
转自关于键盘冲突那点事(3键冲突/7键冲突/PS2/USB的各种原理) 最近闲得无聊,正好看到有人发帖提问,于是就来详细说说所谓键位冲突和无冲突的各种原理--基本上这也是个老生常谈的话题了,但相关的技 ...
- USB HID Report Descriptor 报告描述符详解
Report descriptors are composed of pieces of information. Each piece of information is called an Ite ...
- Shell Script编程——USB挂载/复制文件/查找文件/压缩文件
PS:$引用变量的时候不要加空格.用了case,while的结构. main文件 #!/bin/bash chmod a+x changedate chmod a+x changemod chmod ...
随机推荐
- matlab快速入门
matlab快速入门 1矩阵 生成矩阵 % 直接法 a = [1,2,3;4,5,6;7,8,9]; % 冒号一维矩阵 a = 开始:步长:结束,步长为1可省略 b = 1:1:10; % 1,2 ...
- hg的常用配置
hg的配置文件分为全局配置和每个Repo自己的配置,Ubuntu系统下全局配置文件是~/.hgrc,Win7系统下是C:\Users\chad\mercurial.ini,各repo的配置文件是$RE ...
- 神经网络:numpy实现神经网络框架
欢迎访问个人博客网站获取更多文章: https://beityluo.space 本文用numpy从零搭建了一个类似于pytorch的深度学习框架 可以用于前面文章提到的MINST数据集的手写数字识别 ...
- ad 差分布线 等长布线
差分要素: 1.原理图差分对名字后缀必须是 _n _p 2.规则改动 定义差分线宽和间距
- SQL 练习10
查询没有学全所有课程的同学的信息 分析 先查询出所有课程的数量 select count(cid) from course 再查询出成绩表中课程数量=总课数的人员 select sid from sc ...
- SpringCloud War 包部署导致服务未正常注册到 Nacos 问题
转载地址:https://blog.csdn.net/qq_28379809/article/details/103773149
- ASP.NET Core:依赖注入
ASP.NET Core的底层设计支持和使用依赖注入.ASP.NET Core应用程序可以利用内置的框架服务将它们注入到启动类的方法中,并且应用程序服务能够配置注入.由ASP.NET Core提供的默 ...
- 【spring 注解驱动开发】spring组件注册
尚学堂spring 注解驱动开发学习笔记之 - 组件注册 组件注册 1.@Configuration&@Bean给容器中注册组件 2.@ComponentScan-自动扫描组件&指定扫 ...
- 使用SuperSocket实现自定义协议C/S设计
一.简介: 21世纪是出于互联网+的时代,许多传统行业和硬件挂钩的产业也逐步转向了系统集成智能化,简单来说就是需要软硬件的结合.这时,软硬件通讯便是这里面最主要的技术点,我们需要做到的是让硬件能够听懂 ...
- Mysql 修改本地密码
第一步 update user set authentication_string=password('root') where user='root' and host='localhost'; 第 ...