求助!multiset+贪心没过!WA#8
查看原帖
求助!multiset+贪心没过!WA#8
922691
Hisy楼主2024/1/27 14:58
#include<cstdio>
#include<set>
using namespace std;
int main(int argc,char **argv){
	int mul=0,ans=0;
	multiset<int> heap;
	for(int iter=1;iter<=4;++iter){
		int got;
		scanf("%d",&got);
		heap.insert(got);
	};
	for(int iter=1;iter<=3;++iter){
		getchar();
		char got=getchar();
		if(got=='*'){
			++mul;
		};
	};
	while(mul--){
		int top1=*heap.begin();
		int top2;
		heap.erase(heap.begin());
		if(top1<=1){
			multiset<int>::iterator pos=heap.end();
			--pos;
			top2=*pos;
			heap.erase(pos);
		}else{
			top2=*heap.begin();
			heap.erase(heap.begin());
		};
		heap.insert(top1*top2);
	};
	while(!heap.empty()){
		ans+=*heap.begin();
		heap.erase(heap.begin());
	};
	printf("%d",ans);
	return 0;
};
2024/1/27 14:58
加载中...