栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3090 Assemble

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3090 Assemble

#include<cstdio>#include<string>#include<map>#include<cstring>#include<iostream>#include<algorithm>#define MAXN 1005#define INF 0x3f3f3f3fusing namespace std;map< string,int > id;int T,n,b,cnt;char tmp[30];struct Obj {int price,quality,type;}obj[MAXN];bool cmp(Obj a,Obj b) {return a.quality<b.quality;}int insert(string s){if(!id[s]) id[s]=cnt++;return id[s];}bool check(int x){int sum=0,kind=0,cheapest[MAXN];memset(cheapest,INF,sizeof(cheapest));for(int i=1;i<=n;++i){if(obj[i].quality<x) continue;if(cheapest[obj[i].type]==INF) ++kind,sum+=obj[i].price,cheapest[obj[i].type]=obj[i].price;else if(obj[i].price<cheapest[obj[i].type]) sum=sum-cheapest[obj[i].type]+obj[i].price,cheapest[obj[i].type]=obj[i].price;}return sum<=b && kind==cnt-1;}int main(){scanf("%d",&T);while(T--){scanf("%d%d",&n,&b);cnt=1; id.clear();int maxquality=0;for(int i=1;i<=n;++i){scanf("%s",tmp);obj[i].type=insert(tmp);scanf("%s",tmp);scanf("%d %d",&obj[i].price,&obj[i].quality);maxquality=max(maxquality,obj[i].quality);}int low=0,high=maxquality;while(low<high){int mid=low+(high-low+1)/2;if(check(mid)) low=mid;else high=mid-1;}printf("%dn",low);}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368524.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号