Files
PAT/source/html/a1148.html
T

50 lines
11 KiB
HTML

Werewolf - Simple Version
<div class="ques-view"><p>Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,</p>
<ul>
<li>player #1 said: "Player #2 is a werewolf.";</li>
<li>player #2 said: "Player #3 is a human.";</li>
<li>player #3 said: "Player #4 is a werewolf.";</li>
<li>player #4 said: "Player #5 is a human."; and</li>
<li>player #5 said: "Player #4 is a human.".</li>
</ul>
<p>Given that there were 2 werewolves among them, at least one but not all the werewolves were lying, and there were exactly 2 liars. Can you point out the werewolves?</p>
<p>Now you are asked to solve a harder version of this problem: given that there were <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> players, with 2 werewolves among them, at least one but not all the werewolves were lying, and there were exactly 2 liars. You are supposed to point out the werewolves.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. For each case, the first line gives a positive integer <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> (<span class="katex"><span class="katex-mathml"><math><mrow><mn>5</mn><mo>≤</mo><mi>N</mi><mo>≤</mo><mn>1</mn><mn>0</mn><mn>0</mn></mrow>5 \le N \le 100</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.8193em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">5</span><span class="mrel">≤</span><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="mrel">≤</span><span class="mord mathrm">1</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span></span></span></span>). Then <span class="katex"><span class="katex-mathml"><math><mrow><mi>N</mi></mrow>N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span> lines follow and the <span class="katex"><span class="katex-mathml"><math><mrow><mi>i</mi></mrow>i</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.65952em;"></span><span class="strut bottom" style="height:0.65952em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span></span></span></span>-th line gives the statement of the <span class="katex"><span class="katex-mathml"><math><mrow><mi>i</mi></mrow>i</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.65952em;"></span><span class="strut bottom" style="height:0.65952em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span></span></span></span>-th player (<span class="katex"><span class="katex-mathml"><math><mrow><mn>1</mn><mo>≤</mo><mi>i</mi><mo>≤</mo><mi>N</mi></mrow>1 \le i \le N</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.8193em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span><span class="mrel">≤</span><span class="mord mathit">i</span><span class="mrel">≤</span><span class="mord mathit" style="margin-right:0.10903em;">N</span></span></span></span>), which is represented by the index of the player with a positive sign for a human and a negative sign for a werewolf.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>If a solution exists, print in a line in ascending order the indices of the two werewolves. The numbers must be separated by exactly one space with no extra spaces at the beginning or the end of the line. If there are more than one solution, you must output the smallest solution sequence -- that is, for two sequences <span class="katex"><span class="katex-mathml"><math><mrow><mi>A</mi><mo>=</mo><mrow><mi>a</mi><mo>[</mo><mn>1</mn><mo>]</mo><mo separator="true">,</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo separator="true">,</mo><mi>a</mi><mo>[</mo><mi>M</mi><mo>]</mo></mrow></mrow>A = { a[1], ..., a[M] }</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">A</span><span class="mrel">=</span><span class="mord textstyle uncramped"><span class="mord mathit">a</span><span class="mopen">[</span><span class="mord mathrm">1</span><span class="mclose">]</span><span class="mpunct">,</span><span class="mord mathrm">.</span><span class="mord mathrm">.</span><span class="mord mathrm">.</span><span class="mpunct">,</span><span class="mord mathit">a</span><span class="mopen">[</span><span class="mord mathit" style="margin-right:0.10903em;">M</span><span class="mclose">]</span></span></span></span></span> and <span class="katex"><span class="katex-mathml"><math><mrow><mi>B</mi><mo>=</mo><mrow><mi>b</mi><mo>[</mo><mn>1</mn><mo>]</mo><mo separator="true">,</mo><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mi mathvariant="normal">.</mi><mo separator="true">,</mo><mi>b</mi><mo>[</mo><mi>M</mi><mo>]</mo></mrow></mrow>B = { b[1], ..., b[M] }</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.05017em;">B</span><span class="mrel">=</span><span class="mord textstyle uncramped"><span class="mord mathit">b</span><span class="mopen">[</span><span class="mord mathrm">1</span><span class="mclose">]</span><span class="mpunct">,</span><span class="mord mathrm">.</span><span class="mord mathrm">.</span><span class="mord mathrm">.</span><span class="mpunct">,</span><span class="mord mathit">b</span><span class="mopen">[</span><span class="mord mathit" style="margin-right:0.10903em;">M</span><span class="mclose">]</span></span></span></span></span>, if there exists <span class="katex"><span class="katex-mathml"><math><mrow><mn>0</mn><mo>≤</mo><mi>k</mi><mo>&lt;</mo><mi>M</mi></mrow>0 \le k &lt; M</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.83041em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mrel">≤</span><span class="mord mathit" style="margin-right:0.03148em;">k</span><span class="mrel">&lt;</span><span class="mord mathit" style="margin-right:0.10903em;">M</span></span></span></span> such that <span class="katex"><span class="katex-mathml"><math><mrow><mi>a</mi><mo>[</mo><mi>i</mi><mo>]</mo><mo>=</mo><mi>b</mi><mo>[</mo><mi>i</mi><mo>]</mo></mrow>a[i]=b[i]</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">a</span><span class="mopen">[</span><span class="mord mathit">i</span><span class="mclose">]</span><span class="mrel">=</span><span class="mord mathit">b</span><span class="mopen">[</span><span class="mord mathit">i</span><span class="mclose">]</span></span></span></span> (<span class="katex"><span class="katex-mathml"><math><mrow><mi>i</mi><mo>≤</mo><mi>k</mi></mrow>i \le k</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.83041em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mord mathit">i</span><span class="mrel">≤</span><span class="mord mathit" style="margin-right:0.03148em;">k</span></span></span></span>) and <span class="katex"><span class="katex-mathml"><math><mrow><mi>a</mi><mo>[</mo><mi>k</mi><mo>+</mo><mn>1</mn><mo>]</mo><mo>&lt;</mo><mi>b</mi><mo>[</mo><mi>k</mi><mo>+</mo><mn>1</mn><mo>]</mo></mrow>a[k+1]&lt;b[k+1]</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">a</span><span class="mopen">[</span><span class="mord mathit" style="margin-right:0.03148em;">k</span><span class="mbin">+</span><span class="mord mathrm">1</span><span class="mclose">]</span><span class="mrel">&lt;</span><span class="mord mathit">b</span><span class="mopen">[</span><span class="mord mathit" style="margin-right:0.03148em;">k</span><span class="mbin">+</span><span class="mord mathrm">1</span><span class="mclose">]</span></span></span></span>, then <span class="katex"><span class="katex-mathml"><math><mrow><mi>A</mi></mrow>A</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">A</span></span></span></span> is said to be smaller than <span class="katex"><span class="katex-mathml"><math><mrow><mi>B</mi></mrow>B</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.05017em;">B</span></span></span></span>. In case there is no solution, simply print <code>No Solution</code>.</p>
<h3 id="sample-input-1-">Sample Input 1:</h3>
<pre><code class="lang-in">5
-2
+3
-4
+5
+4
</code></pre>
<h3 id="sample-output-1-">Sample Output 1:</h3>
<pre><code class="lang-out">1 4
</code></pre>
<h3 id="sample-input-2-">Sample Input 2:</h3>
<pre><code class="lang-in">6
+6
+3
+1
-5
-2
+4
</code></pre>
<h3 id="sample-output-2-the-solution-is-not-unique-">Sample Output 2 (the solution is not unique):</h3>
<pre><code class="lang-out">1 5
</code></pre>
<h3 id="sample-input-3-">Sample Input 3:</h3>
<pre><code class="lang-in">5
-2
-3
-4
-5
-1
</code></pre>
<h3 id="sample-output-3-">Sample Output 3:</h3>
<pre><code class="lang-out">No Solution
</code></pre>
</div>