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"的更多相关文章

  1. 日常小测:颜色 && Hackerrank Unique_colors

    题目传送门:https://www.hackerrank.com/challenges/unique-colors 感谢hzq大神找来的这道题. 考虑点分治(毕竟是路经统计),对于每一个颜色,它的贡献 ...

  2. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  3. 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 ...

  4. HackerRank "TBS Problem" ~ NPC

    It is marked as a NPC problem. However from the #1 code submission (https://www.hackerrank.com/Charl ...

  5. HackerRank Extra long factorials

    传送门 今天在HackerRank上翻到一道高精度题,于是乎就写了个高精度的模板,说是模板其实就只有乘法而已. Extra long factorials Authored by vatsalchan ...

  6. HackerRank "Lucky Numbers"

    Great learning for me:https://www.hackerrank.com/rest/contests/master/challenges/lucky-numbers/hacke ...

  7. HackerRank "Playing with numbers"

    This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah ...

  8. HackerRank "The Indian Job"

    A sly knapsack problem in disguise! Thanks to https://github.com/bhajunsingh/programming-challanges/ ...

  9. HackerRank "Array and simple queries" !

    The most interesting, flexible and juicy binary tree problem I have ever seen. I learnt it from here ...

随机推荐

  1. UVa 10624 - Super Number

    题目大意 给定两个数n和m,如果长度为m的数满足对于每个i(n<=i<=m),数字的前i位都能被i整除,那么这个数就是超级数,求出字典序最小的符合要求的超级数. 分析 直接暴力搜索 #in ...

  2. php部分---面向对象:定义、实例化、构造函数、析构函数;

    类 − 定义了一件事物的抽象特点.类的定义包含了数据的形式以及对数据的操作. 对象 − 是类的实例.一切皆对象.由类实例化出来的. 成员变量 − 定义在类内部的变量.该变量的值对外是不可见的,但是可以 ...

  3. 安卓虚拟机启动后报错: 类似 SDK Manager] Error: Error parsing .....devices.xml 解决方案

    昨天用android sdk manager 更新了android sdk, 我是在eclipse上面安装adt来开发android的, 而且我每次打开虚拟机的时候也报错.报错的信息都是一样的.    ...

  4. PHP间隔一段时间执行

    for ($i=0; $i < 20; $i++) { $m=M('vote'); $rs=$m->order('id')->select(); $randnum=array(0,1 ...

  5. (转) TensorFlow深度学习,一篇文章就够了

    TensorFlow深度学习,一篇文章就够了 2016/09/22 · IT技术 · TensorFlow, 深度学习 分享到:6   原文出处: 我爱计算机 (@tobe迪豪 )    作者: 陈迪 ...

  6. Processor Speculative & pipeline

    https://en.wikipedia.org/wiki/Instruction-level_parallelism https://en.wikipedia.org/wiki/Instructio ...

  7. c程序代码优化的一些方法

    我认为一个好的用于科学计算的程序代码应该:算法漂亮精妙,程序简洁易懂,运算快速,节省内存.这里有的地方是矛盾的,比如简洁vs易懂,时间vs空间,找个平衡吧.目前来看时间要比空间宝贵一些.写程序分几步: ...

  8. Linux-TCP/IP TIME_WAIT状态原理

    TIME_WAIT状态原理---------------------------- 通信双方建立TCP连接后,主动关闭连接的一方就会进入TIME_WAIT状态. 客户端主动关闭连接时,会发送最后一个a ...

  9. jquery ajax POST 例子详解

    function test(){ $.ajax({ //提交数据的类型 POST GET type:"POST", //提交的网址 url:"testLogin.aspx ...

  10. Unity3d 适配机型

    1,为了是更多机型能够安装你的游戏,Unity3d Device Filter设置:ARMv6 with VFP: 2,华为C8600,一运行强制停止: 参考网址:http://forum.unity ...