Hints for SRM 499, D2, 500-pointer (InternetSecurity)

James S. Plank

Mon Mar 24 14:30:29 EDT 2014
Problem Statement.
This is a really nice problem to practice sets (and maps if you want) and stringstreams.

There are quite a few components to this problem, but let's outline a solution.

Then, your algorithm should be as follows:


Let's do an example -- example 0 works. First, we create our set of dangerous keywords:

{ "decryption" "encryption" "hack" "interference" "internet" "signal" }

We'll also use a set of dangerous web sites. That starts as empty. And finally, we'll create KV:

Now, we do pass one -- we start with i equals zero and we see that "hack", "encryption", "decryption", and "internet" are all dangerous. Since that is above the threshold, we add all of KV[0]'s words to the dangerous set, which now becomes:

{ "algorithm", "decryption" "encryption" "hack" "interference" "internet" "signal" }

We also add i=0 to the set of dangerous websites. The set is { 0 }.

When i=1 we see that there are three dangerous words in KV[1] ("signal", "interference" and "algorithm"), so we add all of KV[1] to the set of dangerous words, which is now:

{ "algorithm", "decryption" "encryption" "evil" "hack" "interference" "internet" "poison" "signal" "snake" }

The set of dangerous web sites is now { 0, 1 }.

We continue with i=2, and we see that there are no dangerous words in KV[2]. We are at the end of web sites, so we ask "Did we add to the number of dangerous words on this pass through the web sites?" The answer is yes, so we do it again.

Now, when i equals 0 and 1, we ignore the web sites because they are already dangerous. When i equals 2, we see again that no words in KV[2] are dangerous. We are done with the web site, and since we didn't add any new dangerous words, we can exit -- we run through the set of dangerous web sites and add their addresses to the return value: { "www.topcoder.com", "www.sindicate_of_evil.com" }.