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 ...
随机推荐
- A Python Environment Detector
The user provide the method to get result(command on remote host), the check standard(a callback fun ...
- Groovy正则表达式复杂逻辑判断实例
下面的两个pattern(p1和p2)分别代表了(A or B) and (C or D)和(A and B) or (C and D)的跨行匹配结果,当然还可以用正则表达式构建更复杂的pattern ...
- Manage Historical Snapshots in Sonarqube
Login as admin, go to a dashboard of a project, then click "Configuration -> History" a ...
- 手工设置Eclipse文本编辑器的配色
Eclipse中不同的文件都有自己专门的编辑器配色设置,下面分别说明. 文本编辑器的背景色: Window->Preferences-> General->Editors->T ...
- 用Python爬取《王者荣耀》英雄皮肤数据并可视化分析,用图说话
大家好,我是辰哥~ 今天辰哥带大家分析一波当前热门手游<王者荣耀>英雄皮肤,比如皮肤上线时间.皮肤类型(勇者:史诗:传说等).价格. 1.获取数据 数据来源于<王者荣耀官方网站> ...
- SpringBoot开发五-社区首页开发
需求介绍-社区首页 根据之前的学习,我们一般都是先按照DAO->Service->Controller这个顺序去开发 分布实现: 开发社区首页,显示前十个帖子. 开发分页组件,分页显示所有 ...
- 【Vulnhub】DC-1靶机
一.信息收集 1.1 环境 kali : 192.168.124.141 DC-1 : 192.168.124.150 1.2 nmap进行扫描 :nmap -sV 192.168.124.150 I ...
- msp432搭建平衡小车(二)
前言 上一节掌握了使用pwm驱动电机,接下来介绍如何使用msp432读取mpu6050数据 正文 首先我们得知道mpu6050通信方式,由于mpu6050只能用i2c通信,所以学会使用msp432的i ...
- mysql 优化面试题
第一方面:30种mysql优化sql语句查询的方法 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by涉及的列上建立索引. 2.应尽量避免在 where 子句中使用 ...
- Leaflet 中 删除 一个 标记(Marker)
参考:https://blog.csdn.net/qq_34922009/article/details/81184004 下面是我在Leaflet官方文档所找到的答案 ,希望可以帮助到大家 比如以下 ...