题意:有n个位置,每次可以选其中一个往另外其它两个位置的中间插(如果有空的话),问最多能插几次

3<=n<=500

1 ≤ ai ≤ 10000

思路:显然可以把所有的空都利用起来

但最左最右两边的空必须选一边放弃

判断一下两种里面哪种更优就行了

感谢队友带我飞

 #include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#define left (now<<1)
#define right ((now<<1)+1)
#define mid ((l+r)>>1)
using namespace std;
typedef long long int lint; const int MAXN = 1e5 + ;
const int MOD = 1e9 + ; int n,t,a[MAXN];
lint ans1,ans2,ans; int main(){
int t; scanf("%d",&t);
while(t--){
scanf("%d",&n); ans1 = ans2 = ans = ;
for(int i = ; i <= n; ++i){
scanf("%d",&a[i]);
}
for(int i = ; i < n; ++i){
ans1 += 1ll * a[i + ] - a[i] - ;
}
for(int i = n - ; i > ; --i){
ans2 += 1ll * a[i] - a[i - ] - ;
}
ans = max(ans1,ans2);
printf("%I64d\n",ans);
}
return ;
}

【HDOJ6227】Rabbits(贪心)的更多相关文章

  1. The 2017 ACM-ICPC Asia Shenyang Regional Contest

    传送门 F - Heron and His Triangle 直接打表找到规律\(f_i=4f_{i-1}+f_{i-2}\),然后大数预处理一下,对于询问直接输出就行. Code #include ...

  2. 【做题记录】CF1428E Carrots for Rabbits—堆的妙用

    CF1428E Carrots for Rabbits 题意: 有 \(n\) 个萝卜,每个萝卜的初始大小为 \(a_i\) .现在要把这些萝卜切为为 \(k\) 个.吃每一个萝卜的时间为这个萝卜的大 ...

  3. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  4. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  9. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

随机推荐

  1. Xcode4删除文件后missing file警告

    1.运行终端,执行命令行进入missing file目录,然后运行 svn delete nameOfMissingFile 或 git rm nameOfMissingFile 2.删除隐藏的.sv ...

  2. BOM函数之history对象

    前面的话 history对象保存着用户上网的历史记录,从窗口被打开的那一刻算起.由于安全方面的考虑,开发人员无法得到用户浏览器的URL,但借由用户访问过的页面列表,可以在不知道实际URL的情况下实现后 ...

  3. Bootstrap历练实例:成功按钮

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  4. shell脚本,文件里面的英文大小写替换方法。

    [root@localhost wyb]# cat daxiaoxie qweBNMacb eeeDFSmkl svdIOPtyu [root@localhost wyb]# cat daxiaoxi ...

  5. mysql delete 表无法用别名

    delete from exam_paper_question_opt a WHERE a.OPTION_ID = 65630 and a.QUESTION_ID = 28656 AND a.EXAM ...

  6. 如何用纯 CSS 创作一支诱人的冰棍

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/vrxzMw 可交互视频教 ...

  7. LeetCode(121) Best Time to Buy and Sell Stock

    题目 Say you have an array for which the ith element is the price of a given stock on day i. If you we ...

  8. 出现Android.os.NetworkOnMainThreadException 错误

    两种方法解决: 1.如果用的gradle打包,在build.gradle中修改配置 修改SDKVersion 为低版本(7),不能版本降低过多,否则会出现很多不适配. 2.将网络访问放在一个新的线程中 ...

  9. 【07】像使用命令行一样使用 GitHub URL

    [07] 像使用命令行一样使用 GitHub URL 既然说到了 URL,那么久接着聊一下.使用 UI 浏览 GitHub 很 方面也很好,不过很多时候最快的方式是使用 URL 来浏览.举个例子,如果 ...

  10. div+css居中

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...