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 ...
随机推荐
- 关于KVM的几篇细节文档
1. Qemu Study http://lists.gnu.org/archive/html/qemu-devel/2011-04/pdfhC5rVdz7U8.pdf http://handboo ...
- 时间作为横轴的图表(morris.js)超越昨天的自己系列(8)
超越昨天的自己系列(8) morris.js的官网有详细的例子:http://www.oesmith.co.uk/morris.js/ 特别注意它的依赖: <link rel="sty ...
- Apache、tomcat、Nginx常用配置合集
配置文件地址: Apache: /etc/httpd/conf/httpd.conf tomcat: /usr/local/tomcat/conf/server.xml Nginx : /usr/l ...
- iPhone4@iOS7Beta4,第一时间刷上,失望,看来苹果是铁了心往扁平化UI走了。看好我的614,保存好SHSH准备
1 今天早上看到新闻,iOS7Beta4放出了,于是赶紧,在家下载,网速很快.(要是在公司,那50K的速度,估计会疯的) 2 等了一会儿一直在提示准备安装,不等了,再等该迟到了. 3 路上实在忍不住, ...
- jquery获取第几个元素的方法总结
使用jquery时经常会遇到,选择器选择一组元素后,需要在这组元素中找到第几个元素. jquery中使用eq()方法找到第几个元素或第N个元素,jquery中eq()的使用如下: eq() 选择器选取 ...
- JS的跨域问题
1.什么是跨域? 跨域问题是由于javascript语言安全限制中的同源策略造成的. 2.什么是同源策略: 同源策略是指一段脚本只能读取来自同一来源的窗口和文档的属性,这里的同一来源指的是主机名.协议 ...
- Spring MVC程序中得到静态资源文件css,js,图片文件的路径问题总结
上一篇 | 下一篇 Spring MVC程序中得到静态资源文件css,js,图片 文件的路径 问题总结 作者:轻舞肥羊 日期:2012-11-26 http://www.blogjava.net/fi ...
- JavaWeb学习记录(十五)——浏览器Cookie禁用后的处理
IE禁用Cookie方式:
- spark优化之优化数据结构
概序: 要减少内存的消耗,除了使用高效的序列化类库以外,还有一个很重要的事情,就是优化数据结构.从而避免Java语法特性中所导致的额外内存的开销,比如基于指针的Java数据结构,以及包装类型. 有一个 ...
- Amazon-countDuplicate
Print the count of duplicate char in a given string in same order. Ex: Input- 'abbaccdbac', Output- ...