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. 『Java』StringBuilder类使用方法

    String类存在的问题 String类的底层是一个被final修饰的byte[],不能改变. 为了解决以上问题,可以使用java.lang.StringBuilder类. StringBuilder ...

  2. 跟我一起写 Makefile(九)

    使用函数 ---- 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函数的返回值可以当做 ...

  3. How to name a slf4j logger

    Use logger in a non-static context: Logger logger = LoggerFactory.getLogger(this.getClass().getName( ...

  4. Java调用Zookeeper

    watch机制 Zookeeper watch是一种监听通知机制,可以随时监听一些数据的变化,从而实现数据的及时性. Zookeeper所有的读操作getData(), getChildren()和 ...

  5. Sqli-Labs less29-31

    Less-29 可以从介绍上看出,第29关被称为世界上最好的WAF,网上许多讲解的办法就是和第一关差不多,其实是不对的. sqli-labs文件夹下面还有tomcat文件,这才是真正的less,里面的 ...

  6. 接口和包--Java学习笔记

    接口 定义及基础用法 interface定义:没有字段的抽象类 interface person{ void hello(); String getName(); } /*接口本质上就是抽象类 abs ...

  7. Quartz任务调度(6)schedulerListener分版本超详细解析

    schedulerListener 在我们的监听器实现类中,这个类中需实现的方法很多,不需要的可以给出空实现,下面是一些常用的用法: 方法 说明 jobScheduled() Scheduler 在有 ...

  8. Spring之AspectJ

    时间:2017-2-4 21:12 --AspectJ简介1.AspectJ是一个基于Java语言的AOP框架.2.Spring2.0以后新增了对AspectJ切点表达式的支持.3.@AspectJ是 ...

  9. 源码解析.Net中DependencyInjection的实现

    前言 笔者的这篇文章和上篇文章思路一样,不注重依赖注入的使用方法,更加注重源码的实现,我尽量的表达清楚内容,让读者能够真正的学到东西.如果有不太清楚依赖注入是什么或怎么在.Net项目中使用的话,请点击 ...

  10. 高德渲染网关Go语言重构实践

    ​1.导读 高德启动Go业务建设已经有段时间了,主要包含Go应用落地,Go中间件建设,云原生三个部分.经过持续的发力,在这些方面取得了不错的进展.高德Go业务落地过程是如何实现的,遇到过哪些问题,如何 ...