题目链接: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. emacs 打开文件乱码

    emacs在win下写的文件在linux打开乱码 M-x set-language-environment RET   chinese-gb    改变当前编码 用当前编码重新打开 M-x rever ...

  2. mac mysql忘记密码解决办法

    http://www.jb51.net/article/87580.htm http://blog.csdn.net/soft2buy/article/details/50223373

  3. can-i-win(好)

    https://leetcode.com/problems/can-i-win/ package com.company; import java.util.*; class Solution { / ...

  4. LibSVM 安装使用

    知道这个库已经很长的时间了,一直没有实践,以前也看过svm的理论,今天开始安装一下一直感觉有错误,结果自己傻了,根本没有错,可以直接使用... libsvm参考资料: libsvm下载网址:http: ...

  5. 转: How to Install MongoDB 3.2 on CentOS/RHEL & Fedora (简单易懂)

    from:  http://tecadmin.net/install-mongodb-on-centos-rhel-and-fedora/ MongoDB (named from “huMONGOus ...

  6. Android Studio 设置项目Module编码,解决Android Studio项目执行时乱码问题

    Android Studio的项目设置逻辑与Eclipse有非常大的差别.运行的操作为File->Setting->File Encodings然后来进行设置,如图所看到的: waterm ...

  7. sklearn特征选择和分类模型

    sklearn特征选择和分类模型 数据格式: 这里.原始特征的输入文件的格式使用libsvm的格式,即每行是label index1:value1 index2:value2这样的稀疏矩阵的格式. s ...

  8. update tableView contenSize

    NSIndexPath *messageIndexPath = [NSIndexPath indexPathForRow:afterRowCount-1 inSection:0];    [self. ...

  9. Android SDK下载速度慢的解决方法(简单使用代理)

    相信做android开发的同学们.一定会遇到的问题就是google那边常常崩,可是学习的開始.我们又必须要用Android SDK,(几个G的大小),一般我们装完ADT之后(假设你用的是Eclipse ...

  10. spl_autoload_register的使用

    class Loader{ static function loadClass($class) { $class = $class.'.php'; if(file_exists($class)) { ...