﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-I believe-随笔分类-粗心题</title><link>http://www.cppblog.com/luyulaile/category/11038.html</link><description>I  can</description><language>zh-cn</language><lastBuildDate>Fri, 31 Jul 2009 11:26:32 GMT</lastBuildDate><pubDate>Fri, 31 Jul 2009 11:26:32 GMT</pubDate><ttl>60</ttl><item><title>joj 1121 False coin</title><link>http://www.cppblog.com/luyulaile/archive/2009/07/25/91106.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 25 Jul 2009 02:17:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2009/07/25/91106.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/91106.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2009/07/25/91106.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/91106.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/91106.html</trackback:ping><description><![CDATA[<p>枚举法是最简单的方法，<br>虽然不是最快的。<br>从1到n一个一个假设它为1或者-1，其它为0，如果满足所有不等式计数器加1（如果第i个数为1时满足，则不必测试-1的情况。），如果最后计数器值不为1，不能推出，输出0.<br>给出下面的测试数据。<br>wa了5次，居然是因为数组范围没有注意到！囧囧囧。<br>下面是一些测试数据。<br>3 2<br>1 1 2<br>&lt;<br>1 2 3<br>&lt;<br>3 2<br>1 1 2<br>&gt;<br>1 1 3<br>&gt;<br>5 1<br>2 1 2 3 4<br>=<br>4 3<br>2 1 2 3 4<br>&lt;<br>2 1 3 2 4<br>&lt;<br>1 2 4<br>=<br>5 3<br>2 1 3 2 4<br>&gt;<br>2 3 5 2 4<br>&gt;<br>1 1 4<br>&gt;<br>5 3<br>2 1 3 2 4<br>&gt;<br>2 3 5 2 4<br>&gt;<br>1 1 4<br>=<br>3 2<br>1 1 2<br>&lt;<br>1 1 3<br>&lt;<br>2 1<br>1 1 2<br>&gt;<br>4 3<br>2 1 2 3 4<br>&lt;<br>2 1 3 2 4<br>&lt;<br>1 2 4<br>=<br>5 2<br>1 1 4<br>=<br>1 2 5<br>=<br>3 2<br>1 1 2<br>&lt;<br>1 2 3<br>&gt;<br>5 2<br>1 1 4<br>=<br>1 2 5<br>=<br>2 1<br>1 1 2<br>&gt;<br>5 3<br>2 1 3 2 4<br>&gt;<br>2 3 5 2 4<br>&gt;<br>1 1 4<br>&gt;<br>5 3<br>1 2 3<br>&lt;<br>1 1 2<br>&gt;<br>1 3 4<br>=<br>3 2<br>1 1 2<br>&lt;<br>1 1 3<br>&lt;<br>5 1<br>2 1 2 3 4<br>=<br>3 2<br>1 1 2<br>&lt;<br>1 2 3<br>&gt;<br>5 3<br>2 1 3 2 4<br>&gt;<br>2 3 5 2 4<br>&gt;<br>1 1 4<br>&gt;<br>5 3<br>1 2 3<br>&lt;<br>1 1 2<br>&gt;<br>1 3 4<br>=<br>2 1<br>1 1 2<br>&gt;<br>0&nbsp; 0<br>---<br>答案<br>Scenario #1:<br>0</p>
<p>Scenario #2:<br>1</p>
<p>Scenario #3:<br>5</p>
<p>Scenario #4:<br>1</p>
<p>Scenario #5:<br>4</p>
<p>Scenario #6:<br>0</p>
<p>Scenario #7:<br>1</p>
<p>Scenario #8:<br>0</p>
<p>Scenario #9:<br>1</p>
<p>Scenario #10:<br>3</p>
<p>Scenario #11:<br>2</p>
<p>Scenario #12:<br>3</p>
<p>Scenario #13:<br>0</p>
<p>Scenario #14:<br>4</p>
<p>Scenario #15:<br>2</p>
<p>Scenario #16:<br>1</p>
<p>Scenario #17:<br>5</p>
<p>Scenario #18:<br>2</p>
<p>Scenario #19:<br>4</p>
<p>Scenario #20:<br>2</p>
<p>Scenario #21:<br>0</p>
<p>&nbsp;</p>
<img src ="http://www.cppblog.com/luyulaile/aggbug/91106.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2009-07-25 10:17 <a href="http://www.cppblog.com/luyulaile/archive/2009/07/25/91106.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 1099 simple computer  推荐题</title><link>http://www.cppblog.com/luyulaile/archive/2009/07/24/91007.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Fri, 24 Jul 2009 02:59:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2009/07/24/91007.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/91007.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2009/07/24/91007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/91007.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/91007.html</trackback:ping><description><![CDATA[<table width="100%">
    <tbody>
        <tr>
            <td vAlign=top>You are to write an interpreter for a simple computer. This computer uses a processor with a small number of machine instructions. Furthermore, it is equipped with 32 byte of memory, one 8-bit accumulator (accu) and a 5-bit program counter (pc). The memory contains data as well as code, which is the usual von Neumann architecture.
            <p>The program counter holds the address of the instruction to be executed next. Each instruction has a length of 1 byte - the highest 3 bits define the type of instruction and the lowest 5 bits define an optional operand which is always a memory address (<tt>xxxxx</tt>). For instructions that don't need an operand the lowest 5 bits have no meaning (<tt>-----</tt>). Here is a list of the machine instructions and their semantics:
            <p><tt>000xxxxx &nbsp; STA x &nbsp; </tt>store the value of the accu into memory byte x<br><tt>001xxxxx &nbsp; LDA x &nbsp; </tt>load the value of memory byte x into the accu<br><tt>010xxxxx &nbsp; BEQ x &nbsp; </tt>if the value of the accu is 0 load the value x into the pc<br><tt>011----- &nbsp; NOP &nbsp; &nbsp; </tt>no operation<br><tt>100----- &nbsp; DEC &nbsp; &nbsp; </tt>subtract 1 from the accu<br><tt>101----- &nbsp; INC &nbsp; &nbsp; </tt>add 1 to the accu<br><tt>110xxxxx &nbsp; JMP x &nbsp; </tt>load the value x into the pc<br><tt>111----- &nbsp; HLT &nbsp; &nbsp; </tt>terminate program<br>
            <p>In the beginning, program counter and accumulator are set to 0. After fetching an instruction but before its execution, the program counter is incremented. You can assume that programs will terminate.
            <h3>Input Specification</h3>
            The input file contains several test cases. Each test case specifies the contents of the memory prior to execution of the program. Byte 0 through 31 are given on separate lines in binary representation. A byte is denoted by its highest-to-lowest bits. Input is terminated by EOF.
            <h3>Output Specification</h3>
            For each test case, output on a line the value of the accumulator on termination in binary representation, again highest bits first. </td>
            <td vAlign=top width="4%"></td>
            <td vAlign=top>
            <h3>Sample Input</h3>
            <pre>00111110
            10100000
            01010000
            11100000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00111111
            10000000
            00000010
            11000010
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            00000000
            11111111
            10001001
            </pre>
            <h3>Sample Output</h3>
            <pre>10000111</pre>
            </td>
        </tr>
    </tbody>
