Problem Link:
Difficulty:
CAKEWALK
Pre-requisites:
ad-hoc
Problem:
You are given a string of "#" and "." representing a passage. A "#" means the presence of a floorboard, while a "." is the absence of it. Digory and Polly decide to cross the passage (from left to right). At each time, they can only tell where the next "#" position is. They start being able to jump a distance of 1, and whenever they are unable to jump a particular distance L, they take one day to learn how to jump L (and any distance <= L). In how many days will they be able to cross the passage?
Quick Explanation:
Just keep track of the current length of jump you need to perform. If it crosses your threshold at the next "#", update your threshold and add one to your answer. Pseudocode follows:
int f (string passage)
int L = 1, ans = 0, cur = 0
for(int i = 0; i < passage.length(); i++)
cur++;
if(passage[i] == '#')
if(cur > L)
L = cur
ans++
cur = 0
return ans
Setter's Solution:
Can be found here
Tester's Solution:
Can be found here