网站的必要性,wordpress免费模版安装教程,google网站打不开了,湖北省和住房建设厅官方网站时间限制#xff1a;2s 内存限制#xff1a;512MB 【题目描述】 申徒嘉和郑子产都是伯昏无人的学生#xff0c;子产因为申徒嘉是残疾人#xff0c;非常看不起他#xff0c;于是想要刁难他。 子产给了申徒嘉 n个数 a1,a2...an。 现在他要求申徒嘉重新排列这些数#xff0c…时间限制2s 内存限制512MB 【题目描述】 申徒嘉和郑子产都是伯昏无人的学生子产因为申徒嘉是残疾人非常看不起他于是想要刁难他。 子产给了申徒嘉 n个数 a1,a2...an。 现在他要求申徒嘉重新排列这些数使得 H||...|b1-b2|-b3|-b4|-...|-bn|最大b 是a 重新排列后的序列,|x|表示取 x的绝对值 申徒嘉对于吹逼很擅长但是数学就不怎么样了于是他请你来帮帮他。 【输入格式】 第一行一个数 n接下来一行n个数第 i 个数表示a[i] n300 1a[i]300 对于30%的数据n10 【输出格式】 输出一行一个整数表示答案 【样例输入】 4 3 6 7 8 【样例输出】 6 【样例解释】 对于第一组样例 |||6-8|-3|-7| 6 【题目分析】 乱搞做法 因为答案不超过300而且似乎要控制只有少数特定的排列使得答案最大是不太容易的因此不断随机打乱更新答案就很容易得到最大值。 【code】 #includeiostream
#includecstdio
#includecstdlib
#includecstring
#includealgorithm
#includecmath
#includectime
#includevector
using namespace std;const int N 305;
int n, a[N];inline int read(){int i 0, f 1; char ch getchar();for(; (ch 0 || ch 9) ch ! -; ch getchar());if(ch -) f -1, ch getchar();for(; ch 0 ch 9; ch getchar())i (i 3) (i 1) (ch - 0);return i * f;
}inline void wr(int x){if(x 0) putchar(-), x -x;if(x 9) wr(x / 10);putchar(x % 10 0);
}int main(){freopen(dcf.in, r, stdin);freopen(dcf.out, w, stdout);n read();srand(time(0));for(int i 1; i n; i) a[i] read();int T 200000, ans -1;while(T--){random_shuffle(a 1, a n 1);int sum a[1];for(int i 2; i n; i)sum abs(sum - a[i]);if(sum ans) ans sum;}wr(ans);return 0;
} 转载于:https://www.cnblogs.com/CzYoL/p/7412531.html