USB vs. PS/2

CodeForces - 762B

题意:有三种电脑,分别有a、b、c个,第一种只有USB接口,第二种只有PS/2接口,第三种有两种接口,有m个鼠标,告诉你价钱和接口类型,问最多有多少电脑和鼠标可以配对,这些鼠标最少花多少钱。

Input

2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2
Output
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(贪心)的更多相关文章

  1. Codeforces 762B USB vs. PS/2 贪心

    Codeforces 762B 题目大意: 有a台只有USB接口的电脑,b台PS/2接口的电脑,c台两种接口都有的电脑.每台电脑只用装一个鼠标.给出n个鼠标及其费用,每个鼠标只能使用一遍.在最大化有鼠 ...

  2. 【codeforces 762B】USB vs. PS/2

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. codeforce 609A - USB Flash Drives

    排序水题 #include<iostream> #include<cstdlib> #include<cstdio> #include<algorithm&g ...

  4. codeforce 985C Liebig's Barrels(贪心+思维)

    Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. 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 ...

  6. 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 ...

  7. 关于键盘冲突那点事(3键冲突/7键冲突/PS2/USB的各种原理)

    转自关于键盘冲突那点事(3键冲突/7键冲突/PS2/USB的各种原理) 最近闲得无聊,正好看到有人发帖提问,于是就来详细说说所谓键位冲突和无冲突的各种原理--基本上这也是个老生常谈的话题了,但相关的技 ...

  8. USB HID Report Descriptor 报告描述符详解

    Report descriptors are composed of pieces of information. Each piece of information is called an Ite ...

  9. Shell Script编程——USB挂载/复制文件/查找文件/压缩文件

    PS:$引用变量的时候不要加空格.用了case,while的结构. main文件 #!/bin/bash chmod a+x changedate chmod a+x changemod chmod ...

随机推荐

  1. 复杂字符串转List<JSONObject>

    public static List<JSONObject> getlist(String data){ ObjectMapper mapper = new ObjectMapper(); ...

  2. Mysql 主从同步原理简析

    在开始讲述原理的情况下,我们先来做个知识汇总,究竟什么是主从,为什么要搞主从,可以怎么实现主从,mysql主从同步的原理1.什么是主从其实主从这个概念非常简单主机就是我们平常主要用来读写的服务,我们称 ...

  3. ASP.NET Core端点路由中三种让人困惑的路由函数

    早先提及了端点路由app.UseEndpoints, 端点路由强调的是端点和 路由,其核心目的是将 请求落地点与路由寻址方式解耦. 这里面有几个容易混淆的函数 MapControllerRoute M ...

  4. SpringCloud升级之路2020.0.x版-22.Spring Cloud LoadBalancer核心源码

    本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford 经过上一节的详细分 ...

  5. flutter学习资料汇总

    1.https://github.com/chinabrant/flutter_study 2.https://github.com/zhujian1989/flutter_study 3.https ...

  6. C++基于ATL工程编写ActiveX控件步骤

    参考网址: https://blog.csdn.net/whui19890911/article/details/8896554 开发环境:VS2010 开发工程:C++ATL项目 开发目的:创建Ac ...

  7. ASP.NET Core教程:ASP.NET Core程序部署到Linux

    一.前言 这篇文章我们将讲解如何将ASP.NET Core 程序部署到Linux.这里我们使用的是虚拟机里面安装的Centos7.这里的ASP.NET Core程序,以上篇文章中发布的框架依赖文件为例 ...

  8. 【springboot】@Valid参数校验

    转自: https://blog.csdn.net/cp026la/article/details/86495659 扯淡: 刚开始写代码的时候对参数的校验要么不做.要么写很多类似 if( xx == ...

  9. PipedInputStream and PipedOutputStream example

    必须要有PipedInputStream ,PipedOutputStream 在不同线程,不然死锁 Java.io.PipedOutputStream and java.io.PipedInputS ...

  10. LVS本地实验环境搭建

    文中实验需要使用以下软件: CentOS的镜像 Virtual Box GNS3 0.实验前的准备工作 0.1.修改yum源 为了方便安装软件,我们设置yum源为公司yum源 1.直接复制公司机器上的 ...