1070 结绳 理解题意较难,代码实现不难

代码

#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main()
{
	int n;
	int a;
	int tmp;
	int tmp2;
	multiset<int> st;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		st.insert(a);
	}
	while(st.size()>1){
		tmp=*st.begin();
		st.erase(st.begin());
		tmp2=*st.begin();
		st.erase(st.begin());
		st.insert((tmp+tmp2)/2);
	}
	cout<<*st.begin();
	return 0;
}
posted @ 2022-07-12 10:49  qwasdasd  阅读(46)  评论(0)    收藏  举报