Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁帮我测试一下,搞不懂哪里有问题

Posted by 123zzzz at 2022-12-11 17:01:03 on Problem 1913
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int n1,n2,n3;
string a,f;
map<string,int> M;
map<string,vector<int> >m2;
map<string,int>::iterator it;
struct element{
	map<string,int> m1;
}x[10005];
struct Rank{
	string name;
	int mix,flag,pos;
	int cost;
}y[10005];
void assign(int num,int p){
	string name;
	int sum;
	while(num--){
		cin>>name>>sum;
		x[p].m1[name]=sum;
	}
}
void init_1(){
	string name;
	int num;
	for(int i=1;i<=n1;i++){
		cin>>name>>num;
		M[name]=i;
		assign(num,i);
		y[i].name=name;
		y[i].mix=0;
		y[i].pos=i;
		y[i].cost=0;
	}
}
void init_2(){
	string name;
	int num,price;
	for(int i=1;i<=n2;i++){
		cin>>name>>num>>price;
		m2[name].push_back(num);
		m2[name].push_back(price);
	}
}
void Cost(){
	int flag;
	for(int i=1;i<=n1;i++){
		flag=0;
		for(it=x[i].m1.begin();it!=x[i].m1.end();it++){
			if(m2.find(it->first)==m2.end()){
				flag=1;
				break;
			} 
			y[i].cost+=(it->second*m2[it->first][1]);
		}
		if(!flag)
			y[i].cost=y[i].cost*3+10000;
		else y[i].cost=0;
	}
}
bool cal(){
	for(it=x[M[a]].m1.begin();it!=x[M[a]].m1.end();it++){
		string name=it->first;
		int num=it->second;
		if(m2.find(name)==m2.end()||m2[name][0]<num) return false;
	}
	for(it=x[M[a]].m1.begin();it!=x[M[a]].m1.end();it++){
		string name=it->first;
		int num=it->second;
		if(num>m2[name][0]) return false;
		m2[name][0]-=num;
	}
	y[M[a]].mix++;
	return true;
}
bool judge(){
	if(a==f){
		if(M[a]==n1){
			a=y[1].name;	
		} 
		else{
			a=y[M[a]+1].name;	
		} 
	}
	if(cal()) return true;
	for(int j=1;j<=n1;j++){
		a=y[j].name;
		if(a!=f){
			if(cal()) return true;	
		}	
	}
	return false;
}
bool cmp(Rank t1,Rank t2){
	if(t1.mix==t2.mix) return t1.pos<t2.pos;
	return t1.mix>t2.mix;
}
void Print(){
	for(int i=1,j=1;i<=n1;i++){
		if(y[i].mix&&j!=11){
			cout<<j<<" "<<y[i].name<<" "<<y[i].mix<<" "<<y[i].cost<<endl;
			j++;
		}
		x[i].m1.clear();
	}
}
int main(){ 
	int Case;
	cin>>Case;
	for(int i=1;i<=Case;i++){
		cin>>n1;
		init_1();
		cin>>n2;
		init_2();
		Cost();
		cin>>n3;
		f="";
		for(int i=1;i<=n3;i++){
			cin>>a;
			if(M.find(a)==M.end()) continue;
			if(judge()) f=a;
		}
		sort(y+1,y+1+n1,cmp);
		cout<<"Scenario "<<i<<" top cocktails:"<<endl;
		Print();
		M.clear();
		m2.clear();
	}
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator