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. Windows根据端口号查找对应的进程和服务

    需求 1,我们在Win10安装一些Web服务时,会发现默认端口被占用,比如443端口被占用,808端口被占用,那么如何找出占用这些默认端口的进程和对应的服务呢? 2,系统安装完成后,会有一些应用对外开 ...

  2. Linux线程属性总结(一)

    线程属性标识符:pthread_attr_t 包含在 pthread.h 头文件中. [c] view plaincopy //线程属性结构如下: typedef struct { int       ...

  3. DrJava试用笔记

    安装方便:只要配好JAVA_HOME,用java -jar drjava-stable-20120818-r5686.jar即可启动,算是绿色软件: 特色功能:交互式命令行,可以在调试程序时改变变量值 ...

  4. Golang语言系列-07-函数

    函数 函数的基本概念 package main import ( "fmt" ) // 函数 // 函数存在的意义:函数能够让代码结构更加清晰,更简洁,能够让代码复用 // 函数是 ...

  5. stm32 串口接收一次后再也无法接受,接受都为0

    经检测为串口接受后进入别的程序,开辟了2048的临时数组,因为堆栈溢出.stm32总共堆栈为

  6. contos7 安装weblogic10.3 _wls1036_generic.jar

    环境:CentOS7+jdk1.8 weblogic下载地址1: http://www.oracle.com/technetwork/cn/middleware/weblogic/downloads/ ...

  7. Centos7上安装rabbitmq和使用

    github rpm地址: https://github.com/rabbitmq/erlang-rpm 要安装rabbitmq先安装它的语言 创建erlang repo /etc/yum.repos ...

  8. 【GIS】点图层符号的方向和大小

    方向:根据属性字段设置点图层中每个要素的符号方向和大小, 1 所有要素使用同一种符号---简单渲染 在图层属性---符号系统---单一符号中进行设置,首先设置符号,在后面的[高级]选项按钮中分别设置[ ...

  9. 事务种类jdbc,Hibernate,JTA事务

    JDBC事务 String URL="jdbc:sqlserver://localhost:1433;databaseName=test2"; String USER=" ...

  10. ElasticSearch之配置文件详解

    ################################### Cluster ################################### #定义集群名称,默认是elasticse ...