【noip模拟】德充符
时间限制: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】
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<algorithm>
- #include<cmath>
- #include<ctime>
- #include<vector>
- using namespace std;
- const int N = ;
- int n, a[N];
- inline int read(){
- int i = , f = ; char ch = getchar();
- for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
- if(ch == '-') f = -, ch = getchar();
- for(; ch >= '' && ch <= ''; ch = getchar())
- i = (i << ) + (i << ) + (ch - '');
- return i * f;
- }
- inline void wr(int x){
- if(x < ) putchar('-'), x = -x;
- if(x > ) wr(x / );
- putchar(x % + '');
- }
- int main(){
- freopen("dcf.in", "r", stdin);
- freopen("dcf.out", "w", stdout);
- n = read();
- srand(time());
- for(int i = ; i <= n; i++) a[i] = read();
- int T = , ans = -;
- while(T--){
- random_shuffle(a + , a + n + );
- int sum = a[];
- for(int i = ; i <= n; i++)
- sum = abs(sum - a[i]);
- if(sum > ans) ans = sum;
- }
- wr(ans);
- return ;
- }
【noip模拟】德充符的更多相关文章
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
随机推荐
- JS学习笔记 - fgm练习 2-11- 改变图片路径 var img = new Image(); 图片预加载
<style> *{ margin: 0;padding: 0; list-style: none; } body{ background: black; } .outer{ margin ...
- “-bash: !”: event not found"、echo > sudo permission denied
1. "-bash: !": event not found" 比如当我们在 linux 命令行输入echo "Reboot your instance!&qu ...
- python3中numpy函数tile的用法
tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...
- 【Codeforces Round #440 (Div. 2) B】Maximum of Maximums of Minimums
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k=1的时候就是最小值, k=2的时候,暴力枚举分割点. k=3的时候,最大值肯定能被"独立出来",则直接输出最 ...
- ArcSDE中空间数据的备份与恢复
在采用文件形式空间数据的时代,空间数据的备份仅仅是操作系统中的文件拷贝.备份和归档的过程:而空间数据的恢复也不过是复制.覆盖的操作:在基于ArcSDE和关系型数据库的空间数据库时代,空间数据的备份更多 ...
- [WASM] Write to WebAssembly Memory from JavaScript
We write a function that converts a string to lowercase in WebAssembly, demonstrating how to set the ...
- layui是什么
layui是什么 一.总结 一句话总结:初步看起来比amazeui好看一点点.移动端显示看起来效果真心不错.还有即时聊天那个组件下载,感觉真心不错,可以多去看看. 二.Layui 1.简介 经典模块化 ...
- C#判断操作系统类型
操作系统 PlatformID 主版本号 副版本号 Windows95 1 4 0 Windows98 1 4 10 WindowsMe 1 4 90 WindowsN ...
- 【Python排序搜索基本算法】之拓扑排序
拓扑排序是对有向无环图的一种排序,满足例如以下两个条件: 1.每一个顶点出现且仅仅出现一次. 2.若A在序列中排在B的前面.则在图中不存在从B到A的路径. 如上的无环有向图,v表示顶点:v=['a', ...
- NoSql中的B-tree、B+tree和LSM-tree 分类: B7_HBASE 2015-03-15 18:27 85人阅读 评论(0) 收藏
总结: 1.B+树将数据完全排序,读数据时很快,但当要修改数据时,就需要将新入数据下面的数据重新排位,特别是当写入的数据排在较高的位置时,需要大量的移位操作才能完成写入. 2.SLM牺牲部分的读性能, ...