forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfiniteSoup.html
More file actions
16 lines (16 loc) · 5.56 KB
/
Copy pathInfiniteSoup.html
File metadata and controls
16 lines (16 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>
Integer coordinates in a two-dimensional plane are assigned letters from a grid <b>g</b> as follows: point <tt>(x,y)</tt> is assigned <tt>g[y%R][x%C]</tt>, where <tt>R</tt> and <tt>C</tt> are the number of rows and columns in <b>g</b>, respectively. The grid <b>g</b> is given as a vector <string>, where each element is a single row, and <tt>g[i][j]</tt> is the jth character of the ith element (both 0-indexed).
</p>
<p>
Consider all rays that originate at <tt>(0,0)</tt> and move outward, crossing integer coordinates where both <tt>x</tt> and <tt>y</tt> are greater than or equal to zero.
Each ray spells out an infinite sequence of letters - the letters assigned to each coordinate crossed by the ray, in the order they are crossed.
</p>
<p>
You are given a list of words.
You must return the number of rays that contain each of the given words.
A ray contains a word if the word is a substring of the infinite letter sequence spelled out by the ray.
Only consider rays that intersect at least one integer coordinate <tt>(x,y)</tt> such that both <tt>0<=x<=<b>k</b></tt> and <tt>0<=y<=<b>k</b></tt>, where <b>k</b> is given as a parameter.
In the vector <int> returned, the ith position represents the number of the described rays that contains ith word given in <b>words</b>.
</p></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>InfiniteSoup</td></tr><tr><td>Method:</td><td>countRays</td></tr><tr><td>Parameters:</td><td>vector <string>, vector <string>, int</td></tr><tr><td>Returns:</td><td>vector <int></td></tr><tr><td>Method signature:</td><td>vector <int> countRays(vector <string> g, vector <string> words, int k)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td>    </td></tr><tr><td></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>g</b> will contain between 1 and 35 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>g</b> will contain between 1 and 35 lowercase (<tt>'a'-'z'</tt>) letters, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>All elements of <b>g</b> will contain the same number of characters.</td></tr><tr><td align="center" valign="top">-</td><td><b>words</b> will contain between 1 and 25 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>words</b> will have between 1 and 50 lowercase (<tt>'a'-'z'</tt>) letters, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>k</b> will be between 1 and 200, inclusive.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"abc","def","ghi"}</pre></td></tr><tr><td><pre>{"abc"}</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: {1 }</pre></td></tr><tr><td><table><tr><td colspan="2">With <b>k</b>=2, the only five possible possible rays spell <tt>"abcabc..."</tt>, <tt>"afhafh..."</tt>, <tt>"aeiaei..."</tt>, <tt>"ahfahf..."</tt> and <tt>"adgadg..."</tt>.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"abc","def","ghi"}</pre></td></tr><tr><td><pre>{"abc"}</pre></td></tr><tr><td><pre>3</pre></td></tr></table></td></tr><tr><td><pre>Returns: {2 }</pre></td></tr><tr><td></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"abc","def","ghi"}</pre></td></tr><tr><td><pre>{"abc"}</pre></td></tr><tr><td><pre>4</pre></td></tr></table></td></tr><tr><td><pre>Returns: {3 }</pre></td></tr><tr><td></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"ccbbc","baabc","ccbab","cbcaa","aacab"}</pre></td></tr><tr><td><pre>{"aaccbaaccbaacc","aabbcaabbcaabbc","babccbabccbabc","aaacaaaacaaaaca",
"abbcaabbcaab","ccbbcccbbcccbbc","bbacabbacab","caacccaacccaac",
"baaccbaaccbaac","caccbcaccbca"}</pre></td></tr><tr><td><pre>10</pre></td></tr></table></td></tr><tr><td><pre>Returns: {0, 2, 0, 0, 2, 7, 5, 6, 0, 5 }</pre></td></tr><tr><td></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"abb","bbb","bbb"}</pre></td></tr><tr><td><pre>{"aaa"}</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: {0 }</pre></td></tr><tr><td></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>