
OP is probably expecting a simple solution, given the description of the problem. HTML looks simple enough, but even if one only takes valid HTML into account, there are a lot of rules one might break.
The easiest way to see if it matches up might be by simply rendering it and seeing if there's an exception. The neat (read as "expensive") way would be an interpreterpattern.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics."  Some Bell.





I took a chance and "assumed" their "test data" would be relatively "simple".
While your example is valid, it's also not "fair".
(At times I see code that I wouldn't touch without rewriting it first).
"Fringe cases" can be dealt with easier once one has "something" going (which is usually my objective).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal





Gerry Schmitz wrote: While your example is valid, it's also not "fair".
I challenge you to find any nontrivial HTML page which doesn't include nested <div> tags.
Maybe the OP should use Regular Expressions[^] instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
 Homer





Part 2 would have been:
Read reverse.
Locate inner block.
Remove block.
Repeat.
(From my Wiki "nontrivial" page scraper and Flesch Reading Gunning FOG Index calculator. It also removed "malformed" HTML).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 6Jun18 12:41pm.





Just curious if RBFS can be used in pathfinding scenario such as a map with obstacles between location A and B? I am doing an experiment and the result shows that for some situations RBFS is able to find the path but for others it is not, even there are paths available.





By definition, a path is not a path if there is an "obstacle" (that cannot be overcome).
(Unless one considers / programs a "deadend" as a "branch" / uturn).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal





It is a normal behaviour as RBFS is heuristic, so it discards some branches of the solution tree which may contain the solution. There are some heuristic algorithms, also for some graph problems, that find a solution which is not optimal but they at least find something close to the solution, which is satisfactory, whereas the other heuristic algorithms, when they miss the solution path, they will give you no results.
For finding paths in graphs, heuristic algorithms should be used only if you do not have enough memory for a regular BFS. They usually provide no solution if they miss them. I am now writing solving diamond peg solitaire with BFS, which should be ready within a couple of days on my site
informatykadelphi.blogspot.com
If I am lucky, the graph will have up to 15 GB, compressed graph 4GB, so I shall find the solution with BFS.





I am trying to develop an algorithm which will be able to find minimum spanning tree from a graph.I know there are already many existing algorithms for it.However I am trying to eliminate the sorting of edges required in Kruskal's Algorithm.The algorithm I have developed so far has a part where counting of disjoint sets is needed and I need a efficient method for it.After a lot of study I came to know that the only possible way is using BFS or DFS which has a complexity of O(V+E) whereas Kruskal's algorithms has a complexity of O(ElogE).Now my question is which one is better,O(V+E) or O(ElogE)?





It seems reasonable to simply test both options instead of depending on hearsay.
Unlesss it's not that important; then just flip a coin.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal





Depends on how dense the graph is.





Hello,
Last week I studied aes gcm in lectures. But I fail to understand. Can anyone help to make me understand? Perhaps with explanations or schematic drawings. Thank you






On the link which you have shown all the explanations just discuss aes. Is aes gcm same with aes?





Don't you realize you could have Googled "Is aes gcm same with aes?  Google Search
Do you know how many lives your are impacting and how much life energy you are wasting?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal






<hi,
i am="" using="" subpixel="" edge="" detection="" algorithm="" implementing="" according="" to="" carsten="" steger's="" method.="" the="" output="" is="" a="" struct="" as="" following
struct="" contour="" {="" std::vector<cv::point2f=""> points; // edge location
std::vector<float> direction; // direction of the gradient in edge point,
// starting from y axis, counterclockwise
std::vector<float> response; // amptitude of the gradient in edge point };
How do i use the data of direction and response parameters for drawing and what is the meaning of these parameters?
Thanks





I have a problem where I travel from point A to B and there is distance defined as `l`. In my car, I have a tank which can let me go only `b` kilometers. In `n` places there are gas stations and its cost for filling up my tank (I can only refill it fully). I start with a full tank.
What is the most efficient algorithm to get from the start of the highway to the end with the least cost?
My recent ideas:
Go with window sliding minimum algorithm to find (length is `b`) those stations where the cost is minimal. Code:
int n, range, targetDist;
scanf("%d %d %d", &n, &targetDist, &range);
int di, ci;
for (int k = 1; k <= n; k++)
{
scanf("%d %d", &di, &ci);
D[k] = di;
C[k] = ci;
}
D[0] = C[0] = bestcost[0] = 0;
for (int i = 1; i < n+1; ++i)
{
bestcost[i] = 1 << 30;
for (int j = 0; j < i; ++j)
{
int xx = bestcost[j] + C[i];
if (D[i]  D[j] <= range && xx < bestcost[i])
{
bestcost[i] = xx;
printf("(%d, %d)\n", i, bestcost[i]);
}
}
}
Input is:
3 8 4
2 1
4 2
6 3
Output is:
(1, 1)
(2, 2)
(3, 4)
So it corresponds to the cost to (i, cost(i))  to get at ith station, I have to pay cost(i).
How to find a minimal cost for whole distance with that information?





I found a way:
#include <vector>
#include <algorithm>
#include <deque>
#include <stdio.h>
typedef unsigned long long int ulli;
using namespace std;
void sliding_window_minimum(vector<pair<ulli, ulli>> st, ulli n, ulli targetDist, ulli range)
{
deque<pair<ulli, ulli>> minimize;
ulli j = 0;
for (ulli i = 0; i < n; i++)
{
if (st[i].first <= range)
{
while (!(minimize.empty()) && (minimize.back().second > st[i].second))
{
minimize.pop_back();
}
minimize.push_back(st[i]);
j++;
}
else
{
break;
}
}
for (ulli k = j; k < n; k++)
{
while (!(minimize.empty()) && ((st[k].first  minimize.front().first) > range))
{
minimize.pop_front();
}
if (minimize.empty()) {
break;
}
ulli tempCost = st[k].second + minimize.front().second;
while (!(minimize.empty()) && (minimize.back().second > tempCost))
{
minimize.pop_back();
}
minimize.push_back(make_pair(st[k].first, tempCost));
}
while (!(minimize.empty()) && ((targetDist  minimize.front().first) > range))
{
minimize.pop_front();
}
if (minimize.empty())
{
printf("NIE\n");
}
else
{
printf("%llu", minimize.front().second);
}
}
int main()
{
ulli n, d, b;
scanf("%llu %llu %llu", &n, &d, &b);
if (b >= d)
{
printf("%d", 0);
return 0;
}
int temp = n;
ulli d1, c1;
vector<pair<ulli, ulli>> st;
st.reserve(n+1);
while (temp)
{
scanf("%llu %llu", &d1, &c1);
st.push_back(make_pair(d1, c1));
}
sliding_window_minimum(st, n, d, b);
}






Hello!
So I have this algorithm that outputs the highest value of an array:
Input: A[1,..,n], n>=1
Output: Highest value of an array
Maximum (A)
1. m = A[1]
2. i = 1
3. while i < n
4. if A[i+1] > A[i]
5. m = A[i+1]
6. i = i+1
7. return m
I have to prove this algorithm wrong and I'm confused how to do that, because to me the algorithm seems correct. Any advice on how to do this are very much appreciated.
Thanks!





What's wrong is lines 4 and 5. When i is one less than n , then you try to dereference A[i+1] , which is the same as A[n] , you will receive an access violation because arrays are indexed beginning from zero, not from one.
The difficult we do right away...
...the impossible takes slightly longer.





I was going to ask if his array was "zerobased", but his "spec" threw me off:
Quote: Input: A[1,..,n], n>=1
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal





Oh I see what you mean. You thought that he was specifying that HIS arrays were onebased. I guess it could be interpreted that way.
The difficult we do right away...
...the impossible takes slightly longer.





But, if you take it that it is a 1 based array it will work, as demonstrated by the following bit of Python:
def maxi(A):
m = A[1]
i = 1
n = len(A)  1
while i < n:
if A[i+1] > A[i]:
m = A[i+1]
i += 1
return m
modified 16Apr18 5:15am.





The error is in the line
if A[i+1] > A[i] It must be
if A[i+1] > m



