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. 【Avalon】获取隐藏元素的尺寸

    保存原来的属性 设置成显示的属性 获取尺寸 设置回原来的属性 var cssShow = { position: "absolute", visibility: "hid ...

  2. 一直纠结中的"底层模板"含义(借鉴)

    无意间看到这个解释,推荐给哪些和我一样迷惑的人!

  3. java设定窗口步长,依次统计窗口内数值总和

    import java.util.Arrays; public class test2 { public static void main(String[] args) { int winSize = ...

  4. 21. Merge Two Sorted Lists

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  5. 发布常见问题(C#)

    1.Sys.WebForms.PageRequestManagerServerErrorException: 在服务器上处理请求时出现未知错误.服务器返回的状态码为: 500 可能的原因: asp.n ...

  6. 转:bash: /dev/null: Permission denied

    普通用户登录:bash: /dev/null: Permission denied 2012-12-07 16:01:36|  分类: linux |举报 |字号 订阅     Last login: ...

  7. AXIOM解析XML 详细原理

    转自:http://warlaze.blog.sohu.com/58477971.html AXIOM Axis对象模型(AXIOM)是一个XML对象模型,设计用于提高XML处理期间的内存的使用率和性 ...

  8. 最小二乘法 java

    import java.util.ArrayList; import java.util.Collection; import org.apache.commons.math3.optim.Point ...

  9. leetcode 92 Reverse Linked List II ----- java

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  10. 工作中遇到的问题--缓存配置(使用@Configuration装配 @Bean的方式注入)

    @EnableCaching@Configurationpublic class MFGCachingConfiguration { @Autowired private MFGSettings mf ...