佬!菜!带!
查看原帖
佬!菜!带!
672733
xhx2009楼主2023/7/21 13:34

代码如下,已经把思路注释出来了

#include<bits/stdc++.h>
using namespace std;
int a[20001];//桶 

int main(){
	int n,poer=0;//poer≈power体力 
	cin>>n;
	if(n==1){//特判1 
		int j;
		cin>>j;
		cout<<j;
		return 0;
	}
	if(n==2){//特判2 
		int j1,j2;
		cin>>j1>>j2;
		cout<<j1+j2;
		return 0;
	}
	for(int i=1;i<=n;i++){
		int g;
		cin>>g;
		a[g]++;//进桶 
	}
	int o=0,k=0,x,y;
	for(int i=1;i<n;i++){//合并n-1次 
		o=0;
		while(o<=2){
			if(a[++k]!=0){//找小的果子堆 
				o++;
				if(o==1){//目前最小的果子堆 
					x=k;
				}
				else if(o==2){//第二小的果子堆 
					y=k;
				}
				else{
					poer=poer+x+y;//合并两个小的果子堆 
					a[x+y]++;// 把新堆塞进桶 
					a[x]--;//删旧堆 
					a[y]--;//删旧堆 
					k=x;//节省时间 
					o=114514;//强制退出 
				}
			}
		}	
	}
	cout<<poer;
	return 0;
}

在 C++里测试时正常输出

但一提交评测就全CE

求助大佬

2023/7/21 13:34
加载中...