【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希
BestCoder Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 573 Accepted Submission(s): 201
Mr Potato is the BestCoder.
One night, an amazing sequence appeared in his dream. Length of this sequence is odd, the median number is M, and he named this sequence as Bestcoder Sequence.
As the best coder, Mr potato has strong curiosity, he wonder the number of consecutive sub-sequences which are bestcoder sequences in a given permutation of 1 ~ N.
For each test case, there is a pair of integers N and M in the first line, and an permutation of 1 ~ N in the second line.
[Technical Specification]
1. 1 <= N <= 40000
2. 1 <= M <= N
3
For the second case, {3},{5,3,2},{4,5,3,2,1} are Bestcoder Sequence.
- #include <cstdio>
- #include <cstring>
- const int LEN = ;
- int arr[LEN];
- int table1[LEN];
- int table2[LEN];
- int main()
- {
- int n, m;
- while(scanf("%d %d", &n, &m) != EOF){
- memset(table1, , sizeof(table1));
- memset(table2, , sizeof(table2));
- int t = -;
- for(int i = ; i < n; i++){ //读入并记录m的位置
- scanf("%d", arr+i);
- if (arr[i] == m)
- t = i;
- }
- int ans = ;
- if (t != -) //如果m不在序列中则ans = 0 否则为1,即只有他本身时的情况
- ans = ;
- int ma = ;
- int mi = ;
- for(int i = t-; i >= ; i--){
- if (arr[i] < arr[t])
- mi++;
- else
- ma++;
- int tmp = ma - mi; //哈希记录tmp。
- if (tmp < )
- table1[-tmp]++;
- else
- table2[tmp]++;
- if (ma == mi) //特判t = 0的情况
- ans++;
- }
- ma = ;
- mi = ;
- for(int i = t+; i < n; i++){
- if (arr[i] < arr[t])
- mi++;
- else
- ma++;
- int tmp = mi - ma;
- if (tmp < )
- ans += table1[-tmp]; //查询有没有出现过,若有,则加上出现的次数
- else
- ans += table2[tmp];
- if (ma == mi) //特判t = 0
- ans++;
- }
- printf("%d\n", ans);
- }
- return ;
- }
【HDU】4908 (杭电 BC #3 1002题)BestCoder Sequence ——哈希的更多相关文章
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- 2014/08/24——升级stepbystep修复tc不刷新问题并加入杭电bc
问题: 自从tc站点升级以后做题统计的tc一栏就不刷新了,为此全哥也更新了一下stepbystep的配置文件什么的,我仅仅要将其挂到server上即可了. 由于加了杭电的bc,看来这事儿不easy.还 ...
- HDU 4901(杭电多校训练#3 1005题)The Romantic Hero(DP)
题目地址:HDU 4901 这题没想到最后竟然可以做出来.. .. 这题用了两次DP,先从前往后求一次异或的.再从后往前求一次与运算的. 各自是 1:求异或的时候,定义二维数组huo[1000][10 ...
- HDU 4968(杭电多校#9 1009题)Improving the GPA (瞎搞)
题目地址:HDU 4968 这题的做法是全部学科的学分情况枚举,然后推断在这样的情况下是否会符合平均分. 直接暴力枚举就可以. 代码例如以下: #include <cstring> #in ...
- HDU 4970(杭电多校#9 1011题)Killing Monsters(瞎搞)
题目地址:HDU 4970 先进行预处理.在每一个炮塔的火力范围边界标记一个点. 然后对每一个点的伤害值扫一遍就能算出来. 然后在算出每一个点到终点的总伤害值,并保存下来,也是扫一遍就可以. 最后在询 ...
- HDU 6610 Game — 2019第三场杭电多校 1008题
目录 题意 思路 AC_Code @(hdu 6610) 题意 大概说一下我理解的题意... 链接:here 你有\(n\)堆石子,每堆石子有\(a_i\)个石子.游戏规则:\(Alice\)先选择一 ...
- HDU 献给杭电五十周年校庆的礼物 1290 递推
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1290 题目大意: n刀最多可以把一块蛋糕切多少块 题目分析: 假如我们按照立体考虑的话,这题就非常不 ...
- 【单调栈】hdu 6319 杭电多校Problem A. Ascending Rating
http://acm.hdu.edu.cn/showproblem.php?pid=6319 从后往前更新,维护一个递减单调栈(队列) 最近很多题都是单调栈... #define _CRT_SECUR ...
- HDU6655 Just Repeat(2019杭电多校J题)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 简单博弈问题,A,B手里各有n,m张牌,牌有颜色,两人轮流出牌(A先出),一个人只能打出对放未打 ...
随机推荐
- 自动注册服务NET Core扩展IServiceCollection
NET Core扩展IServiceCollection自动注册服务 前言 在ASP.NET Core中使用依赖注入中使用很简单,只需在Startup类的ConfigureServices()方法中, ...
- Silverlight中无法设置卫星程序集为中立资源程序集
熟悉.Net资源文件体系的人都知道,中立资源程序集(Neutral Resource Assembly)的作用在于,一旦指定语言文化(Culture)的资源查找不到,便会Fallback到中立资源程序 ...
- 40. Testing Prev Part IV. Spring Boot features
40. Testing Spring Boot provides a number of utilities and annotations to help when testing your app ...
- 查询无序列表中第K小元素
当需要在无需列表中寻找第k小的元素时,一个显然的方法是将所有数据进行排序,然后检索k个元素.这种方法的运行时间为O(n log(n)). 无序列表调用分区函数将自身分解成两个子表,其长度为i和n-i. ...
- Android UI ActionBar功能-自定义Tab功能
还可以使用ActionBar实现Tab选项卡功能: 官方帮助文档:http://wear.techbrood.com/training/basics/actionbar/styling.html#Cu ...
- arcgis for javascript之ArcGISDynamicMapServiceLayer图层控制的实现
图层控制是非常多GIS系统里面必须的一个小功能,本文就说说arcgis for javascript下ArcGISDynamicMapServiceLayer图层控制的实现方式.首先看图: 实现效果 ...
- Oracle方向
从毕业到现在工作已经4年了,入职前去过私企,干过外企,当前到了国企,各有各的不同,对于不同的人,有不同的适合的选择. 这几年的工作中也积累了不少知识,业务上的.技术上的,但始终觉得没有掌握一门核心,没 ...
- Java复习第一天---Javascript的基本知识点
1.HelloWord: 2.基础语法: 3.嵌入HTML 借助window.onload事件在整个窗体载入完毕之后运行程序代码 4.事件驱动: 5.DOM操作 5.1 查找元素节点 5.1.1 依据 ...
- oracle获取本月第一天和最后一天及Oracle trunc()函数的用法
select to_char(trunc(add_months(last_day(sysdate), -1) + 1), 'yyyy-mm-dd') "本月第一天", to_cha ...
- some knowledge t
NSNumber static 看下面例子 gCount可以在Person 文件中使用 在main 中不行 @property()括号中可以填的属性 国际化 OC中的快捷键操作 operation ...