cf762b

来源:互联网 发布:淘宝企业店 避税提现 编辑:程序博客网 时间:2024/05/04 12:43

题意需要买三种鼠标a,b,c个,一个是usb接口,一个是ps/2接口,还有一个是两种接口。然后给你一些鼠标,还有价格,问你能买到多少鼠标,还有需要多少钱。
心路历程我一开始是想一个一个归一下类,然后再来sort一下排序,求解,但是如果这样的话就还有一个问题,就是那么两种接口都行的怎么整。
后来就是把所有的归到一个数组里,模拟优先队列,用指针扫一下出解。

#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int N = 3e5 + 10;typedef long long LL;struct nod{    int num ;    char type;}node[N];bool cmp(nod a , nod b){    return a.num < b.num;}int main(){    int a , b , c , n , tot = 0;    scanf("%d %d %d %d",&a ,&b ,&c ,&n);    for(int i = 0 ; i < n ; i++){        int p ;        char str[20];        scanf("%d %s",&p , str);        node[++tot].num = p;        node[tot].type = str[0];    }    LL Num  = 0 , Sum = 0;    sort(node + 1 , node + tot + 1 , cmp);    for(int i = 1 ; i <= n ;i++){        if(node[i].type == 'U' && a > 0){            Num++;            Sum += node[i].num;            a--;            //printf("1%d\n",node[i].num);        }        else if(node[i].type == 'P' && b > 0){            Num++;            Sum += node[i].num;            b--;           // printf("2%d\n",node[i].num);        }        else if(c > 0){            Num++;            Sum += node[i].num;            c--;            //printf("3%d\n",node[i].num);        }    }    printf("%I64d %I64d\n",Num , Sum);}

吃多了,但愿能瘦下来。老子怎么有一种被偷窥的感觉

0 0
原创粉丝点击