B. USB vs. PS/2(结构体排序)
来源:互联网 发布:淘宝助理无法打印 编辑:程序博客网 时间:2024/06/05 06:20
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!
The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.
You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.
You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.
The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.
The next line contains one integer m (0 ≤ m ≤ 3·105) — the number of mouses in the price list.
The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≤ vali ≤ 109) — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.
Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.
2 1 145 USB6 PS/23 PS/27 PS/2
3 14
In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
题意:用最少的钱买配套的鼠标,最多买几个,最少花多少钱。
思路:结构体排序,价格从小到大,依次进行加法运算。
代码:
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<cmath>#include<algorithm>using namespace std;typedef long long LL;struct pp{ int v; char t[10];}s[300000+10];bool cmp(pp a,pp b){ return a.v<b.v;}int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int m; scanf("%d",&m); memset(s,0,sizeof(s)); for(int i=0;i<m;i++) scanf("%d %s",&s[i].v,s[i].t); sort(s,s+m,cmp); int cout1=0,cout2=0,cout3=0; LL w1=0,w2=0,w3=0; for(int i=0;i<m;i++) { if(s[i].t[0]=='U'&&cout1!=a) { cout1++; w1+=s[i].v; } else if(s[i].t[0]=='P'&&cout2!=b) { cout2++; w2+=s[i].v; } else if(cout3!=c) { cout3++; w3+=s[i].v; } } printf("%d %I64d\n",cout1+cout2+cout3,w1+w2+w3);}
- B. USB vs. PS/2(结构体排序)
- B - USB vs. PS/2 CodeForces - 762B (贪心)
- codeforce-762-B USB vs. PS/2(贪心)
- 【codeforces 762B】USB vs. PS/2
- B. USB vs. PS/2 - 简单实现
- Codeforces 762B-USB vs. PS/2
- CodeForces 762B USB vs. PS/2
- Codeforces 597B: Restaurant(贪心+结构体排序)
- Codeforces #274 (Div. 2) B. Towers(模拟:结构体排序)
- CodeForces 151 B 结构体排序。
- CodeForces 151 B 结构体排序。
- PS/2鼠标自己动手改USB接口
- usb结构体
- USB相关结构体
- CodeForces 659 B. Qualifying Contest(结构体排序的问题)
- 输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)
- 输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)
- 输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)
- Mac系统上Android studio真机调试
- Android完全解决6.0以上机型不能拍照选择相册问题
- DELETE_FAILED_INTERNAL_ERROR Error while Installing APK
- glibc
- CString转char*/wchar_t* 转 char*
- B. USB vs. PS/2(结构体排序)
- 四种电子商务支付模式:支付网关模式、网上银行模式、第三方支付模式和手机支付模式。
- Javascript 元素宽高,偏移以及滚动位置
- fastjson生成json时Null转为空字符串""或者不展示
- mysql alter 操作
- android源码设计模式解析与实战 笔记 5.7节
- hdu 3333 Turing Tree 线段树 离线查询(区间内不同的数之和)
- sublimetext3-实用快捷键整理
- Maven分模块项目将依赖一起打包