题目链接: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. 转: WebRTC音视频引擎研究(1)--整体架构分析

    转自: http://blog.csdn.net/temotemo/article/details/7530504   目录(?)[+]   WebRTC技术交流群:234795279 原文地址:ht ...

  2. jquery_ajax 入门实例

    序:本文通过几个小样例,简单介绍怎样使用jqueryAjax异步载入. 1. $(selector).load(url,[data],[callback]) :加载远程HTML文件代码并插入DOM中. ...

  3. c++程序猿经典面试题(2)

    1.以下程序的输出结果是? #include<stdio.h> main(){ int b=3; int arr[]={6,7,8,9,10}; int *ptr=arr; *(ptr++ ...

  4. Vue2.0 视频教程

    好像是一套vue 开发webapp 课程.来自网络. url:https://pan.baidu.com/s/1jIele9w password:b404 文章来源:刘俊涛的博客 地址:http:// ...

  5. What is love ? and how to do?

    1.匹配度(matched-degree): 灵性 文化(东西方.南北方) 智力 审美 性 2.对待差异的原则(The principle of difference): 抓大放小 求同存异 心脑并用 ...

  6. ios文件系统文件目录操作

    对于一个运行在iPhone得app,它只能访问自己根目录下得一些文件(所谓sandbox). 一个app发布到iPhone上后,目录结构如下: 1.其中获取 app root 可以用 NSHomeDi ...

  7. idea刷新项目、清除项目缓存

    点击File -> Invalidate caches ,点击之后在弹出框中点击确认,之后软件就自动重启了

  8. UVA1422-Processor(二分法+优先队列)

    option=com_onlinejudge&Itemid=8&category=512&page=show_problem&problem=4168"> ...

  9. [概率dp] hdu 5378 Leader in Tree Land

    题意: 给你一颗以1位根节点的树.我们定义对于每一个子树,节点权值最大的权值记为这个子树的权值,为你将1~n放到这个树里 满足最大权值仅仅有k个的组合数是多少. 思路: 我们能够知道以每一个节点为子树 ...

  10. 再过半小时,你就能明白kafka的工作原理了

    本文在个人技术博客不同步发布,详情可猛戳 亦可扫描屏幕右侧二维码关注个人公众号,公众号内有个人联系方式,等你来撩... 为什么需要消息队列 周末无聊刷着手机,某宝网APP突然蹦出来一条消息" ...