题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4908

题目意思:给出 一个从1~N 的排列你和指定这个排列中的一个中位数m,从这个排列中找出长度为奇数,中位数是m的子序列有多少个。

我的做法被discuss 中的测试数据一下子就否定了。

这个是别人的做法,暂时留下来,有些地方还没真正弄懂,应该是缺了部分的知识没有学到。。。

留着先:

(1)http://blog.csdn.net/hcbbt/article/details/38377815

(2)  思路:找出m的位置sign,然后向前找比m小,cou++,的index[]在相应的位置加一(等向m后面找的时候发现比m大的元素,构成了一个BestCoder Sequence,直接就sum+=index[]),比m大,cou--,也在的index[]在相应的位置加一(这样就把m前面比m大的数 也加入到准备数组index中,当m后面有比m大的时候sum+=index[],就把m前面比m大的元素也算上了,也构成了一个BestCoder Sequence)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = ;
int a[maxn], h[maxn]; int main()
{
int n, m;
int mid = maxn/;
while (scanf("%d%d", &n, &m) != EOF)
{
int posm;
for (int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
if (a[i] == m)
posm = i;
}
memset(h, , sizeof(h));
int r = , l = ;
for (int i = posm; i <= n; i++)
{
if (a[i] > m)
r++;
else if (a[i] < m)
r--;
h[mid+r]++;
}
int cnt = ;
for (int i = posm; i >= ; i--)
{
if (a[i] > m)
l++;
else if (a[i] < m)
l--;
cnt += h[mid-l];
}
printf("%d\n", cnt);
}
return ;
}

BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告的更多相关文章

  1. BestCoder18 1002.Math Problem(hdu 5105) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...

  2. BestCoder12 1002.Help him(hdu 5059) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...

  3. BestCoder3 1001 Task schedule(hdu 4907) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4907 题目意思:给出工作表上的 n 个任务,第 i 个任务需要 ti 这么长的时间(持续时间是ti ~ ...

  4. 【九度OJ】题目1442:A sequence of numbers 解题报告

    [九度OJ]题目1442:A sequence of numbers 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1442 ...

  5. BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...

  6. hdu 1002.A + B Problem II 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...

  7. BestCoder17 1002.Select(hdu 5101) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...

  8. BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...

  9. BestCoder4 1002 Miaomiao's Geometry (hdu 4932) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1 ...

随机推荐

  1. 预防SQL注入笔记

    SQL注入如何预防? 本文参考自owasp,重点是提供清晰,简单,可操作的指导,以防止应用程序中的SQL注入漏洞.不幸的是,SQL注入攻击很常见,这是由于两个因素: SQL注入漏洞的显着流行 目标的吸 ...

  2. IntelliJ IDEA重构技巧收集

    https://segmentfault.com/a/1190000002488608(重命名文件) http://www.jianshu.com/p/ab298b46bf50(快速生成方法) htt ...

  3. Android自定义Dialog效果

    上面是效果图. 使用方法: NiftyDialogBuilder dialogBuilder=NiftyDialogBuilder.getInstance(this); dialogBuilder . ...

  4. httplib 和 httplib2区别之 gzip解压

    HTTP请求头Accept-encoding: gzip信息告诉服务器,如果它有任何新数据要发送给时,请以压缩的格式发送.如果服务器支持压缩,它将返回由 gzip 压缩的数据并且使用Content-e ...

  5. 视图交互--表视图(UITableView)的cell交互析略

    在表视图UITableView的cell上经常有一些交互,根据项目开发中的情况,需要对此进行一些规范.总结出了几种交互方法,这些方法在其他视图的交互上同样可以适用.用一个简单的例子来举例说明一下,其他 ...

  6. AngularJS的表单验证提交示例

    代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsFormSubmit.rar 前台代码: <%@ page content ...

  7. linux下nginx+php+mysql 自助环境搭建

    ++++++++++++++++++++++++++++++++++++++++++++++linux下nginx+php+mysql环境搭建+++++++++++++++++++++++++++++ ...

  8. PHP开发环境简析

    单工作机情况 windows + wamp windows + XShell类终端工具 + linux虚拟机 Ubuntu桌面版 自带终端 Mac OS + mamp Mac OS 自带终端 Mac ...

  9. CareerCup之1.6 Rotate Image

    [题目] 原文: 1.6 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, ...

  10. IMDB-WIKI - 具有年龄和性别标签的500k +脸部图像

    Rasmus Rothe, Radu Timofte, Luc Van Gool DEX:从单一形象深刻地看待年龄 观看 人物研讨会国际计算机视觉大会(ICCV),2015*获胜LAP面对年龄估计的挑 ...