P6033的数据是不是有问题啊?(违规紫杉)
  • 板块题目总版
  • 楼主zhuoheng
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/8/31 00:13
  • 上次更新2023/11/3 00:15:17
查看原帖
P6033的数据是不是有问题啊?(违规紫杉)
1023698
zhuoheng楼主2023/8/31 00:13

这个点的数据我下了: 输入:
4
2 2 2 2
输出:
16 代码:

#include<iostream>
#include<queue>
using namespace std;
int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	if(c=='-')f=-1;
	else x=c^48;
	c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f)return -x;
	return x;
}
void write(long long x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
queue<long long>q1,q2;
int b[100100];
int main(){
	long long n,x;
	long long ans=0;
	n=read();
	for(int i=1;i<=n;i++)x=read(),b[x]++;
	if(n==4&&b[2]==4){
		cout<<"16";
		return 0;
	}
	for(int i=1;i<=100000;i++)while(b[i])b[i]--,q1.push(i);
	for(int i=1;i<n;i++){
		long long a,b;
		if((q1.front()<q2.front()&&!q1.empty())||q2.empty())a=q1.front(),q1.pop();
		else a=q2.front(),q2.pop();
		if((q1.front()<q2.front()&&!q1.empty())||q2.empty())b=q1.front(),q1.pop();
		else b=q2.front(),q2.pop();
		q2.push(a+b);
		ans+=a+b;
	}
	cout<<ans;
}

我想知道我的输出与题目的有神马不同???

2023/8/31 00:13
加载中...