时间限制:2s
内存限制:512MB

【题目描述】
申徒嘉和郑子产都是伯昏无人的学生,子产因为申徒嘉是残疾人,非常看不起他,于是
想要刁难他。
子产给了申徒嘉 n个数 a1,a2...an。
现在他要求申徒嘉重新排列这些数,使得 H=||...|b1-b2|-b3|-b4|-...|-bn|最大(b 是
a 重新排列后的序列,|x|表示取 x的绝对值)
申徒嘉对于吹逼很擅长,但是数学就不怎么样了,于是他请你来帮帮他。

【输入格式】
第一行一个数 n,接下来一行n个数,第 i 个数表示a[i]
n<=300
1<=a[i]<=300
对于30%的数据,n<=10

【输出格式】
输出一行一个整数表示答案

【样例输入】
4
3 6 7 8

【样例输出】
6

【样例解释】
对于第一组样例:
|||6-8|-3|-7| = 6

【题目分析】

乱搞做法:

因为答案不超过300,而且似乎要控制只有少数特定的排列使得答案最大是不太容易的,因此不断随机打乱更新答案,就很容易得到最大值。

【code】

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<ctime>
  8. #include<vector>
  9. using namespace std;
  10.  
  11. const int N = ;
  12. int n, a[N];
  13.  
  14. inline int read(){
  15. int i = , f = ; char ch = getchar();
  16. for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
  17. if(ch == '-') f = -, ch = getchar();
  18. for(; ch >= '' && ch <= ''; ch = getchar())
  19. i = (i << ) + (i << ) + (ch - '');
  20. return i * f;
  21. }
  22.  
  23. inline void wr(int x){
  24. if(x < ) putchar('-'), x = -x;
  25. if(x > ) wr(x / );
  26. putchar(x % + '');
  27. }
  28.  
  29. int main(){
  30. freopen("dcf.in", "r", stdin);
  31. freopen("dcf.out", "w", stdout);
  32. n = read();
  33. srand(time());
  34. for(int i = ; i <= n; i++) a[i] = read();
  35. int T = , ans = -;
  36. while(T--){
  37. random_shuffle(a + , a + n + );
  38. int sum = a[];
  39. for(int i = ; i <= n; i++)
  40. sum = abs(sum - a[i]);
  41. if(sum > ans) ans = sum;
  42. }
  43. wr(ans);
  44. return ;
  45. }

【noip模拟】德充符的更多相关文章

  1. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  2. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  3. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  4. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  5. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  6. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  7. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  8. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  9. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

  10. CH Round #49 - Streaming #4 (NOIP模拟赛Day2)

    A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...

随机推荐

  1. JS学习笔记 - fgm练习 2-11- 改变图片路径 var img = new Image(); 图片预加载

    <style> *{ margin: 0;padding: 0; list-style: none; } body{ background: black; } .outer{ margin ...

  2. “-bash: !”: event not found"、echo > sudo permission denied

    1. "-bash: !": event not found" 比如当我们在 linux 命令行输入echo "Reboot your instance!&qu ...

  3. python3中numpy函数tile的用法

    tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...

  4. 【Codeforces Round #440 (Div. 2) B】Maximum of Maximums of Minimums

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k=1的时候就是最小值, k=2的时候,暴力枚举分割点. k=3的时候,最大值肯定能被"独立出来",则直接输出最 ...

  5. ArcSDE中空间数据的备份与恢复

    在采用文件形式空间数据的时代,空间数据的备份仅仅是操作系统中的文件拷贝.备份和归档的过程:而空间数据的恢复也不过是复制.覆盖的操作:在基于ArcSDE和关系型数据库的空间数据库时代,空间数据的备份更多 ...

  6. [WASM] Write to WebAssembly Memory from JavaScript

    We write a function that converts a string to lowercase in WebAssembly, demonstrating how to set the ...

  7. layui是什么

    layui是什么 一.总结 一句话总结:初步看起来比amazeui好看一点点.移动端显示看起来效果真心不错.还有即时聊天那个组件下载,感觉真心不错,可以多去看看. 二.Layui 1.简介 经典模块化 ...

  8. C#判断操作系统类型

    操作系统  PlatformID  主版本号  副版本号  Windows95  1  4  0  Windows98  1  4  10  WindowsMe  1  4  90  WindowsN ...

  9. 【Python排序搜索基本算法】之拓扑排序

    拓扑排序是对有向无环图的一种排序,满足例如以下两个条件: 1.每一个顶点出现且仅仅出现一次. 2.若A在序列中排在B的前面.则在图中不存在从B到A的路径. 如上的无环有向图,v表示顶点:v=['a', ...

  10. NoSql中的B-tree、B+tree和LSM-tree 分类: B7_HBASE 2015-03-15 18:27 85人阅读 评论(0) 收藏

    总结: 1.B+树将数据完全排序,读数据时很快,但当要修改数据时,就需要将新入数据下面的数据重新排位,特别是当写入的数据排在较高的位置时,需要大量的移位操作才能完成写入. 2.SLM牺牲部分的读性能, ...