</table>
很好的题，很容易错。<br>需要计算机组成原理的一点知识，没学过也能做。<br>指令译码，（将二进制转化为十进制并从中获得操作类型和立即数x）可以用位运算，<br>指令执行 pc,accu,立即数x都可以用int表示且是全局变量，memory用数组表示。<br>有很多注意的地方，<br>pc不能超过32;不能小于0.<br>accu不能超过256.不能小于0.<br>自己都没有注意到。<br>pc,accu,
<img src ="http://www.cppblog.com/luyulaile/aggbug/91007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2009-07-24 10:59 <a href="http://www.cppblog.com/luyulaile/archive/2009/07/24/91007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>joj 2199 the lost number  好题  值得做做</title><link>http://www.cppblog.com/luyulaile/archive/2009/07/19/90519.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sun, 19 Jul 2009 06:18:00 GMT</pubDate><guid>http://www.cppblog.com/luyulaile/archive/2009/07/19/90519.html</guid><wfw:comment>http://www.cppblog.com/luyulaile/comments/90519.html</wfw:comment><comments>http://www.cppblog.com/luyulaile/archive/2009/07/19/90519.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/luyulaile/comments/commentRss/90519.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/luyulaile/services/trackbacks/90519.html</trackback:ping><description><![CDATA[<table cellSpacing=3 cellPadding=3 width="75%" border=1>
    <colgroup span=7>
    <tbody>
        <tr>
            <th height=40>Status</th>
            <th>In/Out</th>
            <th>TIME Limit</th>
            <th>MEMORY Limit</th>
            <th>Submit Times</th>
            <th>Solved Users</th>
            <th>JUDGE TYPE</th>
        </tr>
        <tr>
            <td style="FONT-SIZE: 10pt" align=middle height=40><img height=20 src="http://acm.jlu.edu.cn/joj/images/ok1.gif" width=20></td>
            <td style="FONT-SIZE: 10pt">stdin/stdout</td>
            <td style="FONT-SIZE: 10pt">3s</td>
            <td style="FONT-SIZE: 10pt">40960K</td>
            <td style="FONT-SIZE: 10pt">1071</td>
            <td style="FONT-SIZE: 10pt">235</td>
            <td style="FONT-SIZE: 10pt">Standard</td>
        </tr>
    </tbody>
</table>
<div style="FONT-SIZE: 10pt">In a interger sequence S there are N(N &lt; 1000000) intergers, there is a initial number I(-2^31 &lt; I &lt;2^31), which is the minimun interger in S, and no two integers are the same. Now can you find the first lost interger L make the sequence is not consecutive. For example, S = { 1, -2, 2, 9, -1 }, then I = -2, and L = 0.
<h3>Input</h3>
For each case N is in the first line, and next N lines is the sequence S.
<h3>Output</h3>
Output L for each case in a single line.
<h3>Sample Input</h3>
<pre>5
1
-2
2
9
-1
</pre>
<h3>Sample Output</h3>
<pre>0</pre>
<pre>不用走入排序的误区，</pre>
<pre>可以在线性的时间内完成。</pre>
<pre>先一趟循环，保存输入的值n[MAX],同时可找出最小的值，</pre>
<pre>再来一趟循环以此为基准对每个数进行标记，对每个出现的num,mark[num-min]=1;</pre>
<pre>然后</pre>
<pre>for(int i=0;;i++)</pre>
<pre>{if(mark[i]==0)</pre>
<pre>cout&lt;&lt;i+min;</pre>
<pre>break;</pre>
<pre>}
----</pre>
</div>
<img src ="http://www.cppblog.com/luyulaile/aggbug/90519.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/luyulaile/" target="_blank">luis</a> 2009-07-19 14:18 <a href="http://www.cppblog.com/luyulaile/archive/2009/07/19/90519.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>