CCF-2014-12-3集合竞价

思路一;50分 不知道问题出在哪 改天心情好换个思路写一写

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=5050;
struct node{
	float p;
	int s,f,q=0,x=0;
};
vector<node> Z;
vector<node> B;
vector<node> S;
bool cmp1(node a,node b){
	if(a.p!=b.p)
	   return a.p>b.p;
}
int main(void)
{
	int n=0;
	string a;
	while(cin>>a){
		n++;
		node u;
		if(a[0]=='c'){
			int x;
			scanf("%d",&x);
			u.q=x-1;
			u.f=-1;
			u.p=0;
			u.s=0;
		}
		else if(a[0]=='b'){
			float jg;
			int sl;
			scanf("%f %d",&jg,&sl);
			u.p=jg;
			u.s=sl;
			u.f=1;
		}
		else if(a[0]=='s'){
			float jg;
			int sl;
			scanf("%f %d",&jg,&sl);
			u.p=jg;
			u.s=sl;
			u.f=2;			
		}
		Z.push_back(u);
	}
	for(int i=n-1;i>=0;i--){
		node u=Z[i];
		if(u.x!=0)
		   continue;
		else{
			if(u.f==-1){
				Z[u.q].x=1;
			}
			else if(u.f==1){
				B.push_back(u);
			}
			else if(u.f==2){
				S.push_back(u);
			}
		}
	}
	sort(B.begin(),B.end(),cmp1);
	sort(S.begin(),S.end(),cmp1);
	long long sum=0,ts[5050]={0},qs[5050]={0};
	float zp;
	for(int i=S.size()-1;i>=0;i--){
		ts[i]+=ts[i+1]+S[i].s;
	}
	for(int i=0;i<S.size();i++){
		long long ms=0;
		float mp=S[i].p,tp;
		for(int j=0;j<B.size();j++){
			if(mp>B[j].p){
				break;
			}
			else{
				ms+=B[j].s;
				tp=B[j].p;
				if(ms>=ts[i]){
					break;
				}
			}
		}
		ms=min(ms,ts[i]);
		if(ms>sum){
			sum=ms;
			zp=tp;
		}
	}
	if(sum==0)
	    zp=S[0].p;
	printf("%.2f %lld\n",zp,sum);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值