题目没读懂,刚开始都不知道他在说些什么。。。ios
简而言之就是给出一堆绳子,练成一条;spa
没两两段绳子练成环,串在一块儿,以后仍旧视为一串绳子,下次跟别的单独绳子链接的时候仍需对折;code
因此能够看出,越长的绳子在前面越对折越吃亏,因此应该进行排序,长的绳子放在后面进行链接;排序
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<set> #include<algorithm> using namespace std; using std::vector; using std::set; const int maxn=10100; int lope[maxn]={0}; int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&lope[i]); } sort(lope,lope+n); int line=lope[0]; for(int i=1;i<n;i++){ line+=lope[i]; line/=2; } printf("%d",line); system("pause"); return 0; }