HackerRank "Poisonous Plants"
I had the same BFS idea as one of the AC code this: because dying pattern is spead from the initial dying ones :)
#include <iostream>
#include <queue>
#include <vector>
using namespace std; int main()
{
int N; cin >> N;
vector<int> P(N + , -); // Dancing Links
vector<int> pre(N + );
vector<int> nex(N + ); // Markers
vector<int> day(N + ); for(int i = ; i < N; i ++)
{
cin >> P[i];
} // Fill initial queue
queue<int> q;
for(int i = N-; i > ; i--)
{
pre[i]=i-;
nex[i]=i+;
if(P[i] > P[i-])
{
day[i]=;
q.push(i);
}
} int ans = ;
while(!q.empty())
{
int cur=q.front(); q.pop();
ans = day[cur]; // Dis-link current index
pre[nex[cur]]=pre[cur];
nex[pre[cur]]=nex[cur]; if(P[nex[cur]] > P[pre[cur]]){
day[nex[cur]] = day[cur]+;
q.push(nex[cur]);
}
}
cout << ans << endl;
return ;
}
HackerRank "Poisonous Plants"的更多相关文章
- 日常小测:颜色 && Hackerrank Unique_colors
题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- HackerRank "Minimum Penalty Path"
It is about how to choose btw. BFS and DFS. My init thought was to DFS - TLE\MLE. And its editorial ...
- HackerRank "TBS Problem" ~ NPC
It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...
- HackerRank Extra long factorials
传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...
- HackerRank "Lucky Numbers"
Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...
- HackerRank "Playing with numbers"
This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah ...
- HackerRank "The Indian Job"
A sly knapsack problem in disguise! Thanks to https://github.com/bhajunsingh/programming-challanges/ ...
- HackerRank "Array and simple queries" !
The most interesting, flexible and juicy binary tree problem I have ever seen. I learnt it from here ...
随机推荐
- Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)
A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...
- js&jquery验证邮箱和手机号是否正确范例
实现源码: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ...
- js部分---运算符,if分支语句,for循环;switch case 的用法;
------------------------------------------运算符---------------------------------------------------- *数 ...
- php遇见的错误(一)
1.linux 执行脚本时报的错 Call to a member function on a non-object in 是没有实例化对象 解决方法 new类2.在给一个表增加一个新字段或者改 ...
- P188 实战练习(父类和子类)
1.创建一个父类,在父类中创建两个方法,在子类中覆盖第二个方法,为子类创建一个对象,将它向上转型到基类并调用这个方法. 创建Computer父类: package org.hanqi.practise ...
- hdu5441(2015长春赛区网络赛1005)类最小生成树、并查集
题意:有一张无向图,一些点之间有有权边,某条路径的值等于路径上所有边的边权的最大值,而某个点对的值为这两点间所有路径的值的最小值,给出多个询问,每个询问有一个值,询问有多少点对满足其值小于等于询问值. ...
- kuangbin_ShortPath J (POJ 1511)
其实虽然一开始有被这个题的8000MS 和 256MB限制又被吓到 但是严格来说跟之前的POJ 3268是一样的做法只是数据大了点 但是问题就出在数据大了点上 其实严格来说也不大 1e6 数组加起来大 ...
- Vimdiff---VIM的比较和合并工具
本文来自IBMDW http://www.ibm.com/developerworks/cn/linux/l-vimdiff/ 源程序文件(通常是纯文本文件)比较和合并工具一直是软件开发过程中比较 ...
- Unity光照
广义地说,Unity有2种光源.1.动态光源 2.Backed Lighting 1.动态光源 就是实时计算的.只要摆光源就可以了 2.Backed Lighting 提前处理好光照贴图.贴在物体上 ...
- vim配置及插件安装管理(超级详细)[转]
1 写在前面 Linux下编程一直被诟病的一点是: 没有一个好用的IDE, 但是听说Linux牛人, 黑客之类的也都不用IDE. 但是对我等从Windows平台转移过来的Coder来说, 一个好用 ...