40分求助大佬
查看原帖
40分求助大佬
537002
zys180楼主2022/8/7 12:12
#include<iostream>
#include<iomanip>/*保留小数*/
#include<cstring>/*字符串*/
#include<cmath>/*数学语言*/
#include<algorithm>/*算法排序*/
#include<stack>/*栈*/
#include<queue>/*队列*/
#include<deque>/*双端队列*/
#include<cstdio>/*输入输出流*/
#include<fstream> /*文件流*/
using namespace std;
int n,a[205],b[205],sum=0,su;
int main() {
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> a[i];
		b[i]=a[i];
	}
	int t=n;
	for(int i=0; i<n-1; i++) {
		int h=0;
		int o=0;
		for(int j=0; j<t-1; j++) {
			if(a[j]+a[j+1]>=h) {
				h=a[j]+a[j+1];
				o=j;
			}
		}
		if(a[t-1]+a[0]>=h) {
			sum+=a[t-1]+a[0];
			a[0]=a[t-1]+a[0];
		} else {
			a[o]=h;
			sum+=h;
			for(int j=o+1; j<t-1; j++) {
				a[j]=a[j+1];
			}
		}
		t--;
	}
	t=n;
	for(int i=0; i<n-1; i++) {
		int h=2000;
		int o=0;
		for(int j=0; j<t-1; j++) {
			if(b[j]+b[j+1]<=h) {
				h=b[j]+b[j+1];
				o=j;
			}
		}
		if(b[t-1]+b[0]<=h) {
			su+=b[t-1]+b[0];
			cout<<b[t-1]<<' '<<b[0]<<' '<<1<<endl;
			b[0]=b[t-1]+b[0];
		} else {
			b[o]=h;
			su+=h;
			cout<<h<<' '<<o<<endl;
			for(int j=o+1; j<t-1; j++) {
				b[j]=b[j+1];
			}
		}
		t--;
	}
	cout<<su<<endl<<sum;
	return 0;
}

中间三个点WA了

2022/8/7 12:12
加载中...