Greenmoon55's Blog
2019-09-08T19:45:16+00:00
http://greenmooon55.com
greenmoon55
湾区体验
2019-09-08T00:00:00+00:00
http://greenmooon55.com/bay-area
<p>已经搬来湾区快一个月了,趁新鲜劲还没过写一下感受。</p>
<h1 id="衣食住行">衣食住行</h1>
<p>湾区的天气真的好,夏天每天都是晴天,二十来度不冷不热。中餐还是很全的,鲤鱼门早茶甚至比纽约的好吃,不过哪里都要排队,比纽约还可怕。。整个湾区感觉就像是一座座小镇连在一起,在 Buiding 20 或者在去 Fremont 的84号桥上看周围荒芜人烟的样子,和公司的高大上的楼形成了鲜明的对比,总觉得很奇幻。</p>
<p>暂时住在 Foster city,公司提供的房子真的很不错,或许是人生第一次一个人住这么久,挺舒服的。Foster city 是个安静的小城,周围步行就有快乐柠檬、火锅、大华、safeway,还有一个超级美的湖。虽然告别了半夜十二点下楼遛弯儿的纽约生活,这里天没黑的时候出门走走还是很安全的。在 Google 和知乎搜 Foster city,最靠前的结果都是我司员工写的。。那我就把这两个链接放在这里吧。</p>
<p><a href="https://leonson.me/2018/12/foster-city-intro">https://leonson.me/2018/12/foster-city-intro</a></p>
<p><a href="https://zhuanlan.zhihu.com/p/34935531">https://zhuanlan.zhihu.com/p/34935531</a></p>
<p>湾区出行还是很方便的,跟很多其他美国城市一样,高速非常发达,出门很快就能上高速,几乎去哪儿都在半小时以内。唯一的问题是堵车比较严重,刚好去公司这一段路完全没有HOV lane,班车只好堵着,还要停很多站。。每天两小时在路上比较影响生活质量。。纽约地铁确实方便但是很脏,站里也没有空调,各有各的好。</p>
<h1 id="上班感受">上班感受</h1>
<h2 id="交通">交通</h2>
<p>嘿嘿首先还要从交通说起,来了之后才意识到公司有多大,园区内部班车有好几个线路,甚至还有express。接员工上下班的shuttle高峰期几乎不会断,可能有二三十个线路,每个线路有很多班次。园区还有免费的自行车可以骑,前天试着骑了最远的一次,将近20分钟,风很大再也不这么折腾了。。太远的楼还是坐车好。</p>
<h2 id="吃">吃</h2>
<p>用地里的话说,free food, is ok,我不太在乎吃已经知足了。工作日几乎不用花钱,这周工作日除了打uber一分钱都没有花。。这样对我来说,可能比在纽约更省钱,这个月花钱最多的商户肯定是海底捞和uber。</p>
<h2 id="orientation--内部工具">Orientation & 内部工具</h2>
<p>非常强调价值观,还会做奇怪的游戏。。让我想到了阿里。。内部用的work chat竟然是可以看到已读状态和在线状态的,很像钉钉有没有。入职之前我最担心的是outlook难用,现在感觉网页版也可以接受。<a href="https://www.facebook.com/workplace">workspace</a><a href="https://www.youtube.com/watch?v=_aXbD6ysQG0">不按时间排序</a>可能有点乱,但是更容易找之前的对话。上面有很多有趣的组,比如introverts(终于找到同类了),刷内网有点刷reddit的感觉hhhh。</p>
<h2 id="culture">Culture</h2>
<p>对于新人来说,这里像一个startup。非常强调move fast和impact,之前工程上可能要求不高,比如代码很少有文档和注释,code review可能抠的不太细。。虽然听起来不怎么样,但是可能对公司快速迭代是好事,可能要看组里怎么平衡质量和速度了。。这会让员工去想,我做某件事情对公司有什么意义?我真的要refactor这个东西嘛?</p>
<p>想来去年实习跟组里的senior聊,他说大公司可能更规范,我说不一定吧。然后他举个例子说,你看我们的文档可能在github上,也可能在confluence上,也可能在google docs上多乱啊。然而现在我司更乱。。wiki, google docs, dropbox, quip, ms哪都有。。</p>
<p>去年实习的时候就觉得大家都(至少表面上)很nice,这里也是一样,如果有问题一般都是热心解答。可能是美国不太看层级。</p>
<p>open确实是open呀,跟以前实习一样,可以看到别的组的架构、roadmap啥的。</p>
<p>work life balance听说不是很好,似乎确实是这样,我现在已经不敢看同事交代码的heatmap了。好玩/wlb/manager靠谱构成了一个不可能三角形,准确的说可能好玩又轻松的组就很少了。</p>
<h2 id="开发环境">开发环境</h2>
<p>入职第二天大家做第一个教程,所有人都遇到了bug…我来说一些好的地方。</p>
<h3 id="monorepo">Monorepo</h3>
<p>以前只听说<a href="https://cacm.acm.org/magazines/2016/7/204032-why-google-stores-billions-of-lines-of-code-in-a-single-repository/fulltext">Google只有一个repo</a>,FB也差不多,这么搞其实有很多好处,比如内部依赖不需要版本控制,搜代码非常容易,缺点就是需要team管版本控制,dev机器都需要很强的配置,才能pull那么多代码。</p>
<h3 id="task">Task</h3>
<p>可能大家都很讨厌jira,内部task管理就是一个很简单的工具,用起来很爽</p>
<h3 id="nuclide">Nuclide</h3>
<p>这个基于atom的IDE还是很方便的,比如可以一键申请开发机,搜内部代码,甚至可以直接在IDE里inline看别人的comments。</p>
<h3 id="infra">Infra</h3>
<p>如果写backend,除了Hack和数据库跟其他公司区别比较大,其他似乎差不多?可能还是aws这种地方更接近业界常用的框架吧。</p>
<h3 id="ml">ML</h3>
<p>Train model可能不需要写代码,只要点点点就可以了。。真是方便。</p>
<h2 id="bootcamp">Bootcamp</h2>
<p>美国很多公司都是标准化面试不分组,特别是我司,newgrad几乎都是不分组的。Bootcamp前两三周大家一起写一些小task,后面几周就去跟几个组一起做点task,然后只要你说去某个组,并且那个组还有hc就可以去,先到先得,组里都是欢迎你去体验的,manager也愿意花时间跟每个bootcamper聊(这边manager跟tech lead往往是两个人),并不会给你面试的感觉。比如你以前没写过前端,没有做过ml,可能仍然有机会去这些组。如果实在不match你自然也不会去,去了搞不定就没有好的rating了。。这其实有点像pair programming面试。这么搞其实很有趣,可以让你深刻体验某个组是不是适合你,缺点就是万一没有跟你兴趣匹配的组就完蛋了。这还需要这么大的公司尽量保证所有面试的问题和标准是一样的。</p>
<p>以前以为只有newgrad才这样,进来之后发现甚至有工作7年这种资深的人也是没分组进来自己选,当然也有preallocated hire,他们在bootcamp待的时间就短一点。有的组大家都觉的不好玩,就跟本招不到人。。当manager也不容易呵呵。</p>
<p>bootcamp其实并没有想象的那么轻松,真的非常刺激,要上课要了解组要做task,毕竟你的未来掌握在自己手里。回到刚刚说的culture,比如第二周就自己选task做,有问题自己去找task的联系人,这个人可能放假,可能在另一个州,并不是你旁边有一个人手把手教你,task描述也可能有问题,全靠自己去问。也不敢去真的学完全不熟悉的领域,我是不敢接Haskell的task…</p>
<p>听起来还不错?然而如果你想做cloud/backend啥的,合适的组真的不多,可能内部infra确实不像aws那么复杂需要很多人吧。现在聊的组都比较奇怪,每天都在想:我要做ml嘛?我要做风控嘛?虽然肯定不想做fullstack,我要写php还是c++呢?要体验新东西嘛还是求稳?我要忙一点还是轻松一点?这个老板到底好不好?显然跳槽的时候公司的名字不会有多少加成,所以压力山大,相信自己,走着看吧。</p>
<p>Bootcamp很多课其实都没必要现场听,回家看视频感受一下就可以了。有些课讲得确实挺好的,也有些比较浪费时间。</p>
<h2 id="国人">国人</h2>
<p>完全没想到我司也这么多中国人,可能每周说英语不超过两小时。。有时候在办公区走着走着就觉得像回国了。</p>
<p>很幸运同时入职有几个小伙伴可以多交流。</p>
2018Spring
2018-05-26T00:00:00+00:00
http://greenmooon55.com/2018-spring
<p>忍了一学期没有吐槽,今天刚好小长假无聊,并且成绩刚刚出来,终于可以写一篇流水帐了。</p>
<p>这学期没有找工压力,本来以为会很闲,结果过得还是挺忙的,大部分时间还是在写作业,选的三门课是AI+HPC for ML + 1003 ML。这学期的选课思路非常简单,为了保留上ml后续课程的可能性,所以一定要选ml,结果现在发现后面应该不会上ml相关的了…这门课确实不错,但是剩下两门比较一般,好吧,现在开启吐槽模式。</p>
<h3 id="课程">课程</h3>
<p>AI: 30-40人 workload: 1天/周</p>
<p>老师是大佬,教材AIMA他也写了一些内容,但是讲课水平确实一般。抄袭一句经典的话,如果你懂了,那么不用上他的课,如果你不懂,也很难听懂。有次我问旁边的美国人,结果他也没懂… 这门课内容其实还可以,对ai整体介绍了一下,虽然学的东西没有什么用。AIMA也不错,你会发现以前自以为是写搜索的小聪明(例如Bidirectional Search)人家早就研究过。但是讲得太浅了…其实这门课我觉得最有趣的地方是写sat solver,虽然只是个dfs。本科就听说cs的同学在写prolog神马的,现在终于知道他们在干嘛了…这门课不好的地方就是很多作业是做cs同学最讨厌做的事情(我可以这么说吗?),也就是明明可以写代码做的东西非要手算,programming assignment也跟好学校的ai课有很大差距,要是能写个游戏多好(例如stanford cs221)。我就不用说作业成绩一个月之后才出来了,反正大家基本都是满分只看final,final一道选择占总成绩2.5%…</p>
<p>总之跟top学校的ai课相比差距巨大,刚好适合我来水一水。。不然的话完全没必要选这门课,看看berkley的cs 188x或者台大的coursera的ai就行了。rmp教授低分是有原因的…最影响心情的一门课。</p>
<p>HPC for ML: 20-30人 workload: 1天/周</p>
<p>选这课的原因是没敢选compiler,这个看起来有点水所以就选了,不过体验也很一般,很多人都有点后悔选了这门…基本上就是把每个领域的入门教程抄过来放在slide里,三个lab写写pytorch, cuda和mpi,还是学到了一些东西,只是完全可以自学。我还记得春假那会儿一个人在图书馆搞了五天lab1,完全就是浪费生命…然后第一次去piazza求情extend ddl。lab设计一般,说明很不清楚,他自己都没有写过,有次给的checksum还是错的… final考试非常奇怪,有种文科课的感觉…很多东西我觉得他上课没有认真讲就考了,公式也是只告诉你怎么算,并没有说原理,虽然原理其实两分钟就能讲完。</p>
<p>这门课内容还是很好的,虽然讲得浅但提供了一个roadmap…现在ml这么火,很多公司是想要懂算法也懂systems的人的,例如<a href="https://zhuanlan.zhihu.com/p/37195631">阿里</a>,还有这个:<a href="https://www.zhihu.com/question/56676679/answer/151505274">机器学习相关岗位面试中,有哪些加(zhuang)分(bi)项?</a> , uw也开始搞<a href="http://saml.cs.washington.edu">saml group</a>了。其实适合ds的同学选。</p>
<p>这门课也是目前遇到大神最多的一门,太可怕了只能给人家当分母…相关课程的话,当然要提cmu的15-418,视频是公开的,还有uw的systems for ml,陈天奇开的课哦(<a href="https://weibo.com/2397265244/GexRAwOHk">微博</a>)。</p>
<p>ML: 160人 workload: 3天/周</p>
<p>这门课选得相当不容易,因为只给cs30个名额,所以等到开学第一周才选到。rmp满分的课,ds最好的课之一。这门课只是第一周会觉得难一些,后面没有想象的那么难,但是作业不少,作业、考试以及notes都是精心准备的,没有太多数学,是理论和实践的完美结合,是非常值得选的一门课。学了这门课我就敢说入门ml了,也有信心去自学相关内容了。Project给大家一个跟大佬交流的机会,但是非常可惜我们并没有怎么交流。首先是被队友坑,所以只能四个人组队,搞成了我这学期压力最大的事情,还好我们有大佬。我们dataset选的比较奇怪,我们四个都不想做所以拖到了最后几天别人都搞定的时候才搞。刚好那天hpc gateway升了openssh搞的我没法登进去…整个人都抑郁了…现在会想起来如果选一个经常交流的advisor会更好,并且完全可以两人组队,甚至还有一个人做的…这样会舒服很多。ml project做完让我再也不想搞data science了,感觉ds只是把code当做工具,得到某些结果,而我希望code是个可以持续改进的“产品”。</p>
<p>我总觉得这门课从2015到现在慢慢变简单了,虽然对我来说还是不容易,不知道是不是错觉。</p>
<p>其实final之前又发现一堆问题,比如上学期觉得平时没有好好复习,这学期下课之后都会回头看一眼,但是final前几天才发现很多东西其实没学会,所以及时整理非常重要,希望以后每周都能花一两个小时来整理一下,尽量少开新坑多复习…就像<a href="https://github.com/davidrosenberg/mlcourse/blob/gh-pages/course-faq.md">david的建议</a>。</p>
<blockquote>
<p>I think you’ll be surprised how much easier it is to remember something once you’ve fully mastered it. In any case, once you master something, I always recommend that you write a note to your future self, explaining the concept. This should be something you can read in 6-12 months (or years, eventually) when you need that mastery, but you’ve forgotten the details. You’ll have trouble writing the note if you don’t fully understand the material, so it’s also a good self test. I have 100s pages of these types of notes, and I’ve found them immensely useful over the years.</p>
</blockquote>
<p>还有一个尴尬的事情是做完以前的final,同样的问题我竟然又错了…还是印象不深刻,以后错题要再做一遍…如果有空的话orz。</p>
<h3 id="nyu">NYU</h3>
<p>去年总觉得这边cs哪里不对但又说不出来,一是去年以为没有多少colloquium,这学期倒是发现了很多…我去了10个左右,nlp, pl, os啥都有,就是听不懂只能蹭吃噌喝…回头又没时间(不想)看paper… 听完感觉各位phd/postdoc/prof都很会讲,每个人讲得都很有条理。第二点是没有cs氛围…就像看到reddit<a href="https://www.reddit.com/r/nyu/comments/7zba30/the_cs_scene_at_nyu_cas/">这一条</a>。</p>
<blockquote>
<p>Personally I’ve found a lot of the students to be intelligent, hard working people, but what I call “tech enthusiasts”. They like the idea of programming, they may even go to clubs like tech@nyu or BUGS (open source club), but they don’t spend the time to actually program. </p>
</blockquote>
<p>不像某学校”空气中弥漫着代码的味道”。我觉得有很多原因吧,比如</p>
<p>1.大家都不住在一起,不会像本科时候一起去学院俱乐部写代码什么的</p>
<p>2.课程作业就很多了,谁有空自己写代码玩</p>
<p>3.很多人学cs是为了会一些技术,把cs当作工具来完成自己的目的。(no offense)</p>
<h3 id="实习">实习</h3>
<p>刚好两年没有工作了,感觉上学相当于花钱度假…确实对工作没有太大帮助但是很有趣,之前看到知乎帖子有美本申到了mcds问是去读书还是去azure工作,大家都说如果不转行就应该直接工作,读书的时间成本还是挺高的。</p>
<p>到现在刚刚实习一周,没有太特别的感觉,第一天有点紧张很快就好了,同事都很professional,不像以前在创业公司大家天天闲聊。我五年前竟然还写过<a href="https://greenmoon55.com/intern-at-dianping/">实习感受1</a>和<a href="https://greenmoon55.com/intern-at-ctrip/">实习感受2</a>…这边实习感觉真心不错,办公环境好,开放,不加班,用我喜欢的技术还有很多挑战,代码质量虽然不够完美但是很不错了。除了没有免费的饭其他都很完美的样子,至少比之前去过的team都好…但是不知道为什么我不是很excited,可能是跟以前的技术栈比较像,所以我有一种第500天上班的感觉,并没有刚上班的新鲜感。如果去做点其他的东西会不会更有趣呢?比如cuda, ml, nlp, blockchain?可能学会之后也觉得无聊了…这要怎么办…我甚至都不知道自己为什么不是特别感兴趣…难道是刚放假没休息好?反正我不会觉得不喜欢…所以似乎还好?</p>
2017总结
2018-01-22T00:00:00+00:00
http://greenmooon55.com/2017-year-in-review
<p>2017年初在看Casey Neistat的Vlog和C君纽约旅行视频的我完全想不到自己真的会来纽约(当初觉得会去加州吧,没觉得NYU会要我),到现在半年过去,每天还会想自己是有多幸运能来到纽约。来到这边啥culture shock都没有,除了语言跟国内没啥区别,逛街啥的甚至比国内还方便,城里人也少一些比较舒服,气候跟国内也差不多,同学很多中餐馆也很多。我心里最喜欢的城市就是纽约和上海了,现在都不想去湾区了。。</p>
<p>终于彻底变成学生了,工作过才能体会上学有多幸福。只要能赚回来学费,这波不亏。这学期上了算法、OS、PL和概率统计,Siegel的算法课的作业题很有趣,用同学的话说,”He really makes you think”,可以说是我上过最好的一门算法课,还是学到了一些新东西。OS主要对内存管理认识更深刻了,还简单介绍了很多Linux的具体实现的,学完之后很想再找本Kernel的书看看,或者说给了我再去自学的信心(估计不会看的。。),不过这门课还是undergraduate level的,作为cs的graduate student应该学得更深一点,学深了写写代码反而比学概念容易理解,这也可能是为什么大家都想去CMU吧。概率统计补补数学,上学期花了这么多时间还是很值的,不过时间分配很失败,总是没时间预习,上课跟不上,课后花很多时间自学,写作业总是很痛苦。总的来说,没想到这半年学生生活让我更喜欢CS了,算是这学期的最大收获吧。</p>
<p>写作业找实习一学期过去感觉甚至比上班还要忙,过着图书馆和家两点一线的生活。。实习也不好找,当初想着面面FLAG,最后去个中型公司,实际上这边面试非常难拿。我是投了四五十家,最后面试不到5个。最开始收到简历拒就很伤心,最后接到拒信都心怀感激。如果早知道实习这么难找我可能就不选概率统计了,会把重心放在找工作上。还好有惊无险,很幸运接了个小公司offer。发offer之后还组织参观公司问各种问题,体验还不错。感觉中美找工作也越来越趋同了,美国除了面算法也越来越看中项目,国内也越来越重视算法吧。</p>
<p>其实好多次感觉心态都要崩了,比如被fb, amazon简历拒,比如感恩节一个人在家花了好久debug OS lab,比如十一月中旬以为面挂了没有offer,比如考试一边写一边想会不会挂科不能去实习。。</p>
<p>2017年也是我第一次出国,四月底去了日本,风景倒没有特别的,倒是亲眼见识了一分钟间隔的铁路、拿出钢笔画地图热心指路的小哥、胡同里汽车停下来耐心等救护车、博物馆对战争的美化。去了一次印象深刻,希望以后还能去玩~</p>
<p><img src="/images/2017-newport.jpg" alt="Newport" /></p>
<p align="center">Newport</p>
<p><img src="/images/2017-wsq.jpg" alt="WSQ" /></p>
<p align="center">Washington Square Park</p>
<p><img src="/images/2017-bobst.jpg" alt="Bobst" /></p>
<p align="center">最喜欢的图书馆四楼</p>
<p>2018没有什么特别的想法,学喜欢的课,出去多玩玩,好好管理时间,希望一切顺利。</p>
LeetCode 44 Wildcard Matching
2017-06-09T00:00:00+00:00
http://greenmooon55.com/leetcode-44-wildcard-matching
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">Solution</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">isMatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
<span class="s">"""
:type s: str
:type p: str
:rtype: bool
"""</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="n">p</span><span class="p">:</span>
<span class="k">if</span> <span class="n">ch</span> <span class="o">!=</span> <span class="s">'*'</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">False</span>
<span class="k">return</span> <span class="bp">True</span>
<span class="n">f</span> <span class="o">=</span> <span class="p">[[</span><span class="bp">False</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">)]</span>
<span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="k">if</span> <span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="ow">or</span> <span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">'?'</span><span class="p">:</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">'*'</span><span class="p">:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="k">if</span> <span class="n">f</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">break</span>
<span class="c">#print f</span>
<span class="k">return</span> <span class="n">f</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)][</span><span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="p">)]</span>
</code></pre></div></div>
<p>第一个思路是<code class="highlighter-rouge">f[i][j]</code>表示<code class="highlighter-rouge">s[i]</code>匹配到<code class="highlighter-rouge">p[j]</code>能否实现,两重循环计算,遇到*还要再加一层循环来确定p前一位匹配到了哪里。提交之后TLE。</p>
<p>可以发现有两个可以优化的地方,第一个是<code class="highlighter-rouge">f[i][j]</code>第二维只需要j-1,因此可以降成一维数组。第二个是当p[j]是*时,任意<code class="highlighter-rouge">f[k][j]</code>(k<=i)为True都可以,不需要每个i都向前搜索一遍,而应该遇到<code class="highlighter-rouge">f[k][j]</code>反过来填后面的<code class="highlighter-rouge">f[i][j]</code>(i>=k)。</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">Solution</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">isMatch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
<span class="s">"""
:type s: str
:type p: str
:rtype: bool
"""</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="n">p</span><span class="p">:</span>
<span class="k">if</span> <span class="n">ch</span> <span class="o">!=</span> <span class="s">'*'</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">False</span>
<span class="k">return</span> <span class="bp">True</span>
<span class="n">f</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="n">p</span><span class="p">:</span>
<span class="k">if</span> <span class="n">ch</span> <span class="o">!=</span> <span class="s">'*'</span><span class="p">:</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">):</span>
<span class="k">if</span> <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">ch</span> <span class="ow">or</span> <span class="n">ch</span> <span class="o">==</span> <span class="s">'?'</span><span class="p">:</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">f</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">break</span>
<span class="k">return</span> <span class="n">f</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)]</span>
</code></pre></div></div>
<p>此时f[i]表示截止到当前ch,能否匹配到第i位。</p>
Codeforces Round #418 (Div. 2)
2017-06-08T00:00:00+00:00
http://greenmooon55.com/codeforces-round-418-div-2
<p>又是发挥很差的一场,只过了A..</p>
<h1 id="a-an-abandoned-sentiment-from-past">A. An abandoned sentiment from past</h1>
<p>逆序填入数字再判断是否还是递增的序列</p>
<h1 id="b-an-express-train-to-reveries">B. An express train to reveries</h1>
<p>这道题看了样例想了想就写了个算法,居然还过了pretest,最后WA了。说明要认真想算法的正确性。。</p>
<p>分两种情况讨论:</p>
<ol>
<li>a, b只有一个数字不同,那么说明a[i]和b[i]都不可能是要找的数字,找一找剩下n-1个数中未出现的数字即可。</li>
<li>a, b在第i位和第j位不同</li>
</ol>
<p>如果是</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>1 2 3 4 3
1 2 5 4 5
</code></pre></div></div>
<p>那么i位和j位选哪个都无所谓。</p>
<p>如果是</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>5 4 5 3 1
4 4 2 3 1
</code></pre></div></div>
<p>就要先去掉出现两次的数,例如上面第3位先选b,因为2只出现了一次,接下来第一位选5,因为a中第三位的5已经被替换成2了,5在a中只出现1次。</p>
<p>再举个例子</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>5 4 3 5 2
5 4 1 1 2
</code></pre></div></div>
<p>答案是:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>5 4 3 1 2
</code></pre></div></div>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">defaultdict</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">input</span><span class="p">())</span>
<span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">input</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
<span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">input</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">a_used</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
<span class="n">b_used</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">)):</span>
<span class="n">a_used</span><span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">b_used</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">!=</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">x_done</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="n">x_done</span> <span class="o"><</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)):</span>
<span class="k">if</span> <span class="n">a_used</span><span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]]</span> <span class="o">></span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">b_used</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">x_done</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">a_used</span><span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]]</span> <span class="o">-=</span> <span class="mi">1</span>
<span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">=</span> <span class="n">b</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span>
<span class="k">elif</span> <span class="n">a_used</span><span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]]</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">b_used</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]]</span> <span class="o">></span> <span class="mi">1</span><span class="p">:</span>
<span class="n">x_done</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">b_used</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]]]</span> <span class="o">-=</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">x_done</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">b</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="k">if</span> <span class="n">a_used</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">i</span>
<span class="k">break</span>
<span class="k">print</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">end</span><span class="o">=</span><span class="s">""</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">)):</span>
<span class="k">print</span><span class="p">(</span><span class="s">" "</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]),</span> <span class="n">end</span><span class="o">=</span><span class="s">""</span><span class="p">)</span>
</code></pre></div></div>
<h1 id="c-an-impassioned-circulation-of-affection">C. An impassioned circulation of affection</h1>
<p>当时把自己带到沟里了,想着先split,然后就卡在“aaaaaa”这种情况。今天发现只要暴力扫一遍就好,不需要split啥的。。注意需要先算好所有答案,因为q太大了。
卡python也是无语,只好再用c++写一下。我这里循环用滑动窗口来做,j先确定当前串的长度,另一种做法是直接两重循环串的起点和终点,两种做法都是O(n^2),没有区别。官方题解还提到了有复杂度更低的算法,目前没有动力去看。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cp">#include <iostream>
#include <string>
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">f</span><span class="p">[</span><span class="mi">26</span><span class="p">][</span><span class="mi">1510</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">c</span><span class="p">;</span>
<span class="n">string</span> <span class="n">s</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">s</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">26</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">char</span> <span class="n">ch</span> <span class="o">=</span> <span class="sc">'a'</span> <span class="o">+</span> <span class="n">i</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">r</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">r</span> <span class="o"><</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">r</span><span class="p">]</span> <span class="o">!=</span> <span class="n">ch</span><span class="p">)</span> <span class="p">{</span>
<span class="n">count</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">while</span> <span class="p">(</span><span class="n">count</span> <span class="o">></span> <span class="n">j</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">l</span><span class="p">]</span> <span class="o">!=</span> <span class="n">ch</span><span class="p">)</span> <span class="p">{</span>
<span class="n">count</span><span class="o">--</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">l</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">r</span><span class="o">-</span><span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
<span class="n">r</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">q</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">q</span><span class="p">)</span> <span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">m</span> <span class="o">>></span> <span class="n">c</span><span class="p">;</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">f</span><span class="p">[</span><span class="kt">int</span><span class="p">(</span><span class="n">c</span><span class="o">-</span><span class="sc">'a'</span><span class="p">)][</span><span class="n">m</span><span class="p">]</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="n">q</span><span class="o">--</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
LeetCode 600 Non-negative Integers without Consecutive Ones
2017-06-07T00:00:00+00:00
http://greenmooon55.com/leetcode-600-non-negative-integers-without-consecutive-ones
<p>第一次ak哈哈,可能是因为这周的比赛比较简单。</p>
<p>先说第一个方法,也是我当时想出来的。分情况讨论,一种是二进制表示的长度小于n的长度,另一种是跟n长度相同。第一种情况任意不含11的数都符合条件,第二种要搜索判断。</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">Solution</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">count</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">num</span><span class="p">,</span> <span class="n">size</span><span class="p">):</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="n">size</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">num</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="c"># top: whether current value is the same as a</span>
<span class="k">def</span> <span class="nf">countLimit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">num</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">top</span><span class="p">):</span>
<span class="k">if</span> <span class="n">top</span> <span class="ow">and</span> <span class="n">num</span> <span class="o">></span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="n">size</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">num</span> <span class="o"><</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]:</span>
<span class="n">top</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">if</span> <span class="n">num</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">if</span> <span class="n">top</span> <span class="o">==</span> <span class="bp">False</span><span class="p">:</span>
<span class="c"># we can choose whatever we want</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="nb">all</span><span class="p">[</span><span class="n">size</span><span class="o">-</span><span class="n">i</span><span class="p">]</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">countLimit</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">top</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">countLimit</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">top</span><span class="p">)</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">countLimit</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">top</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">findIntegers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">):</span>
<span class="s">"""
:type num: int
:rtype: int
"""</span>
<span class="c"># possible solutions starting with 1</span>
<span class="bp">self</span><span class="o">.</span><span class="nb">all</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mi">31</span>
<span class="bp">self</span><span class="o">.</span><span class="nb">all</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="nb">all</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">31</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="nb">all</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="nb">all</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="nb">all</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span>
<span class="n">a</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">while</span> <span class="n">num</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span>
<span class="n">a</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">num</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">//</span> <span class="mi">2</span>
<span class="n">a</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
<span class="n">length</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="c">#print(a)</span>
<span class="n">res</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">countLimit</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">length</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
<span class="c">#print(res)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">length</span><span class="p">):</span>
<span class="n">res</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="nb">all</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
<span class="c"># add 0 to solutions</span>
<span class="k">return</span> <span class="n">res</span> <span class="o">+</span> <span class="mi">1</span>
</code></pre></div></div>
<p>all数组表示1开头符合条件的数的数量,本来是通过count函数来搜索的,后来发现是斐波那契数列就直接算了。countLimit用来搜索长度与n相同的数,top用来标记当前位是否与n一样大,如果当前第i位是1并且已经不是最大的,那就说明从第i位开始就可以随意选1和0了,加了这个剪枝就过了。</p>
<p>下面是官方题解的思路,另外参考<a href="http://blog.csdn.net/u014688145/article/details/72812515">这个解释</a>。
这个f[i]包含以0开头的情况,所以如果发现n的第i位是1,那么当前位是0,后面就可以任意选数字了。如果遇到连续的1,选完第i位是0,就可以退出了,因为此时第i位只能为0。最后返回时加上n本身(如果遇到11要限减掉,因为不可能出现n这个数)。</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">Solution</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">findIntegers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">num</span><span class="p">):</span>
<span class="s">"""
:type num: int
:rtype: int
"""</span>
<span class="n">a</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">while</span> <span class="n">num</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span>
<span class="n">a</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">num</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">num</span> <span class="o">=</span> <span class="n">num</span> <span class="o">//</span> <span class="mi">2</span>
<span class="n">a</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
<span class="n">length</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="c"># number of available solutions, i is the length of binary representations</span>
<span class="c"># f[1]: 0, 1; f[2]: 00, 10, 01</span>
<span class="n">f</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="n">length</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">f</span><span class="p">)):</span>
<span class="c"># f[i] = (f[i-1] + '0') + (f[i-2] + '01')</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span>
<span class="n">res</span> <span class="o">=</span> <span class="mi">0</span>
<span class="c">#print(length,res)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">length</span><span class="p">):</span>
<span class="k">if</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">l</span> <span class="o">=</span> <span class="n">length</span> <span class="o">-</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">res</span> <span class="o">+=</span> <span class="n">f</span><span class="p">[</span><span class="n">l</span><span class="p">]</span>
<span class="k">if</span> <span class="n">i</span> <span class="o">></span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="c"># num itself is invalid and will be deleted later</span>
<span class="n">res</span> <span class="o">-=</span> <span class="mi">1</span>
<span class="c"># res was updated in previous i</span>
<span class="k">break</span>
<span class="c"># plus num itself</span>
<span class="k">return</span> <span class="n">res</span><span class="o">+</span><span class="mi">1</span>
</code></pre></div></div>
我的2016
2016-12-31T00:00:00+00:00
http://greenmooon55.com/2016-year-in-review
<p>2016年发生了很多事情,年前一二月在公司忙重构,四月决定出国,六月离职,七八月复习GRE,后面在学校申请+看看论文。</p>
<p>今年做的最重要决定肯定是离职准备申请master,可能在别人看来是比较冲动的决定,这次也就上网搜了一圈资料就决定了,其实本科的时候有过一点点想法,只是后来完全放弃了。</p>
<p>不记得在哪里看到一篇文章,不管从事什么高薪工作,多年后很多人还是会选择做自己最想做的事情,过自己想要的生活方式。初中的时候有次跟同学聊天,讲以后想做什么,我就想做一个平凡的人,白天做有意义的工作,空闲时间可以读读书,这就是最理想的人生了,希望以后能实现这个目标。(有意义 = 影响的人数 * 贡献度,比如让电脑开机耗时-1s,如果影响的人多,也是一件有意义的工作。)接下来读研希望也有时间见识更大的世界,思考人生目标。</p>
<p>第一次回到软院很想哭,很喜欢最近在嘉定的生活。申请季到现在还比较顺利,最紧张的时候是八月初担心GRE考不出来和十一月底担心文书写不好,等明年结果都出来再好好总结一下吧。完全没想到最近这半年会这么忙,近三个月的节奏是这样的:每周实验室开会之后先自己看看公开课放松一两天,然后再花两三天做本周的主要任务,比如复习托福或者网申几所学校,最后开会前一两天再去看论文或者折腾代码,这一两天才是每周最紧张的时候,所以其实每次去考托福或者GRE我都非常放松。。</p>
<p>今年公开课看了宾大的《城市规划》,感觉好多设计很有特色,很强调构建一个walkable neighbourhood,然而真的跟中国国情差距太大,人太多了= = 第一次体验peer review的公开课,大家做presentation都挺认真的。专业相关的就是Andrew Ng的Machine Learning,Geoffrey Hinton的神经网络,再加上Udacity的自动驾驶,都各有侧重,明年学完再来总结。</p>
<p>虽然不是学霸,对于我来说,学习带来的快感要比上班写代码爽得多,可能因为码农不能决定产品方向?(其实还算幸运一直在做还算感兴趣的东西,没有遇到过新浪微博那种脑残PM。)挺喜欢读paper的,申请季也在考虑以后是做科研还是工作,工作的话要是去不了好玩的组,就算在FLAG又如何,科研我不明确做什么方向,也不知道自己是否天赋、智商足够,要知道科研选错方向可比在公司进错组惨多了。(推荐这篇研究生后出国去Google的思考《<a href="https://laike9m.com/blog/shi-shi-hou-liao,94/">是时候了</a>》,我也比较看重技术氛围和国内环境)</p>
<p>最近在一亩三分地上看到两篇讨论这类问题的帖子,一篇是<a href="http://www.1point3acres.com/bbs/thread-216592-1-1.html">top5硕士毕业工作三年后想做科研</a>,另外一篇是<a href="http://www.1point3acres.com/bbs/thread-217580-1-1.html">想做CV但是master读了一年之后有些迷茫</a>,第二篇很可能就是明年的我。我发现性格因素其实也挺重要,上大学测过自己是INTJ,这两个帖子的作者也是INTJ/INTP,我昨天测了下还是INTJ,I最明显,NTJ其实倾向不大,或许这种测试还是有点道理的?INTJ也就是内倾、直觉、理性、判断。内向是肯定的,我是属于充电(跟人聊天)五分钟可以放电(一个人呆着)很久的,一直充电就会爆炸,大一对门的时候就不理结果为啥希望寝室没有人。还有一点是强烈兴趣驱动,完全无法忍受做自己不想做的事情,比如当年不保研的原因之一是不想再上政治课,现在申请也不想选MSIM甚至MSIN这种课程表不完美的项目。追求完美?可能是有点吧。。我也越来越不在意别人的想法了。“INTJ是十六种人格类型中最稀有的类型,约占女性人口比例0.5%,男性人口比例1%”,来自<a href="https://zh.wikipedia.org/zh-hans/INTJ">维基百科</a>,真是可怜。</p>
<p>今年的主要娱乐是看youtube的游戏视频…F1(播主是工科生)、模拟卡车(播主居然是cs毕业的大叔,有次还聊他喜欢操作系统讨厌数学课。。),还有bilibili的视频吧。。书几乎没看,kindle已经积灰很久了。每天晚上从十一点多躺一两个小时睡不着也是醉醉的。豆瓣告诉我今年电影居然看得比去年少,额是更宅了还是更忙了?</p>
<p>申请季仅仅是个开始,不管找工还是科研,后面的压力会更大。新年计划就不写了,听说不告诉别人计划会更好?越长大越想家,也希望能多回家看看。</p>
<p>新年快乐!</p>
<p>最后放一张调过色的嘉定。</p>
<p><img src="/images/jiading.png" alt="" /></p>
Coursera Machine Learning
2016-11-18T00:00:00+00:00
http://greenmooon55.com/coursera-machine-learning
<p>这门课也是本科的时候尝试然后放弃的课,今年五月重新捡了起来还买了证书,夏天复习GRE没看,赶在可以获得证书的最后几天(要半年内学完)终于学完了。</p>
<p>这门课是 <a href="http://cs229.stanford.edu/">CS229</a> 的 <a href="https://www.quora.com/What-are-the-differences-between-the-Andrew-Ngs-Machine-Learning-courses-offered-on-Coursera-and-iTunes-U?srid=bMF">“watered down”版本</a>。
剔除了几乎所有需要数学知识的部分,只需要知道如何求导以及矩阵乘法。编程作业里的所有数学公式都给出来了,只需要在MATLAB里实现就可以了。这门课很奇葩的一点是入门比较难…后面越来越简单。</p>
<p>总结一下这门课都讲了啥?</p>
<ol>
<li>
<p>线性回归,cost function, gradient descent, vectorized implementation</p>
</li>
<li>
<p>Feature scaling, mean normalization, normal equation(但是数据量大的时候很慢), regularization</p>
</li>
<li>
<p>Logistic Regression(用到sigmoid function和取对数的cost function), Advanced optimization, one-vs-all</p>
</li>
<li>
<p>Neural Networks: Forward Propagation, bias unit, Backpropagation(可以用gradient checking确定backpropagation算出的导数是否正确), Random initialization: Symmetry breaking</p>
</li>
<li>
<p>Training/validation/test sets</p>
<p><img src="/images/ml-bias-variance.png" alt="" />
<img src="/images/ml-learning-curve.png" alt="" /></p>
</li>
<li>
<p>Spam classification, Precision/Recall, F Score</p>
</li>
<li>
<p>SVM:修改Logistic Regression的model,优化theta即可获得比较好的结果。</p>
<p>参考:<a href="http://blog.pluskid.org/?p=632">支持向量机: Maximum Margin Classifier</a></p>
<p>Kernel: 生成feature的好方法,可以选择数据作为landmarks,选择基于到landmark的距离的similarity methods来生成新的数据。</p>
<p><img src="/images/ml-logistic-regression-svm.png" alt="" /></p>
</li>
<li>
<p>KMeans</p>
</li>
<li>
<p>Demension Reduction: PCA(SVD分解)(Bad use: prevent overfitting)</p>
</li>
<li>
<p>Anomaly Detection,这里用的是高斯分布,判断数据点是否离均值太远</p>
<p><img src="/images/ml-anomaly-detection.png" alt="" /></p>
</li>
<li>
<p>Collabrative Filtering</p>
<p><img src="/images/ml-collabrative-filtering.png" alt="" /></p>
</li>
<li>
<p>Stochastic gradient descent(random shuffle first, can slowly decrease alpha), mini-batch gradient descent, MapReduce</p>
</li>
<li>
<p>Pipline, Ceiling analysis</p>
</li>
</ol>
<p>嗯只是给我自己看的….有人写了很详细的笔记,强烈推荐:<a href="http://www.holehouse.org/mlclass/index.html">http://www.holehouse.org/mlclass/index.html</a></p>
<p>接下来我现在在看Hilton的Neural Network,很详细地讲神经网络,上周学了CNN,这周讲RNN。等明年有空去搞搞Kaggle,学完不动手就全忘了。或许看下CS229或者231n吧…</p>
回到嘉定
2016-07-06T00:00:00+00:00
http://greenmooon55.com/back-to-jiading
<p>像我这么不敏感的人,并没有什么感觉,一进图书馆开始看书就把自己当做准备期末考的大二学生了,没有任何违和感。然而这都是考试周的第二周了,图书管理依旧都是大二电气的复习考试呢。。</p>
<p>倒是睡前刷邮箱刷到LinkedIn,看到好几个大一学CS的同学,现在都挺不错的,去了好公司or去了好学校,突然发现真的过了好多年了。</p>
<p><a href="https://www.shanbay.com/weekly/article/1051/">笑来寄语:人生是一场长跑,但你想明白了么?</a></p>
猴年快乐
2016-02-09T00:00:00+00:00
http://greenmooon55.com/160209
<p>又是很匆忙的一年,除夕下午出去买东西,头一次看到没人的河南街。。回到家晚会都开始了,都没来得及贴春联。</p>
<p>想想 2015 也发生了很多,首先是换了个工作,当时想着扇贝的一句话 I know it’s going to be very busy, but I’m ready to welcome that with open arms. 结果到了 2016 才是真忙,一月份忙到都没有生活了= =</p>
<p>技术上么,终于有了MBP,系统是挺好用的,不过在我手上经常五国- - 开始用了 PyCharm,终于开始 coding 了,有机会开发新功能&重构感觉很爽的。不过一直没机会折腾 docker 相关的东西,今年要搞起来咯,还要看看旧代码,多向同事学东西~ 其实现在并发量还没上来,以后有更多挑战。</p>
<p>入了 steam 大坑,买了好多游戏,玩得多的是不用动脑的卡车模拟和Mini Metro,周末就想在家宅着好好休息打游戏= =</p>
<p>终于从闵行回到了大杨浦^_^。尽管上半年去了西安,后面去了两次杭州,参加了一次 8km 跑步比赛,不过后面感觉更宅了,健身一点都没搞了,Keep 也没做,口琴半年木有拿出来了。。Todoist 和扇贝倒是坚持下来啦。</p>
<p>新年希望自己更开心咯,要多花时间想想计划了。</p>
Raspberry Pi 上手
2015-11-19T00:00:00+00:00
http://greenmooon55.com/hands-on-with-raspberry-pi
<p>从公司拿来一台树莓派折腾玩,下面记录一下折腾的的过程吧。</p>
<h1 id="买-sd-卡装系统">买 SD 卡装系统</h1>
<p>京东买了个 <a href="http://item.jd.com/1875996.html">Sandisk 16G卡</a>,插在读卡器上就可以用了。官网下载 <a href="https://www.raspberrypi.org/downloads/raspbian/">RASPBIAN JESSIE</a>,
装好之后懒得接显示器,nmap 查一下 ip, ssh pi@<ip>,密码是 raspberry。配了 192.168.1.233 这个静态 ip,这样以后就可以直接连了233。</ip></p>
<h1 id="连接显示器">连接显示器</h1>
<p>HDMI连上我的 Dell U2312HM 显示器,居然没反应。。还好搜到<a href="http://www.chriszh.com/?p=562">解决方法</a></p>
<blockquote>
<p>在网上找了一下,说是将/boot/config.txt的HDMI_SAFE的注释删掉就好了,于是照做。发现显示器能亮了,但是只有640*480的分辨率。再经过若干折腾,发现将HDMI_SAFE还是注掉,将hdmi_force_hotplug=1打开就可以完美1080p了。不过用hdmi接电视的时候需要再关上。</p>
</blockquote>
<h1 id="usb网卡">USB网卡</h1>
<p>开始折腾的时间到了。。买了个<a href="http://item.jd.com/123836.html">TP-LINK TL-WN821N 300M无线USB网卡</a>,插上去之后 lsusb 没识别。</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pi@raspberrypi ~ $ lsusb
Bus 001 Device 004: ID 0bda:818b Realtek Semiconductor Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
</code></pre></div></div>
<p>能搜到需要 rtl8192eu 驱动,谢天谢地有人编译好了,从<a href="http://tieba.baidu.com/p/4161599392">百度贴吧</a>找到的链接:
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=124509&p=835823&hilit=8192eu#p835823</p>
<p>根据规则从 Dropbox 下载就好了,好幸福。。就怕他以后不更新了,不敢升级系统了。。</p>
<h1 id="路由器">路由器</h1>
<p>参考这篇文章把树莓派搞成AP吧:</p>
<p>http://jacobsalmela.com/raspberry-pi-and-routing-turning-a-pi-into-a-router/</p>
<p>注意 hostapd 不能用 debian 自带的,需要自己编译,我直接用的 master 分支,参考:http://www.jenssegers.be/43/realtek-rtl8188-based-access-point-on-raspberry-pi</p>
<p>hostapd.conf</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code># Basic configuration
interface=wlan0
ssid=RPiAP
channel=7
#bridge=br0
# WPA and WPA2 configuration
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
# Hardware configuration
driver=rtl871xdrv
ieee80211n=1
hw_mode=g
device_name=RTL8192CU
manufacturer=Realtek
</code></pre></div></div>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pi@raspberrypi ~ $ cat /etc/dnsmasq.conf | grep -v "#" | sed '/^$/d'
domain-needed
interface=wlan0
listen-address=127.0.0.1,192.168.2.1
dhcp-range=192.168.2.20,192.168.2.200,12h
</code></pre></div></div>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pi@raspberrypi ~ $ cat /etc/network/interfaces
# Please note that this file is written to be used with dhcpcd.
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'.
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
#iface eth0 inet manual
iface eth0 inet static
address 192.168.1.233
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
gateway 192.168.2.1
</code></pre></div></div>
<p>iptables 配置参考这篇文章:http://liberize.me/tech/turn-raspberry-pi-into-a-router.html</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
</code></pre></div></div>
<p>Done! Have fun!</p>
Nova scheduler
2015-07-25T00:00:00+00:00
http://greenmooon55.com/nova-scheduler
<p>Nova部署、迁移VM都会用到scheduler来调度。本文内容基于Icehouse。</p>
<p>#Filters and Weights</p>
<p><img src="http://greenmoon55.com/images/scheduler.png" alt="Filters and Weights" title="Filters and Weights" /></p>
<p>Filters会过滤不符合条件的宿主机,然后经过Weights获得权重,最终选择权重最大的host。</p>
<p>常用filter有RetryFilter,AvailabilityZoneFilter,RamFilter,ComputeFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter。</p>
<p>默认启用的weighter只有RAMWeigher。。会返回host的可用内存,最终选取可用内存最大的host。</p>
<p>另外还有个MetricsWeigher,可以自定义各项metric的重要性,不过默认没有启用。</p>
<p>#Resource tracker</p>
<p>那么这些权重怎么获取呢?</p>
<p>nova/compute/manager.py 有个periodic task update_available_resource,每分钟会更新一次host的资源使用情况。最终会调用到resource tracker里的_sync compute node,更新compute_nodes表。scheduler里的HostManager再从数据库里获取metrics。</p>
<p>scheduler本身不会更新host metric,只会在filter_scheduler _provision_resource时更新instance的host, node及schedule_at。</p>
<p>#是否有cache
没有,有个caching scheduler,可缓存all_host_states,默认没有启用。</p>
<p>#retry如何实现?</p>
<p>filter scheduler -> def scheduler_run_instance -> def _schedule -> def _populate_retry</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">retry</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">'num_attempts'</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
<span class="s">'hosts'</span><span class="p">:</span> <span class="p">[]</span> <span class="c"># list of compute hosts tried</span>
<span class="p">}</span>
<span class="n">filter_properties</span><span class="p">[</span><span class="s">'retry'</span><span class="p">]</span> <span class="o">=</span> <span class="n">retry</span>
</code></pre></div></div>
<p>compute/manager.py有_reschedule_or_error,如果失败会RPC调用scheduler。
另外有个RetryFilter,会过滤之前尝试(失败)过的host。</p>
<p>相关资料:</p>
<p><a href="http://www.openstack.cn/?p=3312">Nova Scheduler Intel 王庆</a></p>
<p><a href="http://www.choudan.net/2013/08/11/Nova-Scheduler%E5%88%86%E6%9E%90.html">臭蛋 Nova Scheduler分析</a></p>
<p><a href="https://www.mirantis.com/blog/nova-scheduler-database-interactions-how-to-nail-those-scalability-thwarters/">Mirantis: Nova Scheduler-Database Interactions: How to Nail Those Scalability Thwarters</a></p>
<p>Update:</p>
<p>最后补充个用 pyreverse 画的<a href="http://greenmoon55.com/images/scheduler_classes.png">类图</a></p>
Coursera Cryptography
2015-06-22T00:00:00+00:00
http://greenmooon55.com/coursera-cryptography
<p>大学的时候之前尝试过两次,都没跟下来,这次终于学完了。。</p>
<p>密码学是什么?在学这门课之前,我只有这些印象:</p>
<ol>
<li>课程项目写用户注册的时候要 hash+salt</li>
<li>Rails 会把 session 信息存在 cookie 里,为了防止被篡改,cookie 里还有个 HMAC,用到了secret key。<a href="http://stackoverflow.com/questions/13786320/rails-where-is-message-digest-of-sessions-using-default-cookiestore">link</a></li>
<li>SSH keypair</li>
</ol>
<p>目标主要有两个:confidentiality and integrity。要保证confidentiality,就要选择各种加密方法,要保证integrity,就要用到MAC。
两种都保证了,就可以说实现了authenticated encryption。</p>
<p>好吧,那接下来看看都讲了啥。。自己整理一下:</p>
<p>第一周:Stream Cipher, One-time Pad, PRG</p>
<p>第二周:Block Cipher, AES, DES, PRG, PRF, CBC, CTR</p>
<p>第三周:Secure MAC, Birthday Attack, Merkle–Damgard iterated construction</p>
<p>第四周:Authenticated Encryption, Encrypt-then-MAC, Padding Oracle, HKDF, PBKDF</p>
<p>第五周:Diffie-Hellman protocol, Fermat, Euler, DLOG</p>
<p>第六周:Trapdoor Functions, RSA, PKCS1 v1.5, PKCS1 v2.0: OAEP, EIGamal</p>
<p><a href="http://naotu.baidu.com/viewshare.html?shareId=awh8z6rrpwk4">百度脑图</a></p>
<p>现在感觉只是大概了解了这些概念和数学证明,习题做得太少,已经忘了一些了。。知道这些已经知足啦,期待Part 2:)</p>
OpenStack Horizon Filter 功能的实现
2015-03-07T00:00:00+00:00
http://greenmooon55.com/horizon-filter-feature
<p>怕自己以后忘了,随手记一下。</p>
<p>下图是 admin dashboard 里的 filter,可根据 Project 和 Name 过滤 instance。</p>
<p><img src="/images/horizon-filter-admin.png" alt="" /></p>
<p>下图是 project dashboard 里的 filter,可以过滤表格里的任意一列</p>
<p><img src="/images/horizon-filter-project.png" alt="" /></p>
<p>代码以当前 stable/icehouse 分支为准</p>
<p>首先从后端看起,<a href="https://github.com/openstack/horizon/blob/cfa611bedf14c9b1ef0b5689b6942aa6431e6313/horizon/tables/actions.py">horizon/tables/actions.py</a> 有 FilterAction class</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">FilterAction</span><span class="p">(</span><span class="n">BaseAction</span><span class="p">):</span>
</code></pre></div></div>
<p><a href="https://github.com/openstack/horizon/blob/cfa611bedf14c9b1ef0b5689b6942aa6431e6313/openstack_dashboard/dashboards/project/instances/tables.py">openstack_dashboard/dashboards/project/instances/tables.py</a> 有</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">InstancesFilterAction</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">FilterAction</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</span><span class="p">,</span> <span class="n">instances</span><span class="p">,</span> <span class="n">filter_string</span><span class="p">):</span>
<span class="s">"""Naive case-insensitive search."""</span>
<span class="n">q</span> <span class="o">=</span> <span class="n">filter_string</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
<span class="k">return</span> <span class="p">[</span><span class="n">instance</span> <span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">instances</span>
<span class="k">if</span> <span class="n">q</span> <span class="ow">in</span> <span class="n">instance</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span><span class="n">admin</span>
</code></pre></div></div>
<p><a href="https://github.com/openstack/horizon/blob/cfa611bedf14c9b1ef0b5689b6942aa6431e6313/openstack_dashboard/dashboards/admin/instances/tables.py">openstack_dashboard/dashboards/admin/instances/tables.py</a></p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">AdminInstanceFilterAction</span><span class="p">(</span><span class="n">tables</span><span class="o">.</span><span class="n">FilterAction</span><span class="p">):</span>
<span class="n">filter_type</span> <span class="o">=</span> <span class="s">"server"</span>
<span class="n">filter_choices</span> <span class="o">=</span> <span class="p">((</span><span class="s">'project'</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">"Project"</span><span class="p">)),</span>
<span class="p">(</span><span class="s">'name'</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">"Name"</span><span class="p">))</span>
<span class="p">)</span>
<span class="n">needs_preloading</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">def</span> <span class="nf">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">table</span><span class="p">,</span> <span class="n">instances</span><span class="p">,</span> <span class="n">filter_string</span><span class="p">):</span>
<span class="s">"""Server side search.
When filtering is supported in the api, then we will handle in view
"""</span>
<span class="n">filter_field</span> <span class="o">=</span> <span class="n">table</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'instances__filter__q_field'</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">filter_field</span> <span class="o">=</span> <span class="n">filter_field</span>
<span class="bp">self</span><span class="o">.</span><span class="n">filter_string</span> <span class="o">=</span> <span class="n">filter_string</span>
<span class="k">if</span> <span class="n">filter_field</span> <span class="o">==</span> <span class="s">'project'</span> <span class="ow">and</span> <span class="n">filter_string</span><span class="p">:</span>
<span class="k">return</span> <span class="p">[</span><span class="n">inst</span> <span class="k">for</span> <span class="n">inst</span> <span class="ow">in</span> <span class="n">instances</span>
<span class="k">if</span> <span class="n">inst</span><span class="o">.</span><span class="n">tenant_name</span> <span class="o">==</span> <span class="n">filter_string</span><span class="p">]</span>
<span class="k">if</span> <span class="n">filter_field</span> <span class="o">==</span> <span class="s">'name'</span> <span class="ow">and</span> <span class="n">filter_string</span><span class="p">:</span>
<span class="n">q</span> <span class="o">=</span> <span class="n">filter_string</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
<span class="k">return</span> <span class="p">[</span><span class="n">instance</span> <span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">instances</span>
<span class="k">if</span> <span class="n">q</span> <span class="ow">in</span> <span class="n">instance</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span>
<span class="k">return</span> <span class="n">instances</span>
</code></pre></div></div>
<p>然后我们看下前端的实现,<a href="https://github.com/openstack/horizon/blob/cfa611bedf14c9b1ef0b5689b6942aa6431e6313/horizon/templates/horizon/common/_data_table_table_actions.html">horizon/templates/horizon/common/_data_table_table_actions.html</a></p>
<p>可以看到这里有三种 <code class="highlighter-rouge">filter_type</code>,InstancesFilterAction 默认是 query,AdminInstanceFilterAction 是 server。query 和 server 有什么不同呢?我们去看看 js。</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">horizon</span><span class="p">.</span><span class="nx">datatables</span><span class="p">.</span><span class="nx">set_table_query_filter</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">parent</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">(</span><span class="nx">parent</span><span class="p">).</span><span class="nx">find</span><span class="p">(</span><span class="s1">'table'</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">index</span><span class="p">,</span> <span class="nx">elm</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">input</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="nx">elm</span><span class="p">).</span><span class="nx">find</span><span class="p">(</span><span class="s1">'div.table_search.client input'</span><span class="p">)),</span>
<span class="nx">table_selector</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// Disable server-side searcing if we have client-side searching since</span>
<span class="c1">// (for now) the client-side is actually superior. Server-side filtering</span>
<span class="c1">// remains as a noscript fallback.</span>
<span class="c1">// TODO(gabriel): figure out an overall strategy for making server-side</span>
<span class="c1">// filtering the preferred functional method.</span>
<span class="nx">input</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">'keypress'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">evt</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">evt</span><span class="p">.</span><span class="nx">keyCode</span> <span class="o">===</span> <span class="mi">13</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="nx">input</span><span class="p">.</span><span class="nx">next</span><span class="p">(</span><span class="s1">'button.btn-search'</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s1">'click keypress'</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">evt</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">});</span>
<span class="c1">// Enable the client-side searching.</span>
<span class="nx">table_selector</span> <span class="o">=</span> <span class="s1">'table#'</span> <span class="o">+</span> <span class="nx">$</span><span class="p">(</span><span class="nx">elm</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">'id'</span><span class="p">);</span>
<span class="nx">input</span><span class="p">.</span><span class="nx">quicksearch</span><span class="p">(</span><span class="nx">table_selector</span> <span class="o">+</span> <span class="s1">' tbody tr'</span><span class="p">,</span> <span class="p">{</span>
<span class="s1">'delay'</span><span class="p">:</span> <span class="mi">300</span><span class="p">,</span>
<span class="s1">'loader'</span><span class="p">:</span> <span class="s1">'span.loading'</span><span class="p">,</span>
<span class="s1">'bind'</span><span class="p">:</span> <span class="s1">'keyup click'</span><span class="p">,</span>
<span class="s1">'show'</span><span class="p">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">show</span><span class="p">,</span>
<span class="s1">'hide'</span><span class="p">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">hide</span><span class="p">,</span>
<span class="na">onBefore</span><span class="p">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">table</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">table_selector</span><span class="p">);</span>
<span class="nx">horizon</span><span class="p">.</span><span class="nx">datatables</span><span class="p">.</span><span class="nx">remove_no_results_row</span><span class="p">(</span><span class="nx">table</span><span class="p">);</span>
<span class="p">},</span>
<span class="na">onAfter</span><span class="p">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">template</span><span class="p">,</span> <span class="nx">table</span><span class="p">,</span> <span class="nx">colspan</span><span class="p">,</span> <span class="nx">params</span><span class="p">;</span>
<span class="nx">table</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">table_selector</span><span class="p">);</span>
<span class="nx">horizon</span><span class="p">.</span><span class="nx">datatables</span><span class="p">.</span><span class="nx">update_footer_count</span><span class="p">(</span><span class="nx">table</span><span class="p">);</span>
<span class="nx">horizon</span><span class="p">.</span><span class="nx">datatables</span><span class="p">.</span><span class="nx">add_no_results_row</span><span class="p">(</span><span class="nx">table</span><span class="p">);</span>
<span class="nx">horizon</span><span class="p">.</span><span class="nx">datatables</span><span class="p">.</span><span class="nx">fix_row_striping</span><span class="p">(</span><span class="nx">table</span><span class="p">);</span>
<span class="p">},</span>
<span class="na">prepareQuery</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="nx">val</span><span class="p">,</span> <span class="s2">"i"</span><span class="p">);</span>
<span class="p">},</span>
<span class="na">testQuery</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">query</span><span class="p">,</span> <span class="nx">txt</span><span class="p">,</span> <span class="nx">_row</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">query</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="nx">_row</span><span class="p">).</span><span class="nx">find</span><span class="p">(</span><span class="s1">'td:not(.hidden):not(.actions_column)'</span><span class="p">).</span><span class="nx">text</span><span class="p">());</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">};</span>
</code></pre></div></div>
<p>如果 filter_type 是 query,就直接调用 js 来 filter,用的是 <a href="https://github.com/DeuxHuitHuit/quicksearch">jQuery quicksearch</a>。(Icehouse 好像用的不是这个版本)</p>
<p>那么服务端的 filter 是怎么实现的呢?</p>
<p><a href="https://github.com/openstack/horizon/blob/cfa611bedf14c9b1ef0b5689b6942aa6431e6313/horizon/tables/base.py">horizon/tables/base.py</a></p>
<p>class DataTable 里的 filtered_data 会调用 action 的 filter 函数,而 get_rows 函数会从 filtered_data 里读数据。</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">filtered_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c"># This function should be using django.utils.functional.cached_property</span>
<span class="c"># decorator, but unfortunately due to bug in Django</span>
<span class="c"># https://code.djangoproject.com/ticket/19872 it would make it fail</span>
<span class="c"># when being mocked by mox in tests.</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">'_filtered_data'</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_filtered_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="nb">filter</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">_filter_action</span><span class="p">:</span>
<span class="n">action</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">_filter_action</span>
<span class="n">filter_string</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_filter_string</span><span class="p">()</span>
<span class="n">request_method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">method</span>
<span class="n">needs_preloading</span> <span class="o">=</span> <span class="p">(</span><span class="ow">not</span> <span class="n">filter_string</span>
<span class="ow">and</span> <span class="n">request_method</span> <span class="o">==</span> <span class="s">'GET'</span>
<span class="ow">and</span> <span class="n">action</span><span class="o">.</span><span class="n">needs_preloading</span><span class="p">)</span>
<span class="n">valid_method</span> <span class="o">=</span> <span class="p">(</span><span class="n">request_method</span> <span class="o">==</span> <span class="n">action</span><span class="o">.</span><span class="n">method</span><span class="p">)</span>
<span class="k">if</span> <span class="n">valid_method</span> <span class="ow">or</span> <span class="n">needs_preloading</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">mixed_data_type</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_filtered_data</span> <span class="o">=</span> <span class="n">action</span><span class="o">.</span><span class="n">data_type_filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,</span>
<span class="n">filter_string</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_filtered_data</span> <span class="o">=</span> <span class="n">action</span><span class="o">.</span><span class="nb">filter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">,</span>
<span class="n">filter_string</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_filtered_data</span>
<span class="k">def</span> <span class="nf">get_rows</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="s">"""Return the row data for this table broken out by columns."""</span>
<span class="n">rows</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">for</span> <span class="n">datum</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">filtered_data</span><span class="p">:</span>
<span class="n">row</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">row_class</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">datum</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_object_id</span><span class="p">(</span><span class="n">datum</span><span class="p">)</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_item_id</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">selected</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">row</span><span class="o">.</span><span class="n">classes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'current_selected'</span><span class="p">)</span>
<span class="n">rows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>
<span class="k">except</span> <span class="nb">Exception</span><span class="p">:</span>
<span class="c"># Exceptions can be swallowed at the template level here,</span>
<span class="c"># re-raising as a TemplateSyntaxError makes them visible.</span>
<span class="n">LOG</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="s">"Error while rendering table rows."</span><span class="p">)</span>
<span class="n">exc_info</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">exc_info</span><span class="p">()</span>
<span class="k">raise</span> <span class="n">template</span><span class="o">.</span><span class="n">TemplateSyntaxError</span><span class="p">,</span> <span class="n">exc_info</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">exc_info</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="k">return</span> <span class="n">rows</span>
</code></pre></div></div>
20150228
2015-02-28T00:00:00+00:00
http://greenmooon55.com/150228
<p>想着要写篇 blog,现在不知道该写什么了。</p>
<p>春节就算过完了,在家最短的一年,十天。春节过得跟十一没什么区别。。没放鞭炮、没怎么见亲戚,连春联都是三十晚上才贴上的。从大一春节回学校开始,每次回家都这么匆忙,我也没有很想家。在家改了改 Leancloud 的 Android todo list demo。</p>
<p>这次给家里买了米4、小米手环、小米路由 mini、米键,都物超所值啊。米4没什么亮点,手环计步、来电震动、解锁手机挺好用的,路由比 TP-Link 信号强多了,再也不用我的迷你路由做中继了,米键截图很好用。明年看看能不能给家里买个空气净化器…</p>
<p>过年见高中同学最神奇了,本来只有四个宅男见面,吃着饭遇到几个妹子,聊着聊着又遇到个,于是我们就在美食广场从午饭坐到晚饭,这些妹子毕业之后都没见过…</p>
<p>大家都挺拼的,在扬州工作的同学网上投了个简历,就来上海工作了。在哈尔滨的同学看到上海的招聘会,直接飞过来面试。。就这样来上海了。不知道我有没有这勇气诶。某童鞋问了我之后开始在扇贝上被单词,现在已经是66天 * 150词/天了,我都几年没背过了= =</p>
<p>初七,第一次看到这么冷清的上海,好多店铺都没开。虽然有喜欢做的任务,这周还是过得好慢,终于到周末了~新的一年开始了!</p>
20150218新春快乐
2015-02-18T00:00:00+00:00
http://greenmooon55.com/150218
<p>羊年就要来了,新年快乐!</p>
<p>我现在完全会想不出14年下半年我都干嘛了,好像生命中少了几个月一样。工作效率不高,心情也不太好。只能想到骑车去了趟嘉定,水了一场hackathon。</p>
<p>去年年底好好去玩了一趟,回来之后就不知道为啥就觉得世界很美好了。。2015年感觉很好,工作虽然很忙,但是很开心,发现真的有好多可以学的。</p>
<p>执行力太重要了,比如说要不是某童鞋,去年年底肯定不会出去玩。想做什么就花时间去做嘛,不然以后会后悔的。就像<a href="cntrains.com">cntrains</a>做出来没花多久:)现在在写Android版yaml的demo(不知道能写到啥程度。。), 口琴也到手了,还没开始玩。还想看看<a href="https://github.com/gitblog-io/gitblog-io.github.io">gitblog</a>呢。</p>
<p>现在感觉找到了大一时候的感觉:) 万一实现了呢~</p>
Upgrade Openstack From Grizzly To Icehouse
2015-02-14T00:00:00+00:00
http://greenmooon55.com/upgrade-openstack-from-grizzly-to-icehouse
<p>首先,我们在Meetup的时候介绍过升级,请看<a href="http://techshow.ctrip.com/archives/810.html">这里</a>的Session 3。说到升级,想起Paris summit的一个视频:<a href="https://www.openstack.org/summit/openstack-paris-summit-2014/session-videos/presentation/upgrading-in-place-from-grizzly-to-icehouse-a-cautionary-tale">Upgrading in Place from Grizzly to Icehouse: A Cautionary Tale</a>,具体说什么没啥印象了,只记得里面那句吐槽:one developer, two weeks,事实证明不可能那么快= =</p>
<p>网上有很多种升级方案,例如<a href="https://openstack.redhat.com/Upgrading_RDO">RDO的分类</a>就很不错。我们这边的环境对cloud的可用性要求不高,只要已经部署好的VM不受影响,可以接受较长时间不部署/管理虚拟机,所以我们最终选择了pdf里的方案一,就是controller原地升级,其实最后我们觉得换controller也不错…能降低点风险,还好升级时用方案一没遇到太多问题。</p>
<p>升级第一关就是db migration了,理论上来说上游代码里会考虑到升级的问题,每步db migration应该都在代码里面。其实这里还是有些问题的,我们有自己的改动,要先downgrade放弃自己的修改再upgrade,我们旧版上所有代码改动都先放弃了。。</p>
<p>首先就是grizzly的keystone client不支持降级(db sync指定版本),这个很好解决,改改代码咯。还有icehouse的nova db migration只支持从H版升上来,解决办法就是从H版把从G升到H的代码搞过来。。</p>
<p>难点在于neutron的db migration。I版的neutron经过重构,有了ml2 plugin,我们db sync之后还需要用官方提供的<a href="https://github.com/openstack/neutron/blob/3116ffafdca72e9eef70f4eaf90626982ae51d4c/neutron/db/migration/migrate_to_ml2.py">migrate to ml2的脚本</a>来改数据库,以支持ml2 plugin。H版的neutron在建VM的时候会把host和port插入portbindingports表,migrate to ml2脚本就会从这个表读数据并插入到<code class="highlighter-rouge">ml2_port_bindings</code>表里,network segment的信息是由<code class="highlighter-rouge">ovs_network_bindings</code>表搞出来的。(待补充)。。</p>
<p>下面问题来了,portbindingports是H版才有的表,G版根本没有啊,从grizzly升上来也不会建这个表,这样migrate to ml2就会有问题。不过用ovs plugin跑起来没啥问题…最终我们的办法是在db sync之后,migrate to ml2之前把host和port插入进去,这样看起来数据ok!网上没搜到这种问题,很奇怪。还有I版用ovs plugin的时候,如果是手工建的port,neutron不会插入到portbindingports里,migrate to ml2就不会插入<code class="highlighter-rouge">ml2_port_bindings</code>表里,但是ml2 plugin会把这种port插入<code class="highlighter-rouge">ml2_port_bindings</code>。Anyway,我们最后也把这种unbound的port都插入进去了。</p>
<p>以上就是db migration的问题,我们在测试升级和实际操作的时候还遇到一些问题。</p>
<ol>
<li>
<p>mysql备份出来的sql,注释的地方也是有用的,不能随便删掉。</p>
</li>
<li>
<p>更新包的时候有些包没有依赖,不会自动更新,要手动搞。</p>
</li>
<li>
<p>neutron agents由fqdn改成hostname,要删掉inactive的那些(这个文档也写了)</p>
</li>
<li>
<p>太多坑了= =!</p>
</li>
</ol>
<p>我们整个升级用时是估算时间*2…</p>
<p>下次升级一定要准备更充分一点,估计是升到Kilo或者Liberty了…最好neutron的代码也有人认真看看。其实I版上游的代码还有挺多bug的,要是有能力的话有很多机会贡献代码= =…</p>
<p>研究升级方案时发现有好多好多可以学的东西啊~之前一直有其他需求,没空搞升级,终于在年前搞定这件大事了。(似乎还有坑没发现T_T)</p>
Novaclient 载入 extensions 的过程
2014-10-28T00:00:00+00:00
http://greenmooon55.com/python-novaclient
<p><code class="highlighter-rouge">novaclient/v1_1/contrib</code>里可以加入新的指令,例如:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nd">@utils.arg</span><span class="p">(</span><span class="s">'server'</span><span class="p">,</span>
<span class="n">metavar</span><span class="o">=</span><span class="s">'<server>'</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="n">_</span><span class="p">(</span><span class="s">'Name or UUID of the server to list actions for.'</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">do_instance_action_list</span><span class="p">(</span><span class="n">cs</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="s">"""List actions on a server."""</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">find_resource</span><span class="p">(</span><span class="n">cs</span><span class="o">.</span><span class="n">servers</span><span class="p">,</span> <span class="n">args</span><span class="o">.</span><span class="n">server</span><span class="p">)</span>
<span class="n">actions</span> <span class="o">=</span> <span class="n">cs</span><span class="o">.</span><span class="n">instance_action</span><span class="o">.</span><span class="nb">list</span><span class="p">(</span><span class="n">server</span><span class="p">)</span>
<span class="n">utils</span><span class="o">.</span><span class="n">print_list</span><span class="p">(</span><span class="n">actions</span><span class="p">,</span>
<span class="p">[</span><span class="s">'Action'</span><span class="p">,</span> <span class="s">'Request_ID'</span><span class="p">,</span> <span class="s">'Message'</span><span class="p">,</span> <span class="s">'Start_Time'</span><span class="p">],</span> <span class="n">sortby_index</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</code></pre></div></div>
<p>那这个函数是怎么被调用的呢</p>
<p>在 <code class="highlighter-rouge">novaclient/shell.py</code> 的 <code class="highlighter-rouge">main</code> 里有</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># build available subcommands based on version</span>
<span class="bp">self</span><span class="o">.</span><span class="n">extensions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_discover_extensions</span><span class="p">(</span>
<span class="n">options</span><span class="o">.</span><span class="n">os_compute_api_version</span><span class="p">)</span>
</code></pre></div></div>
<p>然后找到这个函数</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">_discover_extensions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">version</span><span class="p">):</span>
<span class="n">extensions</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">module</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_discover_via_python_path</span><span class="p">(),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_discover_via_contrib_path</span><span class="p">(</span><span class="n">version</span><span class="p">),</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_discover_via_entry_points</span><span class="p">()):</span>
<span class="n">extension</span> <span class="o">=</span> <span class="n">novaclient</span><span class="o">.</span><span class="n">extension</span><span class="o">.</span><span class="n">Extension</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">module</span><span class="p">)</span>
<span class="n">extensions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">extension</span><span class="p">)</span>
<span class="k">return</span> <span class="n">extensions</span>
</code></pre></div></div>
<p><code class="highlighter-rouge">self._discover_via_python_path()</code> 会找以 <code class="highlighter-rouge">python_novaclient_ext</code> 结尾的 module</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">_discover_via_contrib_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">version</span><span class="p">):</span>
<span class="n">module_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">__file__</span><span class="p">))</span>
<span class="n">version_str</span> <span class="o">=</span> <span class="s">"v</span><span class="si">%</span><span class="s">s"</span> <span class="o">%</span> <span class="n">version</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">'.'</span><span class="p">,</span> <span class="s">'_'</span><span class="p">)</span>
<span class="n">ext_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">module_path</span><span class="p">,</span> <span class="n">version_str</span><span class="p">,</span> <span class="s">'contrib'</span><span class="p">)</span>
<span class="n">ext_glob</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ext_path</span><span class="p">,</span> <span class="s">"*.py"</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ext_path</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">iglob</span><span class="p">(</span><span class="n">ext_glob</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">ext_path</span><span class="p">)[:</span><span class="o">-</span><span class="mi">3</span><span class="p">]</span>
<span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s">"__init__"</span><span class="p">:</span>
<span class="k">continue</span>
<span class="n">module</span> <span class="o">=</span> <span class="n">imp</span><span class="o">.</span><span class="n">load_source</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">ext_path</span><span class="p">)</span>
<span class="k">yield</span> <span class="n">name</span><span class="p">,</span> <span class="n">module</span>
</code></pre></div></div>
<p>其中 <code class="highlighter-rouge">glob.iglob(ext_glob)</code> 会生成一个 iterator 循环所有 <code class="highlighter-rouge">contrib/*.py</code>,<code class="highlighter-rouge">imp.load_source(name, ext_path)</code> 再加载 module。</p>
<p>最后载入 Entry Points <code class="highlighter-rouge">novaclient.extensions</code>,参考 <a href="http://stackoverflow.com/a/9615473">http://stackoverflow.com/a/9615473</a></p>
Cntrains.com Docker 自动部署
2014-09-20T00:00:00+00:00
http://greenmooon55.com/cntrains
<p>很久之前就发现<a href="http://yupiao.info">余票信息网yupiao.info</a> 上能查到余票、正晚点、车次信息,作者还<a href="http://scatwang.com/index.php/2013/07/%E4%BD%99%E7%A5%A8%E5%92%8C%E9%93%81%E8%B7%AF%E5%9C%B0%E5%9B%BE%E7%9A%84%E9%82%A3%E7%82%B9%E4%BA%8B%E5%84%BF/">介绍了网站的实现</a>,我也想自己写一个相似的网站。想了很久都没有动手,几个月前突发奇想去找域名,刚好在 Godaddy 上搜到 cntrains.com 这个域名在拍卖,截止日期刚好是当天,于是我用底价就拍到了,好幸运:-)</p>
<p>买到之后闲置了很久,后来写了个抓盛名时刻表 rar 压缩包的东西。</p>
<p>网站:<a href="http://cntrains.com/smsk">cntrains.com/smsk</a></p>
<p>代码:<a href="http://github.com/greenmoon55/cntrains">github.com/greenmoon55/cntrains</a></p>
<p>##获取数据</p>
<p>这个,我不好意思叫爬虫。。盛名时刻表官方的下载地址很好搞到,从下载页面正则匹配一下就可以获取到最新的下载地址,直接 GET 就能下载到,下载地址里时包含发布时间的,我暴力了一下,找到的最旧的版本是去年的,可惜没有更早的。现在用 crontab 每小时查询一次。</p>
<p>##存储</p>
<p>最开始是把压缩包存在本地,然后用数据库记录下来,现在放在七牛云上了,每月免费配额很多,完全用不完,代码也好写。</p>
<p>##代码</p>
<p>代码是用 Django 写的,你可能想问了,为嘛用 Django 呢,就这么一个破网页,呃,因为公司有用到(<a href="https://github.com/openstack/horizon/">horizon</a>),顺便看看。</p>
<p>##服务器</p>
<p>最开始用的是Azure免费试用,最近刚刚换成DigitalOcean,DO在墙外要方便一点,感觉Azure还有点小问题,比如内网的DNS。DO看起来挺好用的,一个月5刀可以接受。</p>
<p>##Docker</p>
<p>嗯,这个是跑在 Docker 上的,有必要么?我只是跑着玩玩嘛。Dockerfile里主要就是 <code class="highlighter-rouge">pip install</code>了,另外还要自己起 cron。</p>
<p>玩了一下 Docker Hub 的 webhook,就是每次 push 的时候会 POST 一个 json 到自己指定的 URL,我在服务器上又起了个 python http server,接到这个请求就重新 pull image 再 run image。只要 push 就能自动部署啦,分分中搞定,有木有 Heroku 的感觉!</p>
<p>参考:<a href="http://nathanleclaire.com/blog/2014/08/17/automagical-deploys-from-docker-hub/">Automagical Deploys from Docker Hub</a></p>
<p>##未来</p>
<p>首先要把页面稍微改改,至少声明跟软件作者无关。其他功能嘛,暂时懒得弄,我最终目标时要做个自动更新带历史记录的火车时刻表,最好提供个API,其实和 yupiao.info 之前做的差不多,但是没空研究爬虫、验证码方面的东西,很可能会无限期推迟(但愿不会)。</p>
<p>监控和测试目前没有,可以考虑加上。</p>
<p>Docker Hub 支持 Automated Build,就是 push 到 GitHub 之后可以自动根据 Dockerfile build image,但是我有些文件不想传到 GitHub 上(密码、access key),不知道该怎么办,其实现在也不错了。</p>
<p>有个基于 Ubuntu 修改过的 Docker image <a href="https://registry.hub.docker.com/u/phusion/baseimage/">phusion/baseimage</a>,解决了一些问题,有 cron 和 ssh server,挺热门的。</p>
<p>部署方面,要看看 CoreOS,现在 DO 和 UStack 都支持了。现在还有一些 Docker container hosting 的公司,也就是说以后想部署服务,连 VM 都不用搞,直接 push docker image就可以。比如这两家:<a href="http://quay.io">Quay.io</a> 和 <a href="https://www.tutum.co">tutum</a></p>
<p>前几天看到陈沙克的<a href="http://weibo.com/1748606363/Bn9xq1zKh">这条微博</a>,感觉确实很多东西可以用 Docker 来搞了,没必要搞那些 VM 了。</p>
<p>zhxq 最近做了<a href="http://piao.today">票.今天</a>,能生成每小时余票趋势图,看起来好厉害~</p>
使 Cloud-init 只读取一次 Metadata
2014-07-04T00:00:00+00:00
http://greenmooon55.com/cloud-init-get-metadata-only-once
<p>Linux 的 <a href="https://launchpad.net/ubuntu/+source/cloud-init">cloud-init</a> 会在每次启动时运行,默认每次都会读取 metadata,如果 metadata service 挂掉了或者响应缓慢就会使虚拟机重启时花费很多时间,一般 metadata 也不会改变,Windows 上的 <a href="http://www.cloudbase.it/cloud-init-for-windows-instances/">cloudbase-init</a> 貌似就只会读一次。</p>
<p>只需配置<code class="highlighter-rouge">manual_cache_clean:True</code>,否则在 init-local 时会自动清除缓存,见<a href="https://github.com/number5/cloud-init/blob/d37e212159ee14ca859714a7473268717db93e88/bin/cloud-init#L233">代码</a>。</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="c"># The cache is not instance specific, so it has to be purged</span>
<span class="c"># but we want 'start' to benefit from a cache if</span>
<span class="c"># a previous start-local populated one...</span>
<span class="n">manual_clean</span> <span class="o">=</span> <span class="n">util</span><span class="o">.</span><span class="n">get_cfg_option_bool</span><span class="p">(</span><span class="n">init</span><span class="o">.</span><span class="n">cfg</span><span class="p">,</span>
<span class="s">'manual_cache_clean'</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">manual_clean</span><span class="p">:</span>
<span class="n">LOG</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">"Not purging instance link, manual cleaning enabled"</span><span class="p">)</span>
<span class="n">init</span><span class="o">.</span><span class="n">purge_cache</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">init</span><span class="o">.</span><span class="n">purge_cache</span><span class="p">()</span>
<span class="c"># Delete the non-net file as well</span>
<span class="n">util</span><span class="o">.</span><span class="n">del_file</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">path_helper</span><span class="o">.</span><span class="n">get_cpath</span><span class="p">(</span><span class="s">"data"</span><span class="p">),</span> <span class="s">"no-net"</span><span class="p">))</span>
</code></pre></div></div>
毕业设计
2014-06-24T00:00:00+00:00
http://greenmooon55.com/graduation-thesis
<p>还是写写毕设的过程吧。从选导师开始,这就是一个很烦的事情。因为热门导师有很多人选,三个志愿其实后两个完全没意义,我就三个都没要我。。还好最后我的导师还不错,很负责的,每一两周都检查我们的进度,提一些建议。</p>
<p>不想随便写个无聊的项目,最开始我的选择是Kaggle上的<a href="www.kaggle.com/c/expedia-personalized-sort">Personalize Expedia Hotel Searches - ICDM 2013</a>,导师觉得她也不熟,就换了个短文本聚类的题目,最开始的选题是《并行聚类算法在短小文本上的应用》,寒假的时候在家还在看谱聚类的算法,《A Tutorial on Spectral Clustering》(请Google)写得很详细,数学太烂了,看了点线性代数,还是看不懂,后来导师告诉我不用看证明了= =只实现出来就好。
接下来几个月就慢慢在意写代码的基础上实现了K-means、层次聚类和谱聚类,再通过WordNet获取相似度,最后就搞定了。。放弃了Hadoop相关的东西,所有内容都是导师提供的,创新性为0。这是<a href="https://speakerdeck.com/greenmoon55/ju-lei-fen-xi-zai-duan-xiao-wen-ben-shang-de-ying-yong">答辩PPT</a>。</p>
<p>最后一周的时候,导师叫我把传统文本聚类的向量空间模型也做出来,数据集是路透社经过处理后的一些向量,我还请了假写好代码之后发现求出的最佳聚类数目跟正确答案不匹配,又没有和原始数据的对应关系,根本没法debug。那个时候一个人在新租的房子里非常不爽,我的感受就像在做一个需求不清的项目,到了最后一刻又要改需求。反思之后,感觉我的整体毕设就是一直被导师push,像在完成一个作业一样,应该要反过来才对,最开始就应该好好研究一下我原始的选题,早一点要实验数据,早知道是这样的数据的话就应该很早放弃并行,这么点数据搞毛线啊。还有一点很不爽,就是没有去做数据的预处理,起初还想做twitter真实数据呢。。完全不可能。最后的东西只是在很烂的数据上跑了一下而已。</p>
<p>通过毕设了解一点学术圈了,就是不停地提出想法、做实验、发论文的样子。数据挖掘这边coding其实不太重要,数学不行寸步难行。最后写论文的时候花了很久,写到将近一万字到一万五千字是最艰难的,都不知道些什么好了,最后凑到两万多字,四十多页。假期在家看谱聚类的时候也很不爽的。。还想去嘉定看看大组答辩都有啥呢,那天没去,在印论文。</p>
<p>再列几个有价值的参考资料:</p>
<ul>
<li>
<p><a href="http://blog.pluskid.org/?page_id=78">漫谈 Clustering 系列</a> 对各种聚类算法都有介绍</p>
</li>
<li>
<p>Clustering Indices Bernard Desgraupes University Paris Ouest Lab Modal’X April 2013 介绍各种聚类评价方法</p>
</li>
<li>
<p><a href="http://book.douban.com/subject/3639345/">Web数据挖掘</a> 聚类算法介绍详细,译者还有sjtu的俞勇,不过翻译一般,有些词前后译文都不一样。。</p>
</li>
<li>
<p><a href="http://www.ruanyifeng.com/blog/2013/03/tf-idf.html">TF-IDF与余弦相似性的应用(一):自动提取关键词</a> 阮一峰的文章,我论文里的传统文本聚类就是在凑字数- -</p>
</li>
<li>
<p><a href="http://www.matrix67.com/blog/archives/5044">互联网时代的社会语言学:基于SNS的文本数据挖掘</a> M67很早以前写的,just for fun</p>
</li>
</ul>
<p>写论文的过程中Word仍然经常崩溃或者按了保存其实没存上,非常感谢Dropbox一直在备份,还保留历史记录。这次学到了Word自动加参考文献、给图片和表格加编号,还有用制表符给公式编号,以后估计也用不到了。</p>
死亡诗社
2014-03-31T00:00:00+00:00
http://greenmooon55.com/dead-poets-society
<embed src="http://player.youku.com/player.php/sid/XNjYwOTg0OTIw/v.swf" allowfullscreen="true" quality="high" width="480" height="400" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" />
<p></embed></p>
<p>寒假在家看超级碗广告的时候发现的这个 iPad 广告,太赞了,吸引我把<a href="http://movie.douban.com/subject/1291548/">电影</a>也看了,电影有点“痛斥美国教育”的感觉…里面的诗写得真好。</p>
<blockquote>
<p>We don’t read and write poetry because it’s cute. We read and write poetry because we are <strong>members of the human race</strong>. And the human race is filled with passion. And medicine, law, business, engineering, these are noble pursuits and necessary to sustain life. But poetry, beauty, romance, love, <strong>these are what we stay alive for</strong>.</p>
</blockquote>
<p>还有这一段</p>
<blockquote>
<p>To quote from Whitman, “O me! O life!… of the questions of these recurring; of the endless trains of the faithless… of cities filled with the foolish; what good amid these, O me, O life?” Answer. That you are here - that life exists, and identity; that the powerful play goes on and you may contribute a verse. That the powerful play goes on and you may contribute a verse. What will your verse be?</p>
</blockquote>
<p>电影里印象很深的还有这段,Mr.Keating 带学生看很多年前也在这所学校上学的学生的照片,这些照片就摆在楼下,现在的学生们每天匆匆走过,从不驻足。照片里的学生和现在的学生差不多,充满希望,不过现在他们已经离世了,最后到底有没有有所成就呢?</p>
<blockquote>
<p>They’re not that different from you, are they? Same haircuts. Full of hormones, just like you. Invincible, just like you feel. The world is their oyster. <strong>They believe they’re destined for great things, just like many of you, their eyes are full of hope, just like you.</strong> Did they wait until it was too late to make from their lives even one iota of what they were capable? Because, you see gentlemen, these boys are now fertilizing daffodils. But if you listen real close, you can hear them whisper their legacy to you. Go on, lean in. Listen, you hear it? - - Carpe - - hear it? - - <strong>Carpe, carpe diem, seize the day boys, make your lives extraordinary.</strong></p>
</blockquote>
<p>还有电影中评价诗的方法:完美程度为x轴、重要性为y轴,面积越大说明诗越好,真的是笑死了哈哈。于是老师直接让大家把这页书撕掉了。</p>
<p><a href="http://www.imdb.com/character/ch0004782/quotes">John Keating (Character) - Quotes - IMDB</a></p>
<p><a href="http://movie.douban.com/review/1690137/">残酷青春 (死亡诗社 影评) - 豆瓣</a></p>
烟花三月下扬州
2014-03-26T23:46:00+00:00
http://greenmooon55.com/yangzhou
<p>还记得小学时全班一起<strong>唱</strong>《黄鹤楼送孟浩然之广陵》</p>
<blockquote>
<p>故人西辞黄鹤楼,烟花三月下扬州,孤帆远影碧空尽,唯见长江天际流。</p>
</blockquote>
<p>古人用的是农历,我们三月去扬州的时候,瘦西湖好多花儿还没开,游客倒是已经有很多了。瘦西湖很大,和西湖相比,瘦西湖确实很瘦,感觉更像一条河,有“二十四桥”(<a href="http://baike.baidu.com/view/160007.htm">寄扬州韩绰判官</a>,<a href="http://baike.baidu.com/view/2753818.htm">扬州慢·淮左名都</a>),有亭台楼阁,有假山瀑布,还有古时的城墙。</p>
<p><img src="/images/yangzhou1.jpg" alt="" /></p>
<p><img src="/images/yangzhou2.jpg" alt="" /></p>
<p><img src="/images/yangzhou3.jpg" alt="" />
湖心岛上的小径,挺有感觉的</p>
<p><img src="/images/yangzhou4.jpg" alt="" />
从大明寺景区拍瘦西湖,到处都在施工,整个扬州也是,搞得很多尘土。另外看到在修下穿瘦西湖的隧道。</p>
<p><img src="/images/yangzhou5.jpg" alt="" />
个园,有各种竹子,中国四大名园之一。有很多竹子、假山,四季风景。江南的园林还挺有意思。</p>
<p><img src="/images/yangzhou6.jpg" alt="" /></p>
<p><img src="/images/yangzhou7.jpg" alt="" />
何园,刚好赶上人家拍婚纱照,这个角度好漂亮。</p>
<p><img src="/images/yangzhou8.jpg" alt="" />
别有洞天</p>
<p><img src="/images/yangzhou9.jpg" alt="" />
复道回廊,走廊连通着各个房子</p>
<p><img src="/images/yangzhou10.jpg" alt="" />
文昌阁</p>
<p><img src="/images/yangzhou11.jpg" alt="" />
东关街上一家很精致的贺卡店,这些贺卡都能折起来的哦</p>
<p><img src="/images/yangzhou12.jpg" alt="" /></p>
<p><img src="/images/yangzhou13.jpg" alt="" />
瓜州(泊船瓜州)镇杨汽渡,24小时不断</p>
<p>古代的扬州多么繁华,才有了现在这些园林,当年的扬州可能是现在的南京、上海,可惜随着航运的衰落,扬州不再那么重要,感觉城市建设完全比不上苏州。</p>
<p>扬州是个很特别的城市,景点和美食都值得一去,淮扬菜比较清淡,我喜欢,还没吃够,希望有机会再来。不过扬州炒饭没觉得很特别。这次和童鞋们玩得很开心:)</p>
<p>乘坐 CRH2-075C 和 CRH2-076C 往返,还是比普速快多了,这次发现花钱换时间还是很爽的…比如说打车、乘高铁。</p>
20140215
2014-02-15T01:25:00+00:00
http://greenmooon55.com/140215
<p>时间过得太快啦!转眼间已经过了十五。在家里过了学生时代最后一个寒假,总结一下都干了啥。每次假期最后一天都会很后悔时间利用不够好,当然这次也不例外。</p>
<p>1月19号下午到家,2月8号走,约三周。</p>
<p>20略,23见同学看了kmeans,24-26搞定100行的代码,这一周时间利用还可以。</p>
<p>第二周最不爽了,看线代教材看不下去,上网找视频看,看了一段时间又觉得看不完,又回来看书,浪费了很多时间。。导致过年的时候心情不太好。而且其中很长时间都在玩游戏…以后注意..</p>
<p>最后一周没什么,对于我来说过年区别不大,家里聚聚,跟同学吃吃饭,很快就过去了。值得一提的是三个人一起去了趟烟筒山,这种运转的机会不知道以后还有吗= = 另外我找了几个好久没见的高中同学,财富广场真不错,连高中时在北京吃的比格比萨自助都有..为啥我高中、初中、小学都没人组织聚会呢…真神奇= =!吉林这次有了山寨无印良品风格的店,全场十元…</p>
<p>越长大越想家哈,以后估计只有十一和春节会回家…大概就是飞机回吉林,Z62+G1 或 T60+G13 回上海吧,火车的话就末班高铁到北京然后换临D(如果有的话),这样会累死吧。</p>
最小树形图
2013-12-22T13:31:00+00:00
http://greenmooon55.com/directed-minimum-spanning-tree
<p>参考资料:</p>
<ul>
<li><a href="http://www.cs.princeton.edu/courses/archive/spring13/cos528/directed-mst-1.pdf">Lecture notes on “Analysis of Algorithms”: Directed Minimum Spanning Trees</a></li>
<li><a href="http://www.csie.ntnu.edu.tw/~u91029/SpanningTree.html#5">演算法筆記 - Spanning Tree</a></li>
</ul>
<p>先翻译一部分上面的 Lecture notes:</p>
<p>最小树形图也就是有向最小生成树。如果有向加权图 G 有子图 T,T 中从某个结点 r 可以到达全部其他结点,并且若这些边是无向边,T 就是最小生成树的话,那么 T 就是 G 上以 r 为根的有向生成树。最小有向生成树就是有向生成树中边权值的和最小的那个。(有点晕。。)</p>
<p><strong>引理 1.1</strong> 以下条件等价:</p>
<ol>
<li>T 是 G 的以 r 为根的有向生成树</li>
<li>r 在 T 中的入度为 0,其它边在 T 中的入度是 1,且 T 是无环的。</li>
<li>r 在 T 中的入度为 0,其它边在 T 中的入度是 1,T 中从 r 到其他任意结点都有有向路径</li>
</ol>
<p><strong>推论 1.2</strong></p>
<p>设 T 是以 r 为根的有向生成树,设 (u,v) 是不在 T 中的一条边,且 v != r,u 不是 T 中 v 的后续结点(后续结点的意思是 T 中从 v 到 u 有路径),设 (u’, v) 是 T 中终点为 v 的(唯一的)边。那么把 T 加上 (u,v) 去掉 (u,v’) 仍然是一个 r 为根的有向生成树。</p>
<p><strong>定理 4.1</strong></p>
<p>设 G=(V, E, w)是加权有向图,设 r 在 V 中。设 C 是一个不包含 r 的由最小的入边构成的边集。那么,存在一个最小有向生成树,包含 C 中去掉一条边后剩余的边。</p>
<p>证明:设 T 是 G 中以 r 为根的最小有向生成树。设 v1 是 C 中的点,且 T 中从 r 到 v1 不经过 C 中其他的边。(一定至少存在一个点,比如 C 中在 T 上最接近 r 的点中的一个。)按照环上的顺序,设 v1, v2, .., vk 是 C 中的点。如果 (v1, v2), (v2, v3), …, (vk - 1, vk) 属于T,我们就搞定了。不过,假设存在某个 i < k,(v1, v2), (v2, v3), …, (vi - 1, vi) 属于 T,而 (vi, vi + 1) 不属于T。设 T 中 vi + 1 的入边为 (u, vi + 1)。vi 在 T 中的上游结点是 T 中从 r 到 v1 这些结点和 C 上的 v1, v2, …, vi - 1,所以 vi 不是 vi + 1 的下游结点(descendents…)。根据推论1.2,T 去掉 (u, vi + 1) 加上 (vi, vi + 1) 仍然是一个以 r 为根的生成树,记为T‘。既然 (vi, vi + 1) 是进入 vi + 1 的最短边,T’ 也是以 r 为根的最小有向生成树。一直这样做,我们就能构造一个以 r 为根,包含 C 中除了 (vk, v1) 之外所有边的最小有向生成树。</p>
<p>接下来说说做法,根据上面的定理:</p>
<ol>
<li>找除了根节点外其他点的最小入边,如果哪个点没有,就说明无解</li>
<li>看看现在是否有环,如果无环则找到解了,记录当前选择的所有边的权值和,作为答案。</li>
<li>把环缩点,设 u 是不在环上的点,v 是在环上的点,minEdgeDis[v] 表示 v 的最短入边的权值,那么把边 (u, v) 的权值减去 minEdgeDis[v]。把环上所有的点合并为同一个点。回到第一步。</li>
</ol>
<p>曾经2011年大连网络赛就出了这个算法的模板题 <a href="http://acm.hdu.edu.cn/showproblem.php?pid=4009">HDU 4009 Transfer Water</a>,当时好像是 yds 远程过的…我到现在还没去做这道题。</p>
Debian Wheezy 使用 oh-my-zsh 的小问题
2013-12-22T13:26:00+00:00
http://greenmooon55.com/oh-my-zsh-on-debian
<p>最近发现默认的 Shell(应该是 bash)有点小问题,果断换成 zsh,装了 oh-my-zsh 之后发现每次开启终端都会显示类似环境变量的东西</p>
<p>查了半天问题在哪,发现是在 <code class="highlighter-rouge">~/.oh-my-zsh/oh-my-zsh.sh</code> 里:</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Check for updates on initial load...</span>
<span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$DISABLE_AUTO_UPDATE</span><span class="s2">"</span> <span class="o">!=</span> <span class="s2">"true"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
/usr/bin/env <span class="nv">ZSH</span><span class="o">=</span><span class="nv">$ZSH</span> <span class="nv">DISABLE_UPDATE_PROMPT</span><span class="o">=</span><span class="nv">$DISABLE_UPDATE_PROMPT</span> zsh <span class="nv">$ZSH</span>/tools/check_for_upgrade.sh
<span class="k">fi</span>
</code></pre></div></div>
<p>执行 <code class="highlighter-rouge">/usr/bin/env</code> 的时候会输出这些东西。解决办法就是在第三行重定向输出:</p>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/usr/bin/env <span class="nv">ZSH</span><span class="o">=</span><span class="nv">$ZSH</span> <span class="nv">DISABLE_UPDATE_PROMPT</span><span class="o">=</span><span class="nv">$DISABLE_UPDATE_PROMPT</span> zsh <span class="nv">$ZSH</span>/tools/check_for_upgrade.sh &>/dev/null
</code></pre></div></div>
Horizon 中 Python 元编程的例子
2013-11-27T00:00:00+00:00
http://greenmooon55.com/python-metaprogramming-example-in-horizon
<p>Horizon 中创建虚拟机的 workflows 里面有这样一个类,用来选择虚拟机的一些信息,比如配置。<a href="https://github.com/openstack/horizon/blob/cde81c38027b17014abcd1449a263bdc411503cc/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py#L170">GitHub代码</a></p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">SetInstanceDetailsAction</span><span class="p">(</span><span class="n">workflows</span><span class="o">.</span><span class="n">Action</span><span class="p">):</span>
</code></pre></div></div>
<p>里面有这几个方法</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">populate_image_id_choices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
<span class="n">images</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_available_images</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span>
<span class="n">choices</span> <span class="o">=</span> <span class="p">[(</span><span class="n">image</span><span class="o">.</span><span class="nb">id</span><span class="p">,</span> <span class="n">image</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="k">for</span> <span class="n">image</span> <span class="ow">in</span> <span class="n">images</span>
<span class="k">if</span> <span class="n">image</span><span class="o">.</span><span class="n">properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"image_type"</span><span class="p">,</span> <span class="s">''</span><span class="p">)</span> <span class="o">!=</span> <span class="s">"snapshot"</span><span class="p">]</span>
<span class="k">if</span> <span class="n">choices</span><span class="p">:</span>
<span class="n">choices</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="p">(</span><span class="s">""</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">"Select Image"</span><span class="p">)))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">choices</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="p">(</span><span class="s">""</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">"No images available."</span><span class="p">)))</span>
<span class="k">return</span> <span class="n">choices</span>
<span class="k">def</span> <span class="nf">populate_instance_snapshot_id_choices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
<span class="o">.</span>
<span class="o">.</span>
<span class="o">.</span>
<span class="k">def</span> <span class="nf">populate_flavor_choices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
<span class="o">.</span>
<span class="o">.</span>
<span class="o">.</span>
</code></pre></div></div>
<p>这几个方法是用来填充一些页面上的选择框的,看来看去不知道是在哪里被调用的。</p>
<p>于是找父类 <a href="https://github.com/openstack/horizon/blob/cde81c38027b17014abcd1449a263bdc411503cc/horizon/workflows/base.py#L77">workflows.Action</a></p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">_populate_choices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
<span class="k">for</span> <span class="n">field_name</span><span class="p">,</span> <span class="n">bound_field</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">meth</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s">"populate_</span><span class="si">%</span><span class="s">s_choices"</span> <span class="o">%</span> <span class="n">field_name</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">meth</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="nb">callable</span><span class="p">(</span><span class="n">meth</span><span class="p">):</span>
<span class="n">bound_field</span><span class="o">.</span><span class="n">choices</span> <span class="o">=</span> <span class="n">meth</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span>
</code></pre></div></div>
<p>哈,原来在这里,看出来做什么了吧。太具体的我也还没研究= =</p>
<p>最后,在 <code class="highlighter-rouge">__init__</code> 中有一行。</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="bp">self</span><span class="o">.</span><span class="n">_populate_choices</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span>
</code></pre></div></div>
<p>看大牛写的高质量代码也有点意思,我想吐槽貌似 Django 的文档不够全面啊,至少跟 Rails 比。</p>
实习感受131127
2013-11-27T00:00:00+00:00
http://greenmooon55.com/intern-at-ctrip
<p>前段时间换了地方实习,现在在携程待了半个多月,我们组主要是做内部的 IAAS,更具体的说貌似只是给其他组分配虚拟机。。最近主要看了 Python, Django 和 Openstack Horizon,Horizon 是基于 Django 的,然后调用 Nova 的 API,Nova 再去用具体的虚拟化技术分配虚拟机,比如 VMware vSphere 和 KVM。刚开始觉得 Python 不太习惯,缩进有点丑,很多地方没有 Ruby 舒服,现在习惯多了。</p>
<p>现在还没什么事情做,没写代码也动力不大,感觉我用了不到百分之七八十的精力。其实对组里具体事情还不了解,晨会都没有,希望下个月能逐渐熟悉起来。现在看起来还不错,就是写代码有点少。= =不知道这个方向是不是有点窄?前两天把三方交给学院,发现我是第一个交的。。</p>
<p>携程让人很不爽的地方就是办公区域太小了,甚至比寝室的桌子还小,过道也很窄。Outlook 没 Gmail 好用,我自己加了存档和星标凑合用,Outlook 跟 Lync 集成看在线状态不错,不过 Lync 没 QQ 好用。</p>
<p>这边同事看起来更 geek 一点,天天玩魔方、用 Vim、看 The Old Reader 等等。这边的电脑也爽多了,下载速度跟寝室差不多,22 寸显示器。还是想吐槽点评几十K的下载速度,下个 Eclipse 都花了好几个小时,网速差都没有加班的动力啊。</p>
<p>当时也可以留在点评的,面试真是个神奇的事情,当年面实习生,跟我水平差不多的同学挂了,我比较轻松地进来,都没问什么问题,转正面试也感觉还好啊,结果几乎挂掉= = 转正面的面试官让我意识到产品有多么重要,其实我花时间做得那个小工具并不是真正需要的东西,不过让我做的 PM 也没说什么嘛= = 我自己确实没想太多。</p>
<p>很怀念点评那边的氛围,就像大学里的朋友一样~点评的工作环境也很赞,在创意园区里,,我觉得比百度都好,虽然百度每个人的空间大一点。组里希望把每个人培养成 full-stack 工程师。</p>
<p>我觉得不好的地方</p>
<ol>
<li>
<p>对这个东西是在没有太大兴趣= = 不想去深入了解 Spring,Struts,当时学校上课就没兴趣</p>
</li>
<li>
<p>做业务很多人用可能很有成就感,很好玩。听过产品的分享,感觉产品的整体思路很棒,但是,我不是 PM,很多细节不够好,我觉得不能接受,不应该上线,就算是 MVP 也要把体验做到比较好才行啊。这里只说消费的一般用户用到的,比如:</p>
<ol>
<li>
<p>刚开始的时候首页的餐厅预定时间选择是无效的,到了商户页还要再选一遍。有种被耍了的感觉</p>
</li>
<li>
<p>6.0 还没出来的时候首页上就有下载的广告,点开会发现还是旧版</p>
</li>
<li>
<p>这个只是我自己想的,可能产品有自己的想法。团购评价和商户评价没合并,很麻烦</p>
</li>
<li>
<p>对了,预定抽奖的抵用券在团购里没显示,得自己输入号码。。还有细节问题,鼠标不能点的信誉值星级还是手形指针。</p>
</li>
</ol>
</li>
<li>
<p>改 bug 不够快,大概十月份同学提了个bug,后来发现八月论坛上就有报告。我离职两周前提了公司地图位置标错,走的时候也没改= = 而且不够处女座啊,注意点细节好么。</p>
</li>
<li>
<p>比较辛苦啊,我觉得每天工作到八九点,回家哪还有心情去学其他技术了,我还想学点工作上用不到的呢,天天这么写业务,我怕一年后我就开始不想写代码了。。</p>
</li>
<li>
<p>虽然没认真看代码,但是感觉代码质量不会很高的</p>
</li>
</ol>
<p>需求经常变,这是不可避免的= =,我还是想,能不能变得少一点?能不能在 sprint 开始前明确需求?能不能慢一点,体验做得好一点?刚好看到 Fenng 小道消息的<a href="http://zhuanlan.zhihu.com/WebNotes/19624175">《试错》</a></p>
<p>最后再写下我找工作的标准吧:</p>
<ol>
<li>
<p><strong>Do cool things that matter</strong> (via <a href="http://www.google.com/about/jobs/lifeatgoogle/do-cool-things-that-matter.html">Google</a>),这个很难定义啊,以后每天大部分时间都在工作,千万不要做得很不爽。</p>
</li>
<li>
<p>不要太辛苦= = 点评的工作时间已经是我的极限了,不要 996 啊= =</p>
</li>
<li>
<p>薪水</p>
</li>
</ol>
<p>虽然没认真想过,之前的目标大概是毕业的时候有一线的互联网企业的水平吧,完全没达到啊。上半年找实习的时候发现有点难,然后就想去点评或者百姓网了。现在在携程感觉也还不错,今年应该不会再有面试了。</p>
<p>十一之前注册了携程,定了个旅店,付款后第二天上午告诉我没定成,垃圾邮件总是退订失败。去哪儿有百度支持,也招很多牛人,觉得携程可能没有互联网基因吧,看起来最近转型还不错,以后就算去哪儿发展特别好,携程也能是市场第二吧。</p>
<p>我 06 年就注册了点评,阿里的口碑没打过,网易、百度做得类似的东西也不行。点评只是移动端的入口比较弱,挺看好点评的。</p>
<p>终于写了这篇,以后看肯定会觉得现在很幼稚。。留此存照= =</p>
Skip List 的应用
2013-10-26T00:00:00+00:00
http://greenmooon55.com/skip-list
<p>首先这里是 <a href="http://www.redisbook.com/en/latest/internal-datastruct/skiplist.html">skip list</a> 的介绍。</p>
<h1 id="redis-sorted-set">Redis Sorted Set</h1>
<p>之前用 Redis 的 Sorted Set 存在线用户。</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># key, score, member</span>
<span class="vg">$redis</span><span class="p">.</span><span class="nf">zadd</span><span class="p">(</span><span class="s1">'online-users'</span><span class="p">,</span> <span class="no">Time</span><span class="p">.</span><span class="nf">now</span><span class="p">.</span><span class="nf">to_i</span><span class="p">,</span> <span class="n">current_user</span><span class="p">.</span><span class="nf">id</span><span class="p">)</span>
</code></pre></div></div>
<p>查询某用户最后访问的时间</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">last_seen</span> <span class="o">=</span> <span class="vg">$redis</span><span class="p">.</span><span class="nf">zscore</span><span class="p">(</span><span class="s2">"online-users"</span><span class="p">,</span> <span class="nb">self</span><span class="p">.</span><span class="nf">id</span><span class="p">)</span>
</code></pre></div></div>
<p>ZADD 的复杂度是 O(log(N)),ZSCORE 的复杂度是 O(1)。</p>
<p>ZSET 是由一个 dict 和 skip list 实现的。dict 是一个根据 member 生成的哈希表,所以 ZSCORE 的复杂度是 O(1),ZADD 还需插入到 skip list 里所以需要 O(log(N))。</p>
<p>这个 skip list 是根据 score 排序的,所以根据 score 找 member 的复杂度是 O(log(N)),用于 ZRANK 等命令。</p>
<p><a href="http://www.redisbook.com/en/latest/datatype/sorted_set.html">有序集 — Redis 设计与实现</a></p>
<h1 id="倒排索引">倒排索引</h1>
<p>前几天在公司听了搜索的分享,才知道这个东西。
<a href="http://zh.wikipedia.org/wiki/%E5%80%92%E6%8E%92%E7%B4%A2%E5%BC%95">维基百科</a></p>
<p>比如有两个到排索引,一个是“五角场”,另外一个是“火锅”。那在搜索“五角场 火锅”的时候就要合并这两条链,找出两条链上相同的节点。</p>
<p>如果是普通的链表的话,效率是 O(M + N)。skip list 在合并时,如果另外那个表跳跃过去的节点仍然小于当前表的节点,中间的节点就不用考虑了。</p>
Bash 找出最大的数
2013-10-25T00:00:00+00:00
http://greenmooon55.com/bash-command-in-interview
<p>随机生成一些数据</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>
<span class="k">for </span>i <span class="k">in</span> <span class="o">{</span>1..10<span class="o">}</span>
<span class="k">do
</span><span class="nb">printf</span> <span class="s2">"%d</span><span class="se">\t</span><span class="s2">%d</span><span class="se">\n</span><span class="s2">"</span> <span class="nv">$i</span> <span class="nv">$RANDOM</span>
<span class="k">done</span>
</code></pre></div></div>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>1 2879
2 28792
3 91
4 23059
5 8242
6 13228
7 31060
8 12015
9 25696
10 27964
</code></pre></div></div>
<p>现在要找出右边第三大的数</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sort -k2 -n -r temp.txt | sed -n '3p'
</code></pre></div></div>
<ul>
<li>-k2 说明按第二列排序</li>
<li>-n 说明当作数字排序</li>
<li>-r 说明由大到小</li>
</ul>
<p>详见 <a href="http://explainshell.com/explain?cmd=sort+-k2+-n+-r+temp.txt+%7C+sed+-n+%273p%27">explainshell.com</a></p>
<p><a href="http://coolshell.cn/articles/9104.html">sed 简明教程 酷壳 - CoolShell.cn</a></p>
<p>这是百度的面试题和某公司的笔试题</p>
面试问题1
2013-10-07T00:00:00+00:00
http://greenmooon55.com/interview-1
<p>#初面</p>
<h2 id="new和malloc的区别">new和malloc的区别</h2>
<p>http://stackoverflow.com/questions/240212/what-is-the-difference-between-new-delete-and-malloc-free</p>
<table>
<thead>
<tr>
<th>New</th>
<th>Malloc</th>
</tr>
</thead>
<tbody>
<tr>
<td>失败时抛出异常</td>
<td>返回 NULL</td>
</tr>
<tr>
<td>Free Store</td>
<td>Heap</td>
</tr>
<tr>
<td>可重载</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="进程静态区存了什么">进程静态区存了什么</h2>
<p>全局变量和静态变量?</p>
<p>Data Segment (Data(variables, string literals) + BSS + Heap)<br />
Stack<br />
Code segment</p>
<p>http://en.wikipedia.org/wiki/Data_segment</p>
<p>text(program code) data bss heap stack</p>
<h2 id="进程和线程的区别">进程和线程的区别</h2>
<p>没想到被问到这种问题…</p>
<p>一个进程可能有多个线程
共享代码段、数据段</p>
<p>真不知道说什么…</p>
<p>##Web相关,比如(网站)安全、性能优化</p>
<p>CDN、缓存、前端优化,这个当时应该多说一些</p>
<h2 id="查找和排序的关系">查找和排序的关系</h2>
<p>不知所云</p>
<h2 id="链表和数组区别">链表和数组区别</h2>
<p>略</p>
<h2 id="树二叉树的有哪些应用">树、二叉树的有哪些应用?</h2>
<p>树:B树 数据库</p>
<p>二叉树:平衡二叉树:C++ std::map</p>
<h2 id="重载和多态区别">重载和多态区别</h2>
<p>override, overload, polymorphism 这几个词要搞清楚…</p>
<p>http://stackoverflow.com/questions/12893907/is-polymorphism-overloading-and-overriding-are-same-concepts</p>
<p>Polymorphism can be achieved through overriding.<br />
Method Overriding<br />
Method Overloading<br />
Operator Overloading</p>
<h2 id="tcp-udp-区别">TCP UDP 区别</h2>
<p>TCP 三次握手保证传输<br />
UDP best-effort 不保证一定发过去,开销小<br />
视频用UDP,HTTP用UDP。</p>
<p>TCP: connection oriented<br />
UDP: datagram oriented 不保证传输顺序</p>
<h2 id="共30万个url每个占空间256bytesunicode任意给出一个url判断是否在里面">共30万个url,每个占空间256bytes(unicode),任意给出一个url,判断是否在里面</h2>
<p>十分钟写思路</p>
<p>我的想法:hash然后二分查找…当时应该问问正解怎么做…</p>
<h1 id="二面">二面</h1>
<h2 id="c和c有什么区别">C++和C有什么区别</h2>
<p>去死吧…</p>
<p>C++ 面向对象,有类的概念。<br />
C++ 有 STL,有 template,有异常处理</p>
<p>然后我就说不出啥了…</p>
<p>额,new/delete,运算符重载…</p>
<h2 id="既然有gcjava会不会出现内存泄露什么时候会出现gc的原理">既然有GC,Java会不会出现内存泄露,什么时候会出现?GC的原理</h2>
<p>不知道…</p>
<p>如果一个对象 = null 了就可以被回收了吧。如果在某个循环里生成很多的对象,存到循环外的某个容器里,这样就会内存泄露吧。</p>
<p>http://www.ibm.com/developerworks/cn/java/l-JavaMemoryLeak/</p>
<h2 id="本专业四年学了什么-大学里最大的收获-最重要的两门专业课是什么">本专业四年学了什么 大学里最大的收获 最重要的两门专业课是什么</h2>
<h2 id="有没有自己课外做的东西非实习非课程项目非外包">有没有自己课外做的东西(非实习、非课程项目、非外包)</h2>
Const Reference To Pointer
2013-09-21T00:00:00+00:00
http://greenmooon55.com/const-reference-to-pointer
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">struct</span> <span class="n">mycomp</span> <span class="p">{</span>
<span class="kt">bool</span> <span class="k">operator</span><span class="p">()(</span><span class="n">ListNode</span> <span class="o">*</span> <span class="k">const</span> <span class="o">&</span><span class="n">a</span><span class="p">,</span> <span class="n">ListNode</span> <span class="o">*</span> <span class="k">const</span> <span class="o">&</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="o">-></span><span class="n">val</span> <span class="o">></span> <span class="n">b</span><span class="o">-></span><span class="n">val</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">};</span>
</code></pre></div></div>
<p>上学期 euyuil 曾经讲过这方面的东西,现在终于用到了。之前一直写成 <code class="highlighter-rouge">const ListNode *</code>,还不明白为什么不对。</p>
<p>这里重载括号也挺有意思,这种东西叫做 functor,我还没想明白为什么不能直接传名为 mycomp 的函数过去。</p>
<p><a href="http://www.learncpp.com/cpp-tutorial/99-overloading-the-parenthesis-operator/">9.9 — Overloading the parenthesis operator « Learn C++</a></p>
<p>LeetCode 很不错,网页上的代码编辑器做得相当好,和本地的 CodeBlocks 差不多了。写 C++ 也想把左括号放到行尾了,可惜 CodeBlocks 自动缩进有问题。</p>
MyBatis 与 MySQL Timestamp 类型的问题
2013-08-23T00:00:00+00:00
http://greenmooon55.com/mybatis-timestamp
<p>正常使用时,找不到对应的记录,MyBatis 的日志是这样的。</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[DEBUG] 25:52/(BaseJdbcLogger.java:debug:132)
==> Preparing: SELECT COUNT(id) FROM paths WHERE task_id = ? AND time = ?
[DEBUG] 25:52/(BaseJdbcLogger.java:debug:132)
==> Parameters: 255103(Integer), 2013-08-22 13:40:02.208(Timestamp)
</code></pre></div></div>
<p>根据 <a href="http://dev.mysql.com/doc/refman/5.5/en/datetime.html">MySQL 的官方文档</a></p>
<blockquote>
<p>TIMESTAMP has a range of ‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTC.</p>
</blockquote>
<p>经过测试,把毫秒设为 0 就能正常查找了,也就是<code class="highlighter-rouge">2013-01-01 02:03:04.000</code>。</p>
<p>MyBatis 挺好用的,据说公司里用得挺多的。(我还是不想写 Java = =)</p>
20130822上海地铁服务中断
2013-08-22T00:00:00+00:00
http://greenmooon55.com/130822-shmetro-service-outage
<p>八点十几分进入地铁站,准备 2 换 4 到中山公园,海伦路下楼梯的时候听到广播 4 号线延误,果断返回乘坐十号线,坐到了之前那趟 10 号线后面的第二班车。耽误了 10 分钟的时间。走到十号线站台才听到这边的广播说<a href="http://www.shmetro.com/dtyy2010/wdzm_detail.jsp?id=1446">4号线故障</a>。我在换乘通道里刷了一下微博,9 分钟之前就有故障告知,“上海发布”在三分钟之前转发了。看来地铁站反应还没微博快,感觉二号线客流比平时多。</p>
<p>晚上回来,南京东路站台电视上提示由于车门故障,国权路到江湾体育场运行延误。没有任何广播通知,估计是当时基本解决了。</p>
<p>我有个想法是抓取“上海metro”的微博,如果有“突发运营信息”之类的词语就推送给用户。。其实安卓版上海地铁官方应用是有这个功能的,还可以选择推送的线路,不过我这边永远是空白,不知道 iOS 怎么样。</p>
<p>九点多点的时候,中山公园换乘通道已经被完全封锁,凯旋路上有些打车的。中山公园站停着一辆内圈四号线,车内没有照明。</p>
<p>BTW,晚上回来遇到一班终点为龙阳路的二号线,这是要收车了吧。</p>
实习感受
2013-08-19T00:00:00+00:00
http://greenmooon55.com/intern-at-dianping
<p>实习两周了,虽然面试时选的是前端,入职之后发现其实主要是做 Java EE 的,对前端的要求不高,team 里没有专职的前端,大家都来写。现在仍然处于打杂阶段,都是自己一个人写小项目。</p>
<h2 id="好的地方">好的地方</h2>
<ul>
<li>
<p>环境不错,在一个创意园区</p>
</li>
<li>
<p>氛围挺好,一个团队的人挺像学校里的同学。我们是做新业务,也稍微有点 Startup 的感觉</p>
</li>
<li>
<p>用到了一点比较新的东西,比如内部的 GitLab,我们 team 也用到了 MongoDB。下周还有 Hackathon</p>
</li>
<li>
<p>使用 Google Apps</p>
</li>
</ul>
<h2 id="不好的地方">不好的地方</h2>
<ul>
<li>
<p>好辛苦,感觉经常加班的样子,特别是我们 team,我两次在公司吃完饭,发现貌似我们组里走得都很晚,Line Manager 曾经跟我说有时会加班到晚上九十点钟,貌似周末还有人来加班。</p>
</li>
<li>
<p>网速好慢,肯定到不了 100kb/s,这还是互联网公司?</p>
</li>
<li>
<p>木有免费的饮料</p>
</li>
<li>
<p>不想写 Java… 用到各种库、写配置文件,遇到很多莫名其妙的 bug</p>
</li>
<li>
<p>工作时用到 QQ,难道不怕腾讯获取聊天记录?或许这也是公司里 Linuxer 不多的原因?</p>
</li>
<li>
<p>或许因为赶进度代码质量不够好,上周差不多每天线上都有 bug 要去做 hotfix…</p>
</li>
</ul>
迁移到 Jekyll
2013-08-11T00:00:00+00:00
http://greenmooon55.com/migrating-to-jekyll
<p>Wordpress 放在虚拟主机上太慢了,影响写作欲望…</p>
<p>迁移进行中,预计会持续很久。。</p>
Codeforces Round #191 (Div. 2)
2013-07-13T02:35:58+00:00
http://greenmooon55.com/codeforces-round-191-div-2
<p>比赛是在嘉定做的,只做了A,rating掉到历史新低= =</p>
<h1 id="a-flipping-game">A. Flipping Game</h1>
<p>n个0或1,从中任选i,j,翻转从i到j的数(变成x-1),求最长连续的1。由于n很小(100),直接模拟即可。</p>
<h1 id="b-hungry-sequence">B. Hungry Sequence</h1>
<p>输出一个递增的序列,要求任意一项不能被其他项整除。序列长度最大为10^5,每个数字不能超过10^7。</p>
<p>如果全部输出质数就是符合条件的,比赛的时候脑残以为质数不够,所以乱搞的,现在看来貌似不太对。。</p>
<h1 id="c-magic-five">C. Magic Five</h1>
<p>给出一个数字,可以去掉任意个digit,不能全部去掉,可以有leading zero,问能有多少种情况使处理后的数字能被5整除。</p>
<p>这个思路很明显,就是找5和0,然后乘以2^i,i为前面的位数。但是实现上有一些问题。</p>
<p>(ans = 2^i + 2^{l+i} + 2^{2l+i} + … + 2^{(k-1)l+i})</p>
<p>(ans = 2^i * (1 + 2^{l} + 2^{2l} + … + 2^{(k-1)l}))</p>
<p>(1 + 2^{l} + 2^{2l} + … + 2^{(k-1)l} = \frac{2^{k*l}-1}{2^l-1} )</p>
<p>现在的重点就是求出(\frac{2^{k*l}-1}{2^l-1} )</p>
<p>可以根据费马小定理什么的把(\frac{a}{b} \mod{p})转换成(a* b^{p-2} \mod {p})
但是这里有些问题,我还不太理解证明的过程,比如说费马小定理要求b与p互质,这里没法证吧= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXA</span> <span class="o">=</span> <span class="mi">100005</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MOD</span> <span class="o">=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">pow</span><span class="p">(</span><span class="kt">long</span> <span class="kt">long</span> <span class="n">a</span><span class="p">,</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">b</span><span class="p">,</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">mod</span> <span class="o">=</span> <span class="n">MOD</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//cout << a << " ^ " << b << " = ";
</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">b</span> <span class="o">&</span> <span class="mi">1</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">*</span> <span class="n">a</span><span class="p">)</span> <span class="o">%</span> <span class="n">mod</span><span class="p">;</span>
<span class="n">b</span> <span class="o">>>=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">a</span> <span class="o">=</span> <span class="p">(</span><span class="n">a</span> <span class="o">*</span> <span class="n">a</span><span class="p">)</span> <span class="o">%</span> <span class="n">mod</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//cout << ans << endl;
</span> <span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">string</span> <span class="n">str</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">k</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">str</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="n">str</span><span class="p">.</span><span class="n">length</span><span class="p">();</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">l</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">str</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'5'</span> <span class="o">||</span> <span class="n">str</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'0'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">+</span> <span class="n">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">ans</span> <span class="o">*</span> <span class="p">(</span><span class="n">pow</span><span class="p">((</span><span class="n">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">),</span> <span class="n">l</span><span class="p">)</span> <span class="o">%</span> <span class="n">MOD</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">MOD</span><span class="p">)</span> <span class="o">%</span> <span class="n">MOD</span> <span class="o">*</span> <span class="n">pow</span><span class="p">((</span><span class="n">pow</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">),</span> <span class="n">MOD</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<h1 id="d-block-tower">D. Block Tower</h1>
<p>对于每个联通块,可以先全部涂成蓝色,然后只保留一个为蓝色(我选的是第一个),其他都换成红色。
刚开始我用了BFS,而且还用了deque、struct Point,结果segmentation fault = =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">505</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">map</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">Operation</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">operation</span><span class="p">;</span>
<span class="p">};</span>
<span class="n">queue</span> <span class="n">ansq</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">ans</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="n">y</span><span class="p">,</span> <span class="kt">char</span> <span class="n">operation</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">Operation</span> <span class="n">op</span><span class="p">;</span>
<span class="n">op</span><span class="p">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="p">;</span>
<span class="n">op</span><span class="p">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">;</span>
<span class="n">op</span><span class="p">.</span><span class="n">operation</span> <span class="o">=</span> <span class="n">operation</span><span class="p">;</span>
<span class="n">ansq</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">op</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">firsti</span><span class="p">,</span> <span class="n">firstj</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">search</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">]</span> <span class="o">=</span> <span class="sc">'T'</span><span class="p">;</span>
<span class="n">ans</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="sc">'B'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">y</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span> <span class="o"><</span> <span class="n">n</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">y</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">y</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span> <span class="o"><</span> <span class="n">m</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">==</span> <span class="n">firsti</span> <span class="o">&&</span> <span class="n">y</span> <span class="o">==</span> <span class="n">firstj</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="n">ans</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="sc">'D'</span><span class="p">);</span>
<span class="n">ans</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="sc">'R'</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">m</span><span class="p">;);</span>
<span class="n">gets</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">gets</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">firsti</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">firstj</span> <span class="o">=</span> <span class="n">j</span><span class="p">;</span>
<span class="n">search</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">ansq</span><span class="p">.</span><span class="n">size</span><span class="p">());</span>
<span class="k">while</span> <span class="p">(</span><span class="o">!</span><span class="n">ansq</span><span class="p">.</span><span class="n">empty</span><span class="p">())</span>
<span class="p">{</span>
<span class="n">Operation</span> <span class="n">op</span> <span class="o">=</span> <span class="n">ansq</span><span class="p">.</span><span class="n">front</span><span class="p">();</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%c %d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">op</span><span class="p">.</span><span class="n">operation</span><span class="p">,</span> <span class="n">op</span><span class="p">.</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">op</span><span class="p">.</span><span class="n">y</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">ansq</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
130506
2013-05-06T10:55:27+00:00
http://greenmooon55.com/130506
<p>4月28号下午12306查了一下票,居然有29号的1462,果断买下,顺便买下成都到青岛的K206次,徐州换乘。</p>
<p>11号线一路站着,在火车站仓促地解决午饭,然后上楼候车,上海站感觉真好,只要一进去就感觉好像没有很多人的样子。只有1462和T99在一站台,要先坐电梯回到一楼,然后再走到站台上。1462只有3节YW,貌似其它都是YZ…车上大部分是男的列车员,连广播都是男的。。卧铺始发人很少,到南京基本上满了。</p>
<p>对面铺位是个生意人,她也是前一天的下午才买到票的,我感觉可能1462就是提前一天下午,每十分钟放几张票的…她到山东某地(忘了),大部分乘客都是短途的,南京还上来了一大三童鞋,徐州下车前三个人还讨论了一下大学生活及前途。。随遇而安吧,开心就好。貌似中铺也有个徐州下车的。</p>
<p>本来以为神车会一路早点的,没想到是一路小晚点。貌似无锡就看到旁边站台上写的T112到站时间,不过到了点它还没到,我们先走了。然后常州终于看到T112了,DF11好破,机车号都看不清。然后神车又先走了,貌似是在丹阳被踩的。接下来,过了高资站1462正线停车。。当时感觉特别奇怪,后来龙潭站侧近侧出踩了停在正线的T112,估计是机车有故障吧,坐这车得郁闷死了,特快被神车踩。南京停车的时候又看到了,我还以为它追不上来了呢。</p>
<p>南京出发晚点二十分钟吧,然后徐州之前好像依旧小晚点,徐州提前了几分钟到站,出站非常方便,下车两分钟就出站了,有点旧吉林站的感觉。</p>
<p>徐州作为一个中转站是很方便的,站前有麦当劳、德克士以及豆浆店。我在车上吃过15块的盒饭,感觉比518三十块的盒饭好多了。到麦当劳买杯巧克力看书。。</p>
<p>神车还是很爽的,就是这25G好破啊,速度快的时候晃得很厉害。坐神车,不挂科!话说现在应该求实习对吗?</p>
<p>呆了一个多小时实在受不了了,餐厅里有点热,十点十五左右进站候车,徐州站看起来有点旧,候车室挺多的,车也好多啊,一个候车室里平均就得十分钟一趟吧,不过基本都是过路车,每趟车上车的人不多。K206大约晚点20分钟进站,我等得很急。。济局的车,车上好像都没听到四川话,上车待一会就准备睡觉,这一觉可没睡好,盛名时刻写的兖州到泰山均速43km/h,实际在泰山站停了50分钟左右。我停车的时候睡不着。。开车了才睡着。。到济南又醒了,过了淄博、潍坊车上的人很少很少,两个列车员睡在下铺…最后也早点了二十分钟左右到青岛。其中一位还吐槽说“现在的车越开越慢了”= =</p>
<p>回程选择的是K878烟台到南京+G7041到安亭北。感觉胶州道路有些破旧,车站规模不比吉林西大多少。第一次坐残疾人专用车,定员57,厕所还有坐便和卫生纸,好高端。只有一个问题,就是门关不上…这车比1462平稳多了。胶济客专跟秦沈的感觉差不多,在K207上有种坐车回家的感觉…普速和动车共线,但是在胶州又分开了,普速进胶州站,动车进胶州北,貌似以前丹东到青岛的车也进过胶州北。</p>
<p>上车之后基本就在睡,在淄博待避了三趟动车,晚上上下行动车都多,还看到了G243合肥到青岛,这货要在淄博待避G191北京到青岛,真可怜。。然后又睡到了济南,然后从兖州睡到滁州北,时刻表上显示蚌埠要停站半小时,不过我一点感觉都没有。。睡得很好。</p>
<p>南京同站台停着K784鹰潭到上海,这车有人坐全程吗?比走沪昆多三百多公里。。出站之后走到玄武湖边,买报纸,进站吃绝味鸭血粉丝,南京站换乘挺舒服的,还有KFC和永和豆浆,在一个很偏僻的地方发5100。。</p>
<p>G7041南京发车人不多,最高速度29x,一般27x,可能因为离前车太近(前车停镇江),到丹阳之前减速几次,都到了80km/h。后来人就越来越多了,在无锡追上了K784,在苏州追上了早点10分钟的T109,T109居然是SS8牵引,好吧我是看的涂装颜色。过了昆山南车上稍微超员,安亭北有几个上车的,下车的人好多啊,感觉有五十到一百人,安亭北没有人工检票口,我拿着红纸票只好跟在别人后面…</p>
<p>安亭7路换安亭5路回学校,感觉不错,全程四十分钟左右。</p>
<p>好吧,其实其他的没什么想写的。那几天其实很想回上海,这就是人生吧。。总是不满足,总是不珍惜现在。</p>
<p>其实这些应该写在日记里的。。图片现在懒得传…</p>
<p>使用 <a href="http://writings.io">writings.io</a> 编辑,强烈推荐!</p>
The 10th Tongji University Collegiate Programming Contest
2013-04-05T02:23:21+00:00
http://greenmooon55.com/the-10th-tongji-university-collegiate-programming-contest
<p><img src="http://greenmoon55.com/wp-content/uploads/2013/04/2013-03-31-18.07.31.jpg" alt="提交记录" /></p>
<p>囧,居然不是按时间排序的。</p>
<p>比赛前两天做了一些腾讯的初赛题,热热身,发现我还是很适合这种比较水的题的,写起来觉得挺好玩。</p>
<p>比赛的位置非常不好。。在窗边正对着阳光,而且还没有窗帘。刚开始的时候看了A题,也就是复制粘贴那个,觉得很眼熟不过暂时没思路,然后就发现有人已经过了B,接下来就是跟着 board 做题了,没什么可说的。比赛过程中还遇到了一些问题,比如说 CodeBlocks 一直不能调试、memcpy 参数那个在前那个在后、如何从字符数组选择一些转成 String、怎么写 gcd…当然其实不用 gcd 的,J题队友推了公式,貌似思路错了。我一直没看 J 题。另外 H 题模拟也很坑。</p>
<p>封榜之后过了 E(似乎应该TLE的?),最后半小时左右开始写D,貌似就是个搜索吧?最后几分钟大脑空白状态,和队友一起写完,没测样例就交了,结果TLE。</p>
<p>最后应该是二等奖第一名吧,还不错,本来我想不比去年差太多就好的。我们两个第一次一起比赛,配合还不错,代码几乎都是我敲的,队友想到了A、J算法,还帮我出测试数据。</p>
<p><a href="http://greenmoon55.com/tongji-university-programming-contest-2011/">两年前是这样的</a>,不知道明年还会不会过来~</p>
江城
2013-04-01T06:28:51+00:00
http://greenmooon55.com/river-town
<p>刚上大学的时候发现一本新书《寻路中国》,在季风书园看了一部分觉得挺有趣的。后来发现了他写的另外一本书《江城》。前段时间看过国家地理杂志的<a href="http://ngm.nationalgeographic.com/2013/03/fuling-china/hessler-text">Fuling, China Return to River Town</a>,过了一段时间才发现,其实这篇文章的作者就是《江城》的作者“何伟”,我这才去买了这本书。</p>
<p><a href="http://book.douban.com/subject/7060185/"><img src="http://greenmoon55.com/wp-content/uploads/2013/04/rivertown.jpg" alt="江城" /></a></p>
<p>以前以为,只有吉林和武汉才算<a href="http://zh.wikipedia.org/wiki/%E6%B1%9F%E5%9F%8E">江城</a>,其实很多城市都是沿江而建的,它们都可以叫做江城吧。这本书写的是1996年到1998年Peter Hessler在涪陵做志愿者教英语的一些经历,从一个外国人的视角看当时的中国。</p>
<p>大部分中国人都应该听说过涪陵这个名字吧,乌江榨菜可是大家天天都吃的,话说“涪”我还读错了很久。那时的涪陵是一座很有特色的小城,三峡工程尚未完工,出行的主要方式是轮船。</p>
<p>作者来到中国的那段时间正好说我上小学之前的几年,刚刚开始记事,当时的中国还没有很多外国人,我也记得邓小平去世、香港回归。</p>
<blockquote>
<p>我发现,我读不懂文学评论了,因为其中晦涩的学术性与作品的优美性相去甚远。对于绝大多数文学评论,我都不太明白,它们好似一团乱麻,无可救药地充塞着令人费解的字眼:解构主义、后现代主义、新历史主义。这一切统统无法得到简单而明了的解释——就像我在涪陵的这些学生,当被问到什么是历史唯物主义,什么是中国特色的社会主义的时候,只能张口结舌。</p>
</blockquote>
<blockquote>
<p>克莱姆,出于其在华尔街工作的精明的数学头脑,记下了驾驶员摁响喇叭的总次数。在十五分钟的行车过程中,那位驾驶员一共摁响喇叭566次。每分钟37次。</p>
</blockquote>
<blockquote>
<p>这就是中国的方式。成功乃是预期之中的,而失败则遭到批评。你要么对要么不对,这里没有中间地带。</p>
</blockquote>
<blockquote>
<p>不过,这样的集体主义仅限于一些小团体、家庭、朋友和单位之内,这些紧密的社交圈也起到了一定的边界作用:它们既包容,又排他。对于自己熟知的圈子外的人,一般的涪陵人几乎很少表现出认同感。</p>
</blockquote>
<blockquote>
<p>尽管对这一段历史略知一二,我还是觉得人们对三峡大坝工程缺乏兴趣和漠不关心达到了不一般的程度。现在的人们受教育的程度远胜于以往那个年代,在一定程度上,人们应该记住所经历的历史教训,防止因盲目而重蹈覆辙。然而,十分明显的是,普通民众对于三峡大坝和下游城市移民的命运完全漠不关心。</p>
</blockquote>
<blockquote>
<p>在这本宪法里,我最喜欢的是第一章第三十二条:
中华人民共和国对于因为政治原因要求避难的外国人,可以给予受庇护的权利。</p>
</blockquote>
<blockquote>
<p>因为我知道,中国人总是对其他地方的人抱着一种强烈的偏见。</p>
</blockquote>
<blockquote>
<p>据说政府有一条规定,如果气温上升到三十七度,所有人都不用上班。因此官方报告的气温总是三十五度。</p>
</blockquote>
<blockquote>
<p>外国人总是说,中国人很难搞懂,这样的断言一般来说是正确的,但在很多情况下,人们的思想高度同一,可以预测。你只要按下这几个按钮——希特勒、犹太人、日本人、鸦片战争、西藏、台湾,十有八九都可以精准地预测会有怎样的反应,甚至可以精准地预测人们会使用哪些具体的词汇。就中国的具体情况而言——大家基本上属于同一种族、闭关锁国好几百年,目前的教育制度高度单一化和政治化,这是自然而然的事情。</p>
</blockquote>
<blockquote>
<p>“中共中央总书记、国家主席江泽民推荐观看《泰坦尼克号》,富通珠宝金行独家赞助!”</p>
</blockquote>
<p>这本书很有趣,翻译也很不错,有空的时候可以翻翻。。平平淡淡的生活其实并不平凡,所以世界上才会有各种纪录片、纪实文学。</p>
<p>十五年过去了,中国发生了很大的变化,涪陵据说已经成为有很多高楼大厦的典型中国城市。当时何伟班上的学生(大部分来自农村)现在从事着各种各样的工作,基本都过上了“优越的生活”。(<a href="http://ngmchina.com.cn/web/?action-viewnews-itemid-199904">《华夏地理》重返江城</a>)</p>
<p>觉得当时那些由志愿者上课的学生好幸福,或许学到的英美文学的比我们现在多,为什么我们不能多学点英语经典呢。突然想到高中时候的外教,已经忘了他说过什么,只记得大部分人都在下面自习…</p>
<p>不知道再过十年,我会在做什么,观念会改变多少。</p>
2013腾讯编程马拉松初赛第〇场
2013-03-30T06:04:23+00:00
http://greenmooon55.com/2013%e8%85%be%e8%ae%af%e7%bc%96%e7%a8%8b%e9%a9%ac%e6%8b%89%e6%9d%be%e5%88%9d%e8%b5%9b%e7%ac%ac%e3%80%87%e5%9c%ba
<p>很遗憾,连复赛都没进。。cin 超时,一直没想到改成 scanf…</p>
<h1 id="小q系列故事屌丝的逆袭">小Q系列故事——屌丝的逆袭</h1>
<p>略</p>
<h1 id="小明系列故事买年货">小明系列故事——买年货</h1>
<p>dp[i][j][l][x] 表示前i个商品,剩余金额j,剩余积分l,剩余免费商品数x。
dp[i][j][l][x] = max(dp[i-1][j][l][x], dp[i-1][j][l][x+1] + val), dp[i-1][j][l+b][x] + val, dp[i-1][j+a][l][x] + val);</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="mi">110</span><span class="p">][</span><span class="mi">110</span><span class="p">][</span><span class="mi">110</span><span class="p">][</span><span class="mi">6</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">v1</span><span class="p">,</span> <span class="n">v2</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">val</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">v1</span><span class="p">;,</span> <span class="o">&</span><span class="n">v2</span><span class="p">;,</span> <span class="o">&</span><span class="n">k</span><span class="p">;)</span><span class="o">!=</span> <span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="o">&</span><span class="n">val</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">v1</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">l</span> <span class="o"><=</span> <span class="n">v2</span><span class="p">;</span> <span class="n">l</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">x</span> <span class="o"><=</span> <span class="n">k</span><span class="p">;</span> <span class="n">x</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o"><</span> <span class="n">k</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">],</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">val</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">b</span> <span class="o"><=</span> <span class="n">v2</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">],</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="o">+</span><span class="n">b</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">+</span> <span class="n">val</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">+</span> <span class="n">a</span> <span class="o"><=</span> <span class="n">v1</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">],</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="n">a</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">+</span> <span class="n">val</span><span class="p">);</span>
<span class="c1">//printf("%d %d %d %d %d\n", i,j,l,x,dp[i][j][l][x]);
</span> <span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<h1 id="吉哥系列故事临时工计划">吉哥系列故事——临时工计划</h1>
<p>dp[i] 表示工作不超过第i天时获得的最多工资。先把工作按结束时间排序一下,然后你懂的。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="mi">110</span><span class="p">][</span><span class="mi">110</span><span class="p">][</span><span class="mi">110</span><span class="p">][</span><span class="mi">6</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">v1</span><span class="p">,</span> <span class="n">v2</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">val</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">v1</span><span class="p">;,</span> <span class="o">&</span><span class="n">v2</span><span class="p">;,</span> <span class="o">&</span><span class="n">k</span><span class="p">;)</span><span class="o">!=</span> <span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="o">&</span><span class="n">val</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">v1</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">l</span> <span class="o"><=</span> <span class="n">v2</span><span class="p">;</span> <span class="n">l</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">x</span> <span class="o"><=</span> <span class="n">k</span><span class="p">;</span> <span class="n">x</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o"><</span> <span class="n">k</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">],</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">val</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">b</span> <span class="o"><=</span> <span class="n">v2</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">],</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="o">+</span><span class="n">b</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">+</span> <span class="n">val</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">+</span> <span class="n">a</span> <span class="o"><=</span> <span class="n">v1</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">],</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="n">a</span><span class="p">][</span><span class="n">l</span><span class="p">][</span><span class="n">x</span><span class="p">]</span> <span class="o">+</span> <span class="n">val</span><span class="p">);</span>
<span class="c1">//printf("%d %d %d %d %d\n", i,j,l,x,dp[i][j][l][x]);
</span> <span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<h1 id="湫湫系列故事植树节">湫湫系列故事——植树节</h1>
<p>这道题很有趣!!搜了题解才会,其实这道题是在求单色三角形的个数。详见<a href="http://noclyt.com/blog/?p=185">这里</a>吧。。懒得画图说明了。</p>
<h1 id="威威猫系列故事篮球梦">威威猫系列故事——篮球梦</h1>
<p>每次攻击的时候 dp[i] = dp[i-1] + dp[i-2] + dp[i-3],存的就是有多少种。。好多细节,略恶心,还有long long,如果数据不到一局且已经赢了,种数还是1。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">a</span> <span class="o">>></span> <span class="n">b</span> <span class="o">>></span> <span class="n">t</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">defence</span> <span class="o">=</span> <span class="n">t</span> <span class="o">/</span> <span class="mi">30</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">attack</span> <span class="o">=</span> <span class="n">t</span> <span class="o">/</span> <span class="mi">30</span> <span class="o">+</span> <span class="n">t</span> <span class="o">%</span> <span class="mi">30</span> <span class="o">/</span> <span class="mi">15</span><span class="p">;</span>
<span class="n">b</span> <span class="o">+=</span> <span class="n">defence</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">gap</span> <span class="o">=</span> <span class="n">b</span> <span class="o">-</span> <span class="n">a</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">attack</span> <span class="o">*</span> <span class="mi">3</span> <span class="o"><=</span> <span class="n">gap</span><span class="p">)</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">attack</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">attack</span> <span class="o"><=</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">dp</span><span class="p">[</span><span class="mi">210</span><span class="p">];</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">attack</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">200</span><span class="p">;</span> <span class="n">j</span> <span class="o">>=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">-</span> <span class="mi">3</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">3</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">-</span> <span class="mi">2</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">2</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">gap</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="mi">200</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">sum</span> <span class="o">+=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">sum</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">attack</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">sum</span> <span class="o">=</span> <span class="n">sum</span> <span class="o">*</span> <span class="mi">3</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%I64d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">sum</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
USACO Video Game Troubles
2013-03-30T05:18:34+00:00
http://greenmooon55.com/usaco-video-game-troubles
<p>BNUOJ 4140</p>
<p>有很多游戏平台,每个平台上有很多游戏,每个游戏有花费和价值。</p>
<p>这道题很有趣,要背包两次,先考虑要不要买某个游戏,再考虑要不要买某个游戏平台。</p>
<p>看了这个题解才明白的:http://blog.sina.com.cn/s/blog_4a0c4e5d010147j3.html</p>
<p>循环过每个平台所有游戏之后,再考虑购买游戏平台的花费,这时候转换为另一个背包问题,要不要买这个平台。</p>
<p>dp[j][k] 表示第i个(当前平台)考虑了j个游戏,预算为k时的最大价值。dp[0][k] 就是前i个平台,当前预算为k的最优值。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">55</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXG</span> <span class="o">=</span> <span class="mi">15</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">p</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">g</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">gp</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXG</span><span class="p">],</span> <span class="n">pv</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXG</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="mi">100010</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">v</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">v</span><span class="p">;)</span><span class="o">!=</span><span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">g</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">];</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">gp</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="o">&</span><span class="n">pv</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">];</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="n">v</span><span class="p">;</span> <span class="n">k</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">k</span> <span class="o">>=</span> <span class="n">gp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">k</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">k</span><span class="o">-</span><span class="n">gp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]]</span> <span class="o">+</span> <span class="n">pv</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="k">else</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">k</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="n">v</span><span class="p">;</span> <span class="n">k</span> <span class="o">>=</span> <span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">];</span> <span class="n">k</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">k</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">]][</span><span class="n">k</span><span class="o">-</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">dp</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">v</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
130312
2013-03-12T12:33:03+00:00
http://greenmooon55.com/130312
<p>还以为标题可以是 120312 呢,那样更好玩一点。</p>
<p>其实呢,这个世界挺神奇的,有的时候感觉很公平,有的时候又好像也不是。</p>
<p>还记得高中班主任问什么是幸福?我说活着就是幸福。真的啊。。活到十八、二十是很幸运的事情啊,并不是必然事件嘛。。</p>
<p>有的人学X很轻松,有人花了很长时间也学不会X,而如果学Y就可能完全不一样。</p>
<p>其实上一句话不是重点。。所以,顺其自然吧~享受生活,享受这个世界。</p>
为什么 Kosaraju 算法一定要把所有边反向
2013-03-12T12:13:59+00:00
http://greenmooon55.com/why-reversing-all-edges-is-necessary-in-kosarajus-algorithm
<p><a href="https://www.coursera.org/course/algo">算法课</a>上介绍说,<a href="http://en.wikipedia.org/wiki/Kosaraju's_algorithm">Kosaraju 算法</a>的大概步骤是</p>
<ol>
<li>
<p>DFS反向图,记录每个点的出栈顺序</p>
</li>
<li>
<p>逆序(出栈顺序)遍历,找到所有的强连通分量</p>
</li>
</ol>
<p>正确性证明略…见课程 PDF…</p>
<p>很自然地想到一个问题…为什么不能在原图 DFS,然后顺序遍历呢?</p>
<p>想想证明里的那个例子,从强连通分量 SCC1 到 SCC2 有一条边,反向之后DFS,能保证最后出栈的点一定在 SCC2 中,因此第二次 DFS 时能找到正确的结果。如果在原图 DFS,则不能保证第一个出栈的点在哪里…呃,很简单嘛…</p>
<p>比如说 A->B,B->A, A->C 这个图,如果出栈顺序是BAC就杯具了= =</p>
<p>其实这个例子是网上搜到的…</p>
快排笔记
2013-02-27T11:20:18+00:00
http://greenmooon55.com/%e5%bf%ab%e6%8e%92%e7%ac%94%e8%ae%b0
<p>另一种快排的实现方法,<a href="https://www.coursera.org/course/algo">算法课</a>讲的。感觉这个挺容易懂的,都忘了以前怎么写的了= =。</p>
<p>首先选择数组中第一个元素为 pivot,先不管它,引入 i, j 两个指针。从左向右扫描数组,j 分隔开扫描过的元素和未知的元素,从第二个元素到 i 之前都比 pivot 小,从 i 到 j 都比 pivot 大,当然等于 pivot 的元素放在哪边都可以啦。扫描时如果遇到比 pivot 小的元素,与 i 后面那个元素交换即可,然后再右移 i。最后交换第一个元素和 i 左边的数。</p>
<p>实际代码中 a[i] 表示数组中大于 pivot 的第一个数(当然也可能还没扫到),最后和 a[i-1] 交换。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="kt">int</span> <span class="nf">partition</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">p</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="n">l</span><span class="p">];</span> <span class="c1">// pivot
</span> <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">r</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o"><</span> <span class="n">p</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">],</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">i</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">l</span><span class="p">],</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]);</span>
<span class="k">return</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">quicksort</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">p</span> <span class="o">=</span> <span class="n">partition</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o"><</span> <span class="n">p</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="n">quicksort</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">p</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">p</span> <span class="o">+</span> <span class="mi">1</span> <span class="o"><</span> <span class="n">r</span><span class="p">)</span> <span class="n">quicksort</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">p</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
<p>如果选取其他 pivot 怎么办呢?先交换第一个数和新的 pivot 就可以了。</p>
TEDxFDUSalon:因为这是真的
2012-12-27T16:09:32+00:00
http://greenmooon55.com/tedxfdusalon%ef%bc%9a%e5%9b%a0%e4%b8%ba%e8%bf%99%e6%98%af%e7%9c%9f%e7%9a%84
<p>上个月去看了 TEDxFDU,拖到现在还没写点什么呢,把记下来的东西随便写写好了。</p>
<p>暖场演讲有个很惊人的题目 <a href="http://v.youku.com/v_show/id_XNDkzNjc3NTA4.html">Ted is SHIT</a>,让大家思考参加活动的目的。联想自己、不要吐槽、生活中多折腾。</p>
<p>一、兰启昌
http://www.lanqc.com
事实与真相,事实不等于真相,我忘了他这里怎么讲的了,感觉确实是这样。。有些记者和读者都有一些偏见
“中国逻辑”比如说:A:这酒真难喝 B:…
新闻专业主义,还没找到英文怎么说,要独立于权贵、资本、<strong>大多数人或特立独行</strong>。
他提到了两个他喜欢的人:李海鹏和吴晓波</p>
<p>二、沈奕斐
社会性别:文化的力量
女主内,男主外?</p>
<p>她介绍了社会性别的概念,有的时候社会对个体的“期望”和他/她自身的喜好是不一样的。</p>
<p>三、Junxian Lee
授人以鱼不如授人以渔,所以他们帮助印度洋海啸受灾某地区如何晒盐,而不是直接捐款。
三个观点:
follow your heart
try
be do have 而不是 do have be</p>
<p>四、刘雨阳
又是一个物理转到软件工程的学生
他说在做校园活动海报上的二维码什么的…想到了我们的软工项目。
虚拟世界与真实世界:
指令:能量
数据:物质
《Matrix》
虚拟世界不能实现:细节(Retina也要舍弃)、随机(伪随机)</p>
<p>五、贝敏
貌似是大学以后就一直靠家教养活自己,去旅行,在黄山差点丧命= =</p>
<p>六、丁琦亮
PhD:拓展人类知识,想到了<a href="http://matt.might.net/articles/phd-school-in-pictures/">这个图</a>。
研究人类学,好强大,还有这门学科。</p>
<p>七、龚金平
顺势而为的人生。我初中开始就想,每天开开心心的就好了嘛。</p>
<p>===
大概就记得这些有点意义。。
好像学生都是直奔主题,教师/教授都会先说:“很高兴今天来到这里…”
最后回想一下,到底有什么收获呢?好像没什么哎…只是了解了一些别人的想法,不同的工作、人生。
我感觉自己话都不会说了= =</p>
<p>嘉定那个 <a href="http://v.youku.com/v_show/id_XNDkwODMxODQ4.html">ACE Project</a> 可以弄成类似的形式吧。。我还一次都没去过。想要变得更 social 一点,不能太宅了= = 英语社我也没帮上多少忙,不知道下学期怎么样呢。</p>
Ruby on Rails 环境配置
2012-11-06T12:11:15+00:00
http://greenmooon55.com/install-ruby-on-rails-on-ubuntu-12-10
<p><strong>Updated @ 2013/3/21 21:21</strong></p>
<ol>
<li>下载 RVM (Ruby Version Manager)</li>
</ol>
<p>在终端里执行</p>
<blockquote>
<table>
<tbody>
<tr>
<td>curl -L https://get.rvm.io</td>
<td>bash -s stable</td>
</tr>
</tbody>
</table>
</blockquote>
<p>可能需要先安装 curl</p>
<ol>
<li>
<p>关闭当前打开的终端窗口,重新打开</p>
</li>
<li>执行</li>
<li></li>
</ol>
<blockquote>
<p>sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config</p>
</blockquote>
<ol>
<li>安装 Ruby 2.0.0</li>
</ol>
<p>输入</p>
<blockquote>
<p>rvm install 2.0.0</p>
</blockquote>
<p>请耐心等待,可以出去转一圈或者睡一觉了…</p>
<ol>
<li>
<p>点击终端的“编辑”菜单,选择“配置文件首选项”,切换到“标题和命令”选项卡,选择“以登录Shell方式运行命令”,然后重启终端</p>
</li>
<li>
<p>输入</p>
</li>
</ol>
<blockquote>
<p>rvm 2.0.0 –default</p>
</blockquote>
<p>如果没有任何显示,应该是正常的。
此时输入</p>
<blockquote>
<p>ruby -v</p>
</blockquote>
<p>应该会显示 ruby 的版本号。</p>
<ol>
<li>由于某些原因,我们使用淘宝的 <a href="http://ruby.taobao.org/">Rubygems 镜像</a></li>
</ol>
<blockquote>
<p>gem source -r http://rubygems.org/
gem source -a http://ruby.taobao.org</p>
</blockquote>
<ol>
<li>安装rails</li>
</ol>
<blockquote>
<p>gem install rails</p>
</blockquote>
<p>至少需要半小时吧…</p>
TopCoder SRM 558 DIV 2
2012-10-22T08:33:20+00:00
http://greenmooon55.com/topcoder-srm-558-div-2
<p>先吐个嘈。。这次题目太难了吧。。第二题整个房间没人交,第三题只有两个人交,而且都 Failed System Test…</p>
<p>250
略</p>
<p>600
读题很重要!读题很重要!又一次写好了才发现错误。。
dp[i][j]表示盖章到第i个字符,颜色为j,最少盖几次。细节很容易错= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAX</span> <span class="o">=</span> <span class="mh">0x7f7f7f7f</span><span class="p">;</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="n">min</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">c</span><span class="p">;)</span>
<span class="p">{</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="s">"min"</span> <span class="o"><<</span> <span class="n">min</span><span class="p">(</span><span class="n">min</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">c</span><span class="p">)</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="n">min</span><span class="p">(</span><span class="n">min</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">c</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">class</span> <span class="nc">Stamp</span>
<span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">string</span> <span class="n">str</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">length</span><span class="p">;</span>
<span class="kt">bool</span> <span class="n">used</span><span class="p">[</span><span class="mi">300</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">getMinimumCost</span><span class="p">(</span><span class="n">string</span> <span class="n">desiredColor</span><span class="p">,</span> <span class="kt">int</span> <span class="n">stampCost</span><span class="p">,</span> <span class="kt">int</span> <span class="n">pushCost</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">str</span> <span class="o">=</span> <span class="n">desiredColor</span><span class="p">;</span>
<span class="n">length</span> <span class="o">=</span> <span class="n">desiredColor</span><span class="p">.</span><span class="n">size</span><span class="p">();</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="mi">55</span><span class="p">][</span><span class="mi">4</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">MAX</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">l</span> <span class="o"><=</span> <span class="n">length</span><span class="p">;</span> <span class="n">l</span><span class="o">++</span><span class="p">)</span> <span class="c1">// 章的长度为l
</span> <span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">used</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">used</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mh">0x7f</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">l</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">used</span><span class="p">[</span><span class="n">str</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">sum</span> <span class="o">=</span> <span class="n">used</span><span class="p">[</span><span class="sc">'R'</span><span class="p">]</span> <span class="o">+</span> <span class="n">used</span><span class="p">[</span><span class="sc">'G'</span><span class="p">]</span> <span class="o">+</span> <span class="n">used</span><span class="p">[</span><span class="sc">'B'</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span> <span class="o"><=</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="sc">'R'</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="sc">'G'</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="sc">'B'</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="c1">// 当前盖章到第i个字符(含)
</span> <span class="p">{</span>
<span class="c1">// 0????????????
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="n">l</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="n">i</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="c1">// 上一个章到第j个字符(含)
</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">MAX</span> <span class="o">&&</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="n">MAX</span> <span class="o">&&</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="n">MAX</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">used</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">used</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="n">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">k</span> <span class="o"><=</span> <span class="n">i</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">used</span><span class="p">[</span><span class="n">str</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">sum</span> <span class="o">=</span> <span class="n">used</span><span class="p">[</span><span class="sc">'R'</span><span class="p">]</span> <span class="o">+</span> <span class="n">used</span><span class="p">[</span><span class="sc">'G'</span><span class="p">]</span> <span class="o">+</span> <span class="n">used</span><span class="p">[</span><span class="sc">'B'</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">==</span> <span class="n">i</span> <span class="o">-</span> <span class="n">l</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">3</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="sc">'R'</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="sc">'G'</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">else</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span><span class="c1">//used['B']
</span> <span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="sc">'R'</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="sc">'G'</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">else</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">3</span><span class="p">])</span> <span class="o">==</span> <span class="n">MAX</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">stampCost</span> <span class="o">*</span> <span class="n">l</span> <span class="o">+</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="mi">3</span><span class="p">])</span> <span class="o">*</span> <span class="n">pushCost</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span> <span class="o"><</span> <span class="n">ans</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">};</span>
</code></pre></div></div>
<p>900
通过<a href="http://apps.topcoder.com/forums/?module=Thread&threadID=765870&start=0">搜索</a>,才知道这是一个经典博弈题,叫做 <a href="http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=algorithmGames">The Game of Nim</a>,异或一下就可以了,好神奇。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">CatAndRabbit</span>
<span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">string</span> <span class="n">getWinner</span><span class="p">(</span><span class="n">string</span> <span class="n">tiles</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">length</span> <span class="o">=</span> <span class="n">tiles</span><span class="p">.</span><span class="n">size</span><span class="p">();</span>
<span class="kt">bool</span> <span class="n">hasBlack</span> <span class="o">=</span> <span class="nb">false</span><span class="p">,</span> <span class="n">hasWhite</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tiles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'#'</span><span class="p">)</span> <span class="n">hasBlack</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">tiles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span> <span class="n">hasWhite</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">hasBlack</span> <span class="o">||</span> <span class="o">!</span><span class="n">hasWhite</span><span class="p">)</span> <span class="k">return</span> <span class="s">"Rabbit"</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">s</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">tiles</span><span class="p">[</span><span class="n">s</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'#'</span><span class="p">)</span> <span class="o">++</span><span class="n">s</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="mi">100</span><span class="p">],</span> <span class="n">p</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">s</span> <span class="o"><</span> <span class="n">length</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tiles</span><span class="p">[</span><span class="n">s</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'#'</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tiles</span><span class="p">[</span><span class="n">s</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span><span class="p">[</span><span class="n">p</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="o">++</span><span class="n">s</span><span class="p">;</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="o">++</span><span class="n">l</span><span class="p">;</span>
<span class="o">++</span><span class="n">s</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tiles</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span><span class="p">[</span><span class="n">p</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">p</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">ans</span> <span class="o">^</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ans</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="s">"Rabbit"</span><span class="p">;</span>
<span class="k">else</span> <span class="k">return</span> <span class="s">"Cat"</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">};</span>
</code></pre></div></div>
苏宁退货记
2012-10-16T06:42:00+00:00
http://greenmooon55.com/%e8%8b%8f%e5%ae%81%e9%80%80%e8%b4%a7%e8%ae%b0
<p>10月1日于上海苏宁徐家汇旗舰店(肇嘉浜路店)购入三星NP530U3C-A01CN一台。当时发现屏幕亮度不均,苏宁员工认为正常。</p>
<p>10月X日(似乎是五号),去徐家汇太平洋电脑一期20楼三星售后服务站,工程师认为正常。值得一提的是当时只有我一个人去检修,却等了半小时左右,理由是工程师在修昨天的机器。</p>
<p>10月7日,再去三星售后,简单的说问题是电脑休眠唤醒时会进入Windows错误恢复。售后查不出问题,电脑留下来检修。</p>
<p>10月9日中午,工程师来电话说他们仍然找不到问题,需要返厂检测。我说要退货,万一返厂直接修好了怎么办。。</p>
<p>10月12日早9点多,工程师说他没有返厂,可以出具检测单。
下午我就去开了检测单,注明日期是7号。然后<strong>去苏宁要求换货</strong>,苏宁说当时没货但可以帮我调货,当晚可以到,让我第二天来换,卖电脑的人还给我留了电话,好像说了有货会通知我。</p>
<p>10月13日早上,我没有接到电话,于是主动打电话问,<strong>苏宁说还没货,我只好去退</strong>,办了一部分手续。有些东西被我妈拿回家了,没有办法拿过来,苏宁说要我再交50元左右买个包就可以,耳机就不算了。然后说中午有些手续办不了,叫我下午再去,于是我回了趟本部。下午再去,他们复印了发票、身份证、检测单等等,然后说需要联系南京什么的,要周一晚上之后来办退款,给我写了个收条。我问了退款是退到银行卡里还是退现金,貌似她说她不清楚。</p>
<p>10月16日,一直打不通留的电话,我还是去了,售货员说是她手机有问题,难道你就不能给我打个电话?最后说要付款的银行卡,已经被我妈拿走了啊。。问过两次售货员退货需要什么,都没说需要这个,其实她也不清楚。总之,<strong>没有任何人说过需要付款的银行卡</strong>。火车票退票就不用银行卡的嘛。</p>
<p>于是上了地铁往回走,手机上网查了一下,打苏宁客服4008-365-365,某客服在询问后告诉我可以退货,于是我在上海体育馆下车坐回去。苏宁收银人员仍然坚持不能退且态度非常不好,于是我又打了一遍电话,电话里的客服让我把手机给收银员,然后<strong>收银员吼了客服一顿。。。最后客服和我说确实不行。。</strong>这个好好笑哦。。还管我要前一位客服的工号,我根本就没记嘛。。</p>
<p>于是现在手里一张发票一张退货单,等待快递银行卡中。。已经过了退货时间,不知道还会不会有麻烦。反正我都复印/拍照了,实在不行只好找消协什么的了~</p>
<p>To be continued…
@十一号线马陆站
Sent from my Android…….</p>
<p>在实体店买东西就是为了退换货、维修的时候方便点嘛。。</p>
<p><strong>苏宁的问题</strong></p>
<ol>
<li>
<p>应该加强对员工的培训。。说明退货需要什么,比如说身份证、付款的银行卡。</p>
</li>
<li>
<p>不能400和门店员工说法不一样,看他们吵真好笑。。</p>
</li>
<li>
<p>收银和某个新来的员工态度较差,后者不停地问我电脑是什么故障,很不相信我。。话说电脑要是没问题服务站会给我出检测报告吗?你当服务站是傻子啊。。</p>
</li>
<li>
<p>整个退货流程时间太长,我12号说要换货,13号知道没货了,决定退货。就算带了银行卡当天也拿不到钱。。</p>
</li>
<li>
<p>不能出尔反尔吧,要回赠品可以理解,但是不能先说了不要,今天又说要吧。。</p>
</li>
</ol>
<p>本来对苏宁的印象要略好于国美的,现在。。以后肯定不会优先考虑苏宁了。</p>
<p>为了退换货现在已经往返三次了,单程1个半小时,地铁要7块钱。等到银行卡到了再去,难道银行卡挂失了或者销户了就不能退款了?</p>
Trainspotter badge, Level 8!
2012-09-29T15:03:50+00:00
http://greenmooon55.com/trainspotter-badge-level-8
<p><a href="https://foursquare.com/greenmoon55/badge/5039f055e4b0124e4430cd5d"><img src="http://greenmoon55.com/wp-content/uploads/2012/09/20120929224442000.png" alt="" /></a></p>
<p>8月26号从昆山南坐动车回来拿到的 badge,收到邮件之后感觉很好玩,查了一下这些单词:</p>
<p>MTA 是<a href="http://zh.wikipedia.org/wiki/%E7%B4%90%E7%B4%84%E5%A4%A7%E9%83%BD%E6%9C%83%E9%81%8B%E8%BC%B8%E7%BD%B2">纽约大都会运输署</a>。
Tube 是<a href="http://zh.wikipedia.org/wiki/%E4%BC%A6%E6%95%A6%E5%9C%B0%E9%93%81">伦敦地铁</a>哦,以前只知道伦敦地铁叫 Underground…伦敦可是地铁的发源地哦。
Shinkansen 当时是新干线啦,地球人都知道。
Trans-Siberian 是<a href="http://zh.wikipedia.org/wiki/%E8%A5%BF%E4%BC%AF%E5%88%A9%E4%BA%9E%E9%90%B5%E8%B7%AF">西伯利亚大铁路</a>,北京到莫斯科的国际列车就经过这里吧。</p>
<p>最后很好玩,”backpackers who haven’t showered in a week.”</p>
<p>原来火车迷也可以叫做 Trainspotter,其实以前一直以为邮件里这个单词是 Transporter…</p>
<p>明天或后天准备体验一下22号线。</p>
120922
2012-09-22T14:56:31+00:00
http://greenmooon55.com/120922
<p>今年第一场网络赛,还好不是完全没想法,一道简单搜索写了很久,还TLE一次,另外的概率dp,xw的想法有点问题,后来有点思路我也不愿意细想了,没到五点就撤了,很不爽。。</p>
120921
2012-09-21T15:30:33+00:00
http://greenmooon55.com/120921
<p>和老妈中午昆山101+沪宁高铁去了趟苏州,再高铁回然后镇坪路换北安线回来。</p>
<p>沪宁城际太火了,赶到安亭北的时候最后一张票正好被前面的人买走= = 昆山南到苏州的坑爹G上座率也是几乎100%,(全程上海到常州的,在昆山南还要待避后面的G…),苏州买票时前两班也基本没票了,去虹桥的D居然还有二等座。</p>
<p>20:40左右,感觉人多果断没有坐北安跨,等到的北安线有很多空座,一小时回来,感觉不错。昆山101有点慢= =</p>
<p>这次去观前街、苏州博物馆、平江路看了一圈。平江路那边有种古镇的感觉,很多小房子,其实再稍微多点店铺就好了,但是不要太多…听到苏州公交的本地报站了,苏州地铁还没坐过。</p>
<p>沪宁城际现在这样都该加车了吧…人真多。</p>
120920
2012-09-20T15:41:10+00:00
http://greenmooon55.com/120920
<p>前段时间很想写blog的,后来又不想了,今天没收到OhLife的邮件,又登陆不上。在这里写写吧= =</p>
<p>医院水很深,家里有这方面的人会好很多。
注意身体多休息
这学期选课真纠结,课表今天才定下来。有些课有点无聊
没去交换有点遗憾,大四去的话更影响实习吧…
GC分组学习感觉怪怪的。。不过挺好的,希望能坚持到最后,自己也多学点东西
笔记本仍然纠结中。。本来看好了一个,结果京东突然涨价了,不想再挑了,要疯了。。
开始做题吧,现在完全没有信心,十一看看能不能提升点。
还有…有没有可能呢。。</p>
<p>写这个好无聊。
早睡吧,多休息,都要困死了!</p>
Codeforces Round #133 (Div. 2)
2012-08-15T15:43:08+00:00
http://greenmooon55.com/codeforces-round-133-div-2
<p>这次比赛很爽啊,四题,room leader。Rating 终于过 1500 了。Div. 2 专场的题目貌似要简单一些。
<strong>A. Tiling with Hexagons</strong>
分成几个平行四边形,再减去相邻平行四边形重合的面积。(a<em>b+b</em>c+c*a-(a+b+c)+1)</p>
<p><strong>B. Forming Teams</strong>
这道题有个很强烈的限制条件,每个学生最多有两个敌人。于是分为三种情况,环、链和孤立的点,如果环上的结点数为奇数,这个环上一定有个点要被取下。有偶数个节点的链也可以平分为两份,有奇数个节点的链分完之后只能是某一份多一个,奇数个有奇数个节点的链的结果还是某一份多一个,再考虑孤立的点,所以其实只要考虑环,然后剩下的节点数如果是奇数就去得掉一个。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">map</span><span class="p">[</span><span class="mi">105</span><span class="p">][</span><span class="mi">105</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">addedge</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="o">++</span><span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">ans</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">visited</span><span class="p">[</span><span class="mi">105</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">search</span><span class="p">(</span><span class="kt">int</span> <span class="n">node</span><span class="p">,</span> <span class="kt">int</span> <span class="n">depth</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">visited</span><span class="p">[</span><span class="n">node</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">depth</span> <span class="o">-</span> <span class="n">visited</span><span class="p">[</span><span class="n">node</span><span class="p">]</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">((</span><span class="n">depth</span> <span class="o">-</span> <span class="n">visited</span><span class="p">[</span><span class="n">node</span><span class="p">])</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="o">++</span><span class="n">ans</span><span class="p">;</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">visited</span><span class="p">[</span><span class="n">node</span><span class="p">]</span> <span class="o">=</span> <span class="n">depth</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">map</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">search</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">depth</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">a</span> <span class="o">>></span> <span class="n">b</span><span class="p">;</span>
<span class="n">addedge</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="n">addedge</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">visited</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="n">search</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">((</span><span class="n">n</span> <span class="o">-</span> <span class="n">ans</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="o">++</span><span class="n">ans</span><span class="p">;</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>C. Hiring Staff</strong>
这道题也有非常强的限制条件,(m\leq n) 且 (n \neq 1)。
写写算算就出来答案了。
第一天需要 k 个人,第 n 天需要一个,第 n+1 天需要 k-1 个,若 (m \leq n-1),到此结束。若 (m=n),第 2n 天还需要一个,到此结束。其实如果 m > n,应该是第 i<em>n 天一个,第 i</em>n+1 天 k-1 个吧,(k \geq2),直到 n+m+1 天为止。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="mi">1000000</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">work</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">k</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o"><</span> <span class="n">n</span> <span class="o">+</span> <span class="n">m</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">i</span> <span class="o">+=</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">k</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">a</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">a</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">m</span> <span class="o"><=</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">m</span> <span class="o">==</span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">m</span> <span class="o">></span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">n</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="nb">true</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="n">m</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">>=</span> <span class="n">i</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="n">m</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">>=</span> <span class="n">i</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="o">++</span><span class="n">i</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">i</span> <span class="o">+=</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="n">work</span><span class="p">();</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">count</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cout</span> <span class="o"><<</span> <span class="s">" "</span> <span class="o"><<</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>D. Spider’s Web</strong>
这题最难的地方在于读题。对于每个 sector 处理一下就可以了。
每个 sector 可能有 (10^5) 个 bridge,bridge 的总数不超过 (10^5),开数组存不下,只好用 vector 啦。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">1010</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">vector</span> <span class="n">num</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">cur</span><span class="p">,</span> <span class="kt">int</span> <span class="n">prev</span><span class="p">,</span> <span class="kt">int</span> <span class="n">next</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">pcur</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pp</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pn</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">prev</span><span class="p">][</span><span class="n">pp</span><span class="p">]</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">cur</span><span class="p">][</span><span class="n">pcur</span><span class="p">]</span> <span class="o">&&</span> <span class="n">pp</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">prev</span><span class="p">].</span><span class="n">size</span><span class="p">())</span> <span class="o">++</span><span class="n">pp</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">next</span><span class="p">][</span><span class="n">pn</span><span class="p">]</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">cur</span><span class="p">][</span><span class="n">pcur</span><span class="p">]</span> <span class="o">&&</span> <span class="n">pn</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">next</span><span class="p">].</span><span class="n">size</span><span class="p">())</span> <span class="o">++</span><span class="n">pn</span><span class="p">;</span>
<span class="o">++</span><span class="n">pcur</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">pcur</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">cur</span><span class="p">].</span><span class="n">size</span><span class="p">())</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">oldpp</span> <span class="o">=</span> <span class="n">pp</span><span class="p">,</span> <span class="n">oldpn</span> <span class="o">=</span> <span class="n">pn</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">prev</span><span class="p">][</span><span class="n">pp</span><span class="p">]</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">cur</span><span class="p">][</span><span class="n">pcur</span><span class="p">]</span> <span class="o">&&</span> <span class="n">pp</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">prev</span><span class="p">].</span><span class="n">size</span><span class="p">())</span> <span class="o">++</span><span class="n">pp</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">next</span><span class="p">][</span><span class="n">pn</span><span class="p">]</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">cur</span><span class="p">][</span><span class="n">pcur</span><span class="p">]</span> <span class="o">&&</span> <span class="n">pn</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">next</span><span class="p">].</span><span class="n">size</span><span class="p">())</span> <span class="o">++</span><span class="n">pn</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pp</span> <span class="o">-</span> <span class="n">oldpp</span> <span class="o">!=</span> <span class="n">pn</span> <span class="o">-</span> <span class="n">oldpn</span><span class="p">)</span> <span class="o">++</span><span class="n">ans</span><span class="p">;</span>
<span class="o">++</span><span class="n">pcur</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">temp</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="n">k</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">temp</span><span class="p">;</span>
<span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">push_back</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">sort</span><span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">begin</span><span class="p">(),</span> <span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">end</span><span class="p">());</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">work</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">work</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
<span class="n">work</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
Codeforces Round #132 (Div. 2)
2012-08-14T02:34:36+00:00
http://greenmooon55.com/codeforces-round-132-div-2
<p><strong>A. Bicycle Chain</strong>
略</p>
<p><strong>B. Olympic Medal</strong>
可以很容易地推出公式,有些变量直接用double了,用int相乘会溢出。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">5010</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">x</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">z</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">k</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">z</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">a</span> <span class="o">>></span> <span class="n">b</span><span class="p">;</span>
<span class="n">sort</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span> <span class="o">+</span> <span class="n">n</span><span class="p">);</span>
<span class="n">sort</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">z</span> <span class="o">+</span> <span class="n">k</span><span class="p">);</span>
<span class="kt">double</span> <span class="n">r1</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">p2</span> <span class="o">=</span> <span class="n">z</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">double</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">b</span> <span class="o">*</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">r1</span> <span class="o">*</span> <span class="n">r1</span> <span class="o">/</span> <span class="p">(</span><span class="n">a</span> <span class="o">*</span> <span class="n">p2</span> <span class="o">+</span> <span class="n">b</span> <span class="o">*</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">]));</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span> <span class="o">>=</span> <span class="n">r1</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%.10lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">ans</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>C. Crosses</strong>
这题折腾死我了。。Virtual paticipation的时候我猜是个DP,完全没思路。看了题解才知道,是枚举包含Cross的最小矩形,然后算一下四角需要去掉多大面积,枚举某方向的边长,到sqrt(area)即可,全部枚举会超时。如果是矩形,a,b和c,d可以交换位置,所以算两种情况。这里要注意一下。。我有点晕,WA好多次。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">s</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span> <span class="o">>></span> <span class="n">s</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span> <span class="o">+=</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">m</span><span class="p">;</span> <span class="n">j</span> <span class="o">+=</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">*</span> <span class="n">j</span> <span class="o"><</span> <span class="n">s</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">v</span> <span class="o">=</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">m</span> <span class="o">-</span> <span class="n">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">*</span> <span class="n">j</span> <span class="o">==</span> <span class="n">s</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">v</span> <span class="o">*=</span> <span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">i</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">j</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">area</span> <span class="o">=</span> <span class="n">i</span> <span class="o">*</span> <span class="n">j</span> <span class="o">-</span> <span class="n">s</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">area</span> <span class="o">%</span> <span class="mi">4</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">area</span> <span class="o">/=</span> <span class="mi">4</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">length</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">area</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">k</span> <span class="o"><=</span> <span class="n">length</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">area</span> <span class="o">%</span> <span class="n">k</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">k</span> <span class="o">*</span> <span class="mi">2</span> <span class="o"><</span> <span class="n">i</span> <span class="o">&&</span> <span class="n">area</span> <span class="o">/</span> <span class="n">k</span> <span class="o">*</span> <span class="mi">2</span> <span class="o"><</span> <span class="n">j</span><span class="p">)</span> <span class="n">temp</span><span class="o">++</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">k</span> <span class="o">*</span> <span class="mi">2</span> <span class="o"><</span> <span class="n">j</span> <span class="o">&&</span> <span class="n">area</span> <span class="o">/</span> <span class="n">k</span> <span class="o">*</span> <span class="mi">2</span> <span class="o"><</span> <span class="n">i</span><span class="p">)</span> <span class="n">temp</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">*</span> <span class="n">length</span> <span class="o">==</span> <span class="n">area</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">*</span> <span class="mi">2</span> <span class="o"><</span> <span class="n">i</span> <span class="o">&&</span> <span class="n">length</span> <span class="o">*</span> <span class="mi">2</span> <span class="o"><</span> <span class="n">j</span><span class="p">)</span> <span class="n">temp</span><span class="o">--</span><span class="p">;</span>
<span class="n">v</span> <span class="o">*=</span> <span class="n">temp</span> <span class="o">*</span> <span class="mi">2</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">v</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>D. Hot Days</strong>
这题的题目描述好复杂,当时看了好久才懂。第一反应是三分法,后来一想,只有两种可能嘛,一种是有足够多的车,没有“罚款”,另外一种是只有一辆车,可能有罚款。如果车的数量不够多,罚的钱和只有一辆车是一样的。注意一定会罚款的情况,因为这个WA一次= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">t</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">cost</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">n</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span> <span class="o">>></span> <span class="n">T</span> <span class="o">>></span> <span class="n">x</span> <span class="o">>></span> <span class="n">cost</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">T</span> <span class="o"><=</span> <span class="n">t</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">cost</span> <span class="o">+</span> <span class="n">m</span> <span class="o">*</span> <span class="n">x</span><span class="p">;</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">count</span> <span class="o">=</span> <span class="n">ceil</span><span class="p">(</span><span class="n">m</span> <span class="o">/</span> <span class="p">(</span><span class="kt">double</span><span class="p">)(</span><span class="n">T</span> <span class="o">-</span> <span class="n">t</span><span class="p">));</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">t1</span> <span class="o">=</span> <span class="n">count</span> <span class="o">*</span> <span class="n">cost</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">t2</span> <span class="o">=</span> <span class="n">cost</span> <span class="o">+</span> <span class="n">m</span> <span class="o">*</span> <span class="n">x</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">min</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">t2</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
2012 Multi-University Training Contest 6
2012-08-13T11:00:58+00:00
http://greenmooon55.com/2012-multi-university-training-contest-6
<p>官方题解:<a href="http://page.renren.com/601081183/note/865145486">2012 Multi-University Training Contest 6 Solution</a>
1001 <strong>Card</strong>
int length = r - l + 1;
循环节的长度一定是LCM(r, length) / length,然后就好做了吧…代码里把lcm写成lcd了。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="nf">gcd</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">b</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">a</span> <span class="o">%</span> <span class="n">b</span><span class="p">;</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">b</span><span class="p">;</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">t</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">a</span><span class="p">;</span>
<span class="p">}</span>
<span class="kr">inline</span> <span class="kt">long</span> <span class="kt">long</span> <span class="nf">lcd</span><span class="p">(</span><span class="kt">long</span> <span class="kt">long</span> <span class="n">a</span><span class="p">,</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span> <span class="o">*</span> <span class="n">b</span> <span class="o">/</span> <span class="n">gcd</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">card</span><span class="p">[</span><span class="mi">55</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">N</span> <span class="o">=</span> <span class="mi">52</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">t</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">caseno</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">caseno</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">caseno</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">N</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">card</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">l</span><span class="p">;,</span> <span class="o">&</span><span class="n">r</span><span class="p">;);</span>
<span class="kt">int</span> <span class="n">length</span> <span class="o">=</span> <span class="n">r</span> <span class="o">-</span> <span class="n">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">loop</span> <span class="o">=</span> <span class="n">lcd</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">length</span><span class="p">)</span> <span class="o">/</span> <span class="n">length</span><span class="p">;</span> <span class="c1">// 循环节长度
</span> <span class="kt">int</span> <span class="n">shift</span> <span class="o">=</span> <span class="n">n</span> <span class="o">%</span> <span class="n">loop</span> <span class="o">*</span> <span class="n">length</span> <span class="o">%</span> <span class="n">r</span><span class="p">;</span>
<span class="n">shift</span> <span class="o">=</span> <span class="n">r</span> <span class="o">-</span> <span class="n">shift</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d:"</span><span class="p">,</span> <span class="n">caseno</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">shift</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">r</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">" %d"</span><span class="p">,</span> <span class="n">card</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">shift</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">" %d"</span><span class="p">,</span> <span class="n">card</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">r</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">N</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">" %d"</span><span class="p">,</span> <span class="n">card</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1006 <strong>Party All the Time</strong>
对于每个精灵,unhappiness都是与选定的聚会地相关的<a href="http://zh.wikipedia.org/zh-cn/%E5%87%B8%E5%87%BD%E6%95%B0">凹函数</a>,而多个凹函数相加一定还是凹函数(貌似根据定义就可证),所以可以使用三分法。似乎这道题会有<a href="http://blog.ac521.org/?p=526">精度问题</a>。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">50010</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">double</span> <span class="n">eps</span> <span class="o">=</span> <span class="mf">1e-6</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">x</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">w</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">double</span> <span class="nf">calc</span><span class="p">(</span><span class="kt">double</span> <span class="n">pos</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">double</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">w</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">pow</span><span class="p">(</span><span class="n">fabs</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">pos</span><span class="p">),</span> <span class="mi">3</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">t</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">caseno</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">caseno</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">caseno</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%lf%lf"</span><span class="p">,</span> <span class="o">&</span><span class="n">x</span><span class="p">;[</span><span class="n">i</span><span class="p">],</span> <span class="o">&</span><span class="n">w</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="kt">double</span> <span class="n">left</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">right</span> <span class="o">=</span> <span class="n">x</span><span class="p">[</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">leftmid</span><span class="p">,</span> <span class="n">rightmid</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">leftvalue</span><span class="p">,</span> <span class="n">rightvalue</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">left</span> <span class="o">+</span> <span class="n">eps</span> <span class="o"><</span> <span class="n">right</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">leftmid</span> <span class="o">=</span> <span class="p">(</span><span class="n">left</span> <span class="o">+</span> <span class="n">right</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="n">rightmid</span> <span class="o">=</span> <span class="p">(</span><span class="n">leftmid</span> <span class="o">+</span> <span class="n">right</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="n">leftvalue</span> <span class="o">=</span> <span class="n">calc</span><span class="p">(</span><span class="n">leftmid</span><span class="p">);</span>
<span class="n">rightvalue</span> <span class="o">=</span> <span class="n">calc</span><span class="p">(</span><span class="n">rightmid</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">leftvalue</span> <span class="o"><</span> <span class="n">rightvalue</span><span class="p">)</span> <span class="n">right</span> <span class="o">=</span> <span class="n">rightmid</span><span class="p">;</span>
<span class="k">else</span> <span class="n">left</span> <span class="o">=</span> <span class="n">leftmid</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: %.0lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">caseno</span><span class="p">,</span> <span class="n">calc</span><span class="p">(</span><span class="n">left</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1008 <strong>String change</strong>
看官方题解吧。。这思路太神奇了。</p>
<p>1010 <strong>Easy Tree DP?</strong>
题中条件的意思是,左右子树中最大的元素一定在右子树。
搜到一篇题解,遗憾的是现在找不到了。。dp[i][j]表示用了i个节点,高度<strong>小于等于</strong>j的方案数。
dp[i][j] = i * (dp[i-1][j-1] * 2 + c[i-2][k] * dp[k][j-1] * dp[i-k-1][j-1]),k为左子树的节点数。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">365</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MOD</span> <span class="o">=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">c</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">dp</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"test.in"</span><span class="p">,</span> <span class="s">"r"</span><span class="p">,</span> <span class="n">stdin</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">d</span><span class="p">;</span>
<span class="n">c</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">MAXN</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">i</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">j</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">n</span> <span class="o">=</span> <span class="mi">360</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">%=</span> <span class="n">MOD</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">k</span> <span class="o"><</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+=</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">2</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">dp</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">%</span> <span class="n">MOD</span> <span class="o">*</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="o">-</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">%=</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">*=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">%=</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">t</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">caseno</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">caseno</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">caseno</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">d</span><span class="p">;);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: %lld</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">caseno</span><span class="p">,</span> <span class="p">((</span><span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">d</span><span class="p">]</span> <span class="o">-</span> <span class="n">dp</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">d</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span> <span class="o">+</span> <span class="n">MOD</span><span class="p">)</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
2012 Multi-University Training Contest 5
2012-08-13T10:19:23+00:00
http://greenmooon55.com/2012-multi-university-training-contest-5
<p>官方题解:<a href="http://page.renren.com/601081183/note/864816900">2012 Multi-University Training Contest 5 Solution</a></p>
<p>1003 <strong>Gold miner</strong>
分组背包,详见《<a href="http://cuitianyi.com/blog/%E3%80%8A%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98%E4%B9%9D%E8%AE%B2%E3%80%8B2-0-alpha1/">背包问题九讲</a>》。
用点积判断是否在一条直线上。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">210</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">gold</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">v</span><span class="p">;</span>
<span class="p">}</span><span class="n">g</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="mi">40010</span><span class="p">];</span>
<span class="kt">bool</span> <span class="nf">sameGroup</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">g</span><span class="p">[</span><span class="n">a</span><span class="p">].</span><span class="n">x</span> <span class="o">*</span> <span class="n">g</span><span class="p">[</span><span class="n">b</span><span class="p">].</span><span class="n">y</span> <span class="o">==</span> <span class="n">g</span><span class="p">[</span><span class="n">b</span><span class="p">].</span><span class="n">x</span> <span class="o">*</span> <span class="n">g</span><span class="p">[</span><span class="n">a</span><span class="p">].</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">comp</span><span class="p">(</span><span class="k">const</span> <span class="n">gold</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">gold</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">y</span> <span class="o"><</span> <span class="n">b</span><span class="p">.</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">group</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">caseno</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">t</span><span class="p">;)</span><span class="o">!=</span> <span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">groupCount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">group</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">group</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">g</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">,</span> <span class="o">&</span><span class="n">g</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">,</span> <span class="o">&</span><span class="n">g</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">t</span><span class="p">,</span> <span class="o">&</span><span class="n">g</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span><span class="p">);</span>
<span class="n">sort</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="n">g</span> <span class="o">+</span> <span class="n">n</span><span class="p">,</span> <span class="n">comp</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">bool</span> <span class="n">found</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">groupCount</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sameGroup</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">group</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]))</span>
<span class="p">{</span>
<span class="n">gold</span><span class="o">*</span> <span class="n">prev</span> <span class="o">=</span> <span class="o">&</span><span class="n">g</span><span class="p">;[</span><span class="n">group</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">group</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]]];</span>
<span class="o">++</span><span class="n">group</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="n">group</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">group</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">t</span> <span class="o">+=</span> <span class="n">prev</span><span class="o">-></span><span class="n">t</span><span class="p">;</span>
<span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span> <span class="o">+=</span> <span class="n">prev</span><span class="o">-></span><span class="n">v</span><span class="p">;</span>
<span class="n">found</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">found</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="o">++</span><span class="n">groupCount</span><span class="p">;</span>
<span class="o">++</span><span class="n">group</span><span class="p">[</span><span class="n">groupCount</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="n">group</span><span class="p">[</span><span class="n">groupCount</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">groupCount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">time</span> <span class="o">=</span> <span class="n">t</span><span class="p">;</span> <span class="n">time</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">time</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">group</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//if (time - g[group[i][j]].t < 0) break;
</span> <span class="k">if</span> <span class="p">(</span><span class="n">time</span> <span class="o">-</span> <span class="n">g</span><span class="p">[</span><span class="n">group</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]].</span><span class="n">t</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span>
<span class="n">dp</span><span class="p">[</span><span class="n">time</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">time</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">time</span> <span class="o">-</span> <span class="n">g</span><span class="p">[</span><span class="n">group</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]].</span><span class="n">t</span><span class="p">]</span>
<span class="o">+</span> <span class="n">g</span><span class="p">[</span><span class="n">group</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]].</span><span class="n">v</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case %d: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">++</span><span class="n">caseno</span><span class="p">,</span> <span class="n">dp</span><span class="p">[</span><span class="n">t</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1004 <strong>History repeat itself</strong>
不停地求sqrt(N),得到比N小的新平方数的个数,然后加上这个数,直到找不到新的平方数为止。此时正好有N个非平方数(新加的数都是平方数)。然后可以很方便地推出公式求和。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">m</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">add</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">m</span><span class="p">);</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">add</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">m</span> <span class="o">+=</span> <span class="n">add</span><span class="p">;</span>
<span class="n">count</span> <span class="o">+=</span> <span class="n">add</span><span class="p">;</span>
<span class="n">add</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="o">-</span> <span class="n">count</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">m</span> <span class="o"><<</span> <span class="s">" "</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">x</span> <span class="o">=</span> <span class="n">count</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">x</span> <span class="o">*</span> <span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="mi">3</span><span class="o">+</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">x</span><span class="o">*</span><span class="n">x</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span> <span class="o">+</span> <span class="p">(</span><span class="n">m</span> <span class="o">-</span> <span class="n">count</span><span class="o">*</span><span class="n">count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">count</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1007 <strong>Permutation</strong>
很容易想到这道题其实就是求,一些数相加和为N,它们的最小公倍数有多少种情况。遗憾的是没往下想,直接想DP没思路。
官方题解:由于1不影响最小公倍数,问题转化为相加小于等于N的若干正整数的最小公倍数的可能数。
再考虑,如果两个数不互质,最小公倍数与少一些因子变得互质的情况相同。所以只要考虑这些正整数是质数即可,注意每个数可能出现多次。
dp[i][j]表示前i种质数,构成和为j有多少种情况。
dp[i][j] = dp[i-1][j] + dp[i-1][j-k*prime[i]]</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">dp</span><span class="p">[</span><span class="mi">1010</span><span class="p">][</span><span class="mi">1010</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">primeCount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">p</span><span class="p">[</span><span class="mi">1000</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">1010</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">s</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="kt">bool</span> <span class="n">prime</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">s</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">%</span> <span class="n">j</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">prime</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">prime</span><span class="p">)</span> <span class="n">p</span><span class="p">[</span><span class="o">++</span><span class="n">primeCount</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;)</span> <span class="o">!=</span> <span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">primeCount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">primeCount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">ans</span> <span class="o">+=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">temp</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span> <span class="o">></span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">while</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="n">temp</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span> <span class="o">></span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">-</span> <span class="n">temp</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">j</span> <span class="o">-</span> <span class="n">temp</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">temp</span> <span class="o">*=</span> <span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1011 <strong>Xiao Ming’s Hope</strong>
找规律,这题我用cin居然超时,不知道为什么。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;)</span> <span class="o">!=</span> <span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">do</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&</span> <span class="n">n</span><span class="p">)</span> <span class="o">++</span><span class="n">count</span><span class="p">;</span>
<span class="n">n</span> <span class="o">>>=</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span> <span class="k">while</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="mi">1</span> <span class="o"><<</span> <span class="n">count</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
TopCoder SRM 551 DIV 2
2012-08-08T06:06:05+00:00
http://greenmooon55.com/topcoder-srm-551-div-2
<p>250
略</p>
<p>500
枚举中心,然后两边往中间移,当时想错了= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">ColorfulChocolates</span>
<span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="kt">int</span> <span class="n">maximumSpread</span><span class="p">(</span><span class="n">string</span> <span class="n">chocolates</span><span class="p">,</span> <span class="kt">int</span> <span class="n">maxSwaps</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">chocolates</span><span class="p">.</span><span class="n">length</span><span class="p">();</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">left</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">leftCount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">rightCount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">right</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">color</span> <span class="o">=</span> <span class="n">chocolates</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">curSwaps</span> <span class="o">=</span> <span class="n">maxSwaps</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dis</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">left</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">||</span> <span class="n">right</span> <span class="o"><</span> <span class="n">chocolates</span><span class="p">.</span><span class="n">length</span><span class="p">())</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">left</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">chocolates</span><span class="p">[</span><span class="n">left</span><span class="p">]</span> <span class="o">==</span> <span class="n">color</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dis</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">leftCount</span> <span class="o">-</span> <span class="n">left</span><span class="p">;</span>
<span class="n">leftCount</span><span class="o">++</span><span class="p">;</span>
<span class="n">curSwaps</span> <span class="o">-=</span> <span class="n">dis</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">curSwaps</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">leftCount</span> <span class="o">+</span> <span class="n">rightCount</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">right</span> <span class="o"><</span> <span class="n">chocolates</span><span class="p">.</span><span class="n">length</span><span class="p">()</span> <span class="o">&&</span> <span class="n">chocolates</span><span class="p">[</span><span class="n">right</span><span class="p">]</span> <span class="o">==</span> <span class="n">color</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dis</span> <span class="o">=</span> <span class="n">right</span> <span class="o">-</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">rightCount</span><span class="p">);</span>
<span class="n">rightCount</span><span class="o">++</span><span class="p">;</span>
<span class="n">curSwaps</span> <span class="o">-=</span> <span class="n">dis</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">curSwaps</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">leftCount</span> <span class="o">+</span> <span class="n">rightCount</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="o">--</span><span class="n">left</span><span class="p">;</span>
<span class="o">++</span><span class="n">right</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">};</span>
</code></pre></div></div>
<p>950
DP
三种纸杯蛋糕,相邻的朋友得到的蛋糕不一样。
很容易想出dp[i][j][k][l]表示前i个朋友,发了j个A纸杯蛋糕,k个B纸杯蛋糕,第i个朋友的蛋糕种类为l。问题是怎么处理最后一个人和第一个不能相同呢,其实只要枚举第一个蛋糕是哪种,DP三次,然后处理最后一个人获得的蛋糕即可。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MOD</span> <span class="o">=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">ColorfulCupcakesDivTwo</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="mi">55</span><span class="p">][</span><span class="mi">55</span><span class="p">][</span><span class="mi">55</span><span class="p">][</span><span class="mi">3</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">length</span><span class="p">,</span> <span class="n">count</span><span class="p">[</span><span class="mi">3</span><span class="p">];</span>
<span class="k">public</span><span class="o">:</span>
<span class="kt">void</span> <span class="n">work</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">i</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="c1">// 用A的数量
</span> <span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o"><=</span> <span class="n">i</span> <span class="o">-</span> <span class="n">j</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span> <span class="c1">// 用B的数量
</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">k</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="p">(</span><span class="n">i</span> <span class="o">-</span> <span class="n">j</span> <span class="o">-</span> <span class="n">k</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">j</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="p">(</span><span class="n">i</span> <span class="o">-</span> <span class="n">j</span> <span class="o">-</span> <span class="n">k</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">j</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">k</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">countArrangements</span><span class="p">(</span><span class="n">string</span> <span class="n">cupcakes</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">length</span> <span class="o">=</span> <span class="n">cupcakes</span><span class="p">.</span><span class="n">length</span><span class="p">();</span>
<span class="n">memset</span><span class="p">(</span><span class="n">count</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">count</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="o">++</span><span class="n">count</span><span class="p">[</span><span class="n">cupcakes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">'A'</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">work</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">length</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o"><=</span> <span class="n">length</span> <span class="o">-</span> <span class="n">j</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">work</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">length</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o"><=</span> <span class="n">length</span> <span class="o">-</span> <span class="n">j</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">2</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">work</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">length</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o"><=</span> <span class="n">length</span> <span class="o">-</span> <span class="n">j</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">ans</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">length</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">};</span>
</code></pre></div></div>
2012 Multi-University Training Contest 4
2012-08-08T05:41:54+00:00
http://greenmooon55.com/2012-multi-university-training-contest-4
<p>官方题解:<a href="http://page.renren.com/601081183/note/864084778">http://page.renren.com/601081183/note/864084778
</a>1001 <strong>Image Recognition</strong>
从01矩阵中找四条边都是1的正方形。
按照官方题解做的。
可以预处理出每一点上下左右四个方向上全部是1的长度,用l, r, u, d表示。接下来的想法是对于每条对角线(左上到右下),判断各点(i, j)到能到达的最远点(i + min(r[i][j], d[i][j], j + min(r[i][j], d[i][j]),共min(r[i][j], d[i][j]个点里,哪些点往左上可以延伸到原来的(i, j)点,也就是(x, y)的坐标减去min(l[x][y], u[x][y])。这样是三次方的算法,会超时的。
在扫描对角线的时候记录各点能往左上延伸到哪里,相当于记录下坐标。若点(i, j)为1,定义一个区间为从点(i, j)开始到最远点(i + min(r[i][j], d[i][j], j + min(r[i][j], d[i][j])。当扫描到区间始点时,减去左上延伸到始点(i, j)以外的点的个数,扫描到区间终点时,加上左上延伸到始点以外的点的个数,这样就能算出区间内符合条件的点的个数。用线段树来维护每个点往左上能延伸到哪里,线段树的每个区间存区间内点的个数即可。复杂度O(n^2*logn)。写得好累啊。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">1010</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">map</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">u</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">l</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">r</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">visit</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="k">struct</span> <span class="n">node</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">count</span><span class="p">;</span>
<span class="p">}</span><span class="n">tree</span><span class="p">[</span><span class="n">MAXN</span> <span class="o">*</span> <span class="mi">4</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">build</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">=</span> <span class="n">r</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">!=</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">);</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">insert</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">pos</span><span class="p">,</span> <span class="kt">int</span> <span class="n">value</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">count</span> <span class="o">+=</span> <span class="n">value</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pos</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="n">insert</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">value</span><span class="p">);</span>
<span class="k">else</span> <span class="n">insert</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">query</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">l</span> <span class="o">&&</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">==</span> <span class="n">r</span><span class="p">)</span> <span class="k">return</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">count</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">r</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">></span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">)</span> <span class="o">+</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">xx</span><span class="p">,</span> <span class="kt">int</span> <span class="n">yy</span><span class="p">,</span> <span class="kt">int</span> <span class="n">count</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">build</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">count</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="n">xx</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">yy</span><span class="p">;</span>
<span class="c1">//memset(visit, 0, sizeof(visit)); 会超时
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">visit</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">count</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="n">min</span><span class="p">(</span><span class="n">u</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">],</span> <span class="n">l</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span> <span class="n">ans</span> <span class="o">-=</span> <span class="n">query</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">insert</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="mi">1</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="n">min</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">],</span> <span class="n">r</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">])</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">visit</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="o">++</span><span class="n">visit</span><span class="p">[</span><span class="n">temp</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">visit</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">visit</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">query</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">visit</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="p">}</span>
<span class="o">++</span><span class="n">x</span><span class="p">;</span>
<span class="o">++</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">casenum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span><span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">map</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">u</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">u</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">u</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">memset</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">d</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">r</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span> <span class="o">>=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">--</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span> <span class="o">>=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">work</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">n</span> <span class="o">-</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">ans</span> <span class="o">+=</span> <span class="n">work</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span> <span class="o">-</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case %d: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">++</span><span class="n">casenum</span><span class="p">,</span> <span class="n">ans</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1004 <strong>Trouble</strong>
给出五组数,每组各取一个,问能否使和为一。
分成两组、两组、一组。前两组求所有情况,存在sum1里,中间两组存在sum2里,排序sum1、sum2,然后对于最后一组的每个数,找sum1、sum2里有没有两个数的和为这个数的相反数。复杂度O(n^3)。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">205</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">sum1</span><span class="p">[</span><span class="n">MAXN</span><span class="o">*</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">sum2</span><span class="p">[</span><span class="n">MAXN</span><span class="o">*</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">num</span><span class="p">[</span><span class="mi">6</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">5</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%I64d"</span><span class="p">,</span> <span class="o">&</span><span class="n">num</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sum1</span><span class="p">[</span><span class="n">count</span><span class="p">]</span> <span class="o">=</span> <span class="n">num</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="n">num</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="n">sum2</span><span class="p">[</span><span class="n">count</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">num</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="n">num</span><span class="p">[</span><span class="mi">3</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">sort</span><span class="p">(</span><span class="n">sum1</span><span class="p">,</span> <span class="n">sum1</span> <span class="o">+</span> <span class="n">count</span><span class="p">);</span>
<span class="n">sort</span><span class="p">(</span><span class="n">sum2</span><span class="p">,</span> <span class="n">sum2</span> <span class="o">+</span> <span class="n">count</span><span class="p">,</span> <span class="n">greater</span><span class="p">());</span>
<span class="kt">bool</span> <span class="n">found</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">goal</span> <span class="o">=</span> <span class="o">-</span><span class="n">num</span><span class="p">[</span><span class="mi">4</span><span class="p">][</span><span class="n">i</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">p1</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">p2</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">p1</span> <span class="o"><</span> <span class="n">count</span> <span class="o">&&</span> <span class="n">p2</span> <span class="o"><</span> <span class="n">count</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum1</span><span class="p">[</span><span class="n">p1</span><span class="p">]</span> <span class="o">+</span> <span class="n">sum2</span><span class="p">[</span><span class="n">p2</span><span class="p">]</span> <span class="o">==</span> <span class="n">goal</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">found</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum1</span><span class="p">[</span><span class="n">p1</span><span class="p">]</span> <span class="o">+</span> <span class="n">sum2</span><span class="p">[</span><span class="n">p2</span><span class="p">]</span> <span class="o"><</span> <span class="n">goal</span><span class="p">)</span> <span class="n">p1</span><span class="o">++</span><span class="p">;</span>
<span class="k">else</span> <span class="n">p2</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">found</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">found</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"Yes"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">puts</span><span class="p">(</span><span class="s">"No"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1009 <strong>Query</strong>
给出两个字符串,随时可能修改某个字符,找出从任意字符开始,最长字符相同的长度。
这题如果想到怎么建线段树就很好做了,可惜当时想不到。记录区间里第一个不同的字符的位置。找所求位置到最后第一个不同字符的位置即可。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXL</span> <span class="o">=</span> <span class="mi">1000010</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">s1</span><span class="p">[</span><span class="n">MAXL</span><span class="p">],</span> <span class="n">s2</span><span class="p">[</span><span class="n">MAXL</span><span class="p">];</span>
<span class="k">struct</span> <span class="n">node</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">pos</span><span class="p">;</span>
<span class="p">}</span><span class="n">tree</span><span class="p">[</span><span class="n">MAXL</span> <span class="o">*</span> <span class="mi">4</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">length</span><span class="p">;</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="n">getleft</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="k">return</span> <span class="n">b</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">b</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="k">return</span> <span class="n">a</span><span class="p">;</span>
<span class="k">return</span> <span class="n">min</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="n">build</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">=</span> <span class="n">r</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o"><</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">);</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">pos</span> <span class="o">=</span> <span class="n">getleft</span><span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="o">*</span><span class="mi">2</span><span class="p">].</span><span class="n">pos</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="o">*</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">].</span><span class="n">pos</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">l</span><span class="p">]</span> <span class="o">==</span> <span class="n">s2</span><span class="p">[</span><span class="n">l</span><span class="p">])</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">pos</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">else</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">pos</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">query</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">&&</span> <span class="n">r</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="k">return</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">pos</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">r</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">></span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span> <span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">return</span> <span class="n">getleft</span><span class="p">(</span><span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">),</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">));</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="n">modify</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">pos</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">==</span> <span class="n">s2</span><span class="p">[</span><span class="n">pos</span><span class="p">])</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">pos</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">else</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">pos</span> <span class="o">=</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pos</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="n">modify</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">pos</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pos</span> <span class="o">></span> <span class="n">mid</span><span class="p">)</span> <span class="n">modify</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">pos</span><span class="p">);</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">pos</span> <span class="o">=</span> <span class="n">getleft</span><span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="o">*</span><span class="mi">2</span><span class="p">].</span><span class="n">pos</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="o">*</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">].</span><span class="n">pos</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">caseno</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">action</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">pos</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">ch</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">useless</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case %d:</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">++</span><span class="n">caseno</span><span class="p">);</span>
<span class="n">gets</span><span class="p">(</span><span class="n">useless</span><span class="p">);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%s"</span><span class="p">,</span> <span class="n">s1</span><span class="p">);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%s"</span><span class="p">,</span> <span class="n">s2</span><span class="p">);</span>
<span class="n">length</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">s1</span><span class="p">),</span> <span class="n">strlen</span><span class="p">(</span><span class="n">s2</span><span class="p">));</span>
<span class="c1">//cout << length << endl;
</span> <span class="n">build</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">q</span><span class="p">;);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">q</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">action</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">action</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d %d %c"</span><span class="p">,</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="o">&</span><span class="n">pos</span><span class="p">;,</span> <span class="o">&</span><span class="n">ch</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pos</span> <span class="o">>=</span> <span class="n">length</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">==</span> <span class="n">ch</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">!=</span> <span class="n">s2</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">&&</span> <span class="n">ch</span> <span class="o">!=</span> <span class="n">s2</span><span class="p">[</span><span class="n">pos</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">s1</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">=</span> <span class="n">ch</span><span class="p">;</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="n">s1</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">=</span> <span class="n">ch</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s2</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">==</span> <span class="n">ch</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">!=</span> <span class="n">s2</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">&&</span> <span class="n">ch</span> <span class="o">!=</span> <span class="n">s1</span><span class="p">[</span><span class="n">pos</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">s2</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">=</span> <span class="n">ch</span><span class="p">;</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="n">s2</span><span class="p">[</span><span class="n">pos</span><span class="p">]</span> <span class="o">=</span> <span class="n">ch</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">modify</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">pos</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">pos</span><span class="p">;);</span>
<span class="kt">int</span> <span class="n">result</span> <span class="o">=</span> <span class="n">query</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">result</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">result</span> <span class="o">-</span> <span class="n">pos</span><span class="p">);</span>
<span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">length</span> <span class="o">-</span> <span class="n">pos</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
2012 Multi-University Training Contest 3
2012-08-08T04:09:17+00:00
http://greenmooon55.com/2012-multi-university-training-contest-3
<p>官方题解:<a href="http://blog.renren.com/blog/601081183/863771603">http://blog.renren.com/blog/601081183/863771603</a></p>
<p>1001 <strong>Arcane Numbers 1</strong>
问任意一个A进制有限小数,能否用B进制有限小数表示。
A进制小数可以转换为X*A^(-n),n为小数部分位数,这个数除以任意次B^(-i),i从1递增,直到得到一个整数,也就是说,如果A的质因子在B中都包含即可。注意A的某个质因子可能大于sqrt(A),这道题就因为这个WA到最后= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">1000010</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">prime</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">bool</span> <span class="n">notprime</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">primecount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">getprime</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">notprime</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">notprime</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">MAXN</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">notprime</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">prime</span><span class="p">[</span><span class="n">primecount</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o">*</span> <span class="n">j</span> <span class="o"><</span> <span class="n">MAXN</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">notprime</span><span class="p">[</span><span class="n">i</span> <span class="o">*</span> <span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="n">getprime</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tt</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tt</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tt</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: "</span><span class="p">,</span> <span class="n">tt</span><span class="p">);</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">a</span> <span class="o">>></span> <span class="n">b</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o"><</span> <span class="mi">0</span> <span class="o">||</span> <span class="n">b</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">puts</span><span class="p">(</span><span class="s">"NO"</span><span class="p">);</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="n">b</span> <span class="o">&&</span> <span class="n">a</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">puts</span><span class="p">(</span><span class="s">"YES"</span><span class="p">);</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o"><=</span> <span class="mi">1</span> <span class="o">||</span> <span class="n">b</span> <span class="o"><=</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">puts</span><span class="p">(</span><span class="s">"NO"</span><span class="p">);</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">end</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
<span class="kt">bool</span> <span class="n">ok</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">primecount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">></span> <span class="n">end</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">%</span> <span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">b</span> <span class="o">%</span> <span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ok</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">while</span> <span class="p">(</span><span class="n">a</span> <span class="o">%</span> <span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">/=</span> <span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">b</span> <span class="o">%</span> <span class="n">a</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="n">ok</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ok</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"YES"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">puts</span><span class="p">(</span><span class="s">"NO"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1004 <strong>Magic Number</strong>
求字符串间的<a href="http://zh.wikipedia.org/zh-cn/%E7%B7%A8%E8%BC%AF%E8%B7%9D%E9%9B%A2">编辑距离</a>
dp[i][j]可以表示为把第一个字符串前i个字符转换为第二个字符串前j个字符需要的操作数。
dp[i][j] = min(dp[i-1][j]+1(删除原串第i个字符), dp[i][j-1]+1(插入新串第j个字符), dp[i-1][j-1]+(oldstr[i]==newstr[j])?0:1(修改))</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">magic</span><span class="p">[</span><span class="mi">1510</span><span class="p">][</span><span class="mi">15</span><span class="p">];</span>
<span class="kt">char</span> <span class="n">query</span><span class="p">[</span><span class="mi">15</span><span class="p">];</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="n">min</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">c</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o"><</span> <span class="n">b</span><span class="p">)</span> <span class="k">return</span> <span class="n">a</span> <span class="o"><</span> <span class="n">c</span> <span class="o">?</span> <span class="n">a</span> <span class="o">:</span> <span class="n">c</span><span class="p">;</span>
<span class="k">else</span> <span class="k">return</span> <span class="n">b</span> <span class="o"><</span> <span class="n">c</span> <span class="o">?</span> <span class="n">b</span> <span class="o">:</span> <span class="n">c</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">f</span><span class="p">[</span><span class="mi">15</span><span class="p">][</span><span class="mi">15</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">limit</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">t</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tt</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tt</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tt</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">m</span><span class="p">;);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d:</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">tt</span><span class="p">);</span>
<span class="n">getchar</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">gets</span><span class="p">(</span><span class="n">magic</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">ii</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">ii</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">ii</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%s%d"</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="o">&</span><span class="n">limit</span><span class="p">;);</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">jj</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">jj</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">jj</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="n">strlen</span><span class="p">(</span><span class="n">query</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">y</span> <span class="o">=</span> <span class="n">strlen</span><span class="p">(</span><span class="n">magic</span><span class="p">[</span><span class="n">jj</span><span class="p">]);</span>
<span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">x</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">y</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">f</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">j</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">x</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">y</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="p">((</span><span class="n">query</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">magic</span><span class="p">[</span><span class="n">jj</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">?</span> <span class="mi">0</span><span class="o">:</span><span class="mi">1</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">]</span> <span class="o"><=</span> <span class="n">limit</span><span class="p">)</span> <span class="o">++</span><span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">ans</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1005 <strong>Triangle LOVE</strong>
给出一个<a href="http://en.wikipedia.org/wiki/Tournament_(graph_theory)">竞赛图</a>(由无向完全图给每条边加方向构成),问有没有长度为3的环。
方法一,从任意一点出发遍历整个图,搜的时候记录深度,找环。<a href="http://euyuil.com/2687/codeforces-117c-cycle/">http://euyuil.com/2687/codeforces-117c-cycle/</a>
官方题解里的增量算法有点晕。。
竞赛图上如果有环,则一定存在长度为3的环。因为若有长度为n的环,一定有长度为n-1的环,画一下就懂了。所以只要DFS判断有没有环即可。
最简单的想法:若存在两个点出度相同则存在长度为3的环。先找出两个点A和B,若A到B有边,此时A出度为1,B出度为0。对于其他任意一点C,有以下四种情况:AB出度都加一,AB出度不变、A出度加一,B出度不变、A出度不变,B出度加一。要想使AB出度相同,必须有B的出度加一、C的出度不变的情况,B到C、C到A有边才可以。这样ABC就形成了一个环。
神奇的图论啊!</p>
<p>1006 <strong>Flowers</strong>
花在一段时间内开放,问某一时刻最多开多少花。
很明显,离散化区间更新的线段树,没想到这道题过的人这么多。。大家都好强啊。
把每个区间离散为三个点,如[1,4]分为[1,1],[2,3]和[4,4]即可。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">100010</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">flower</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">;</span>
<span class="p">}</span><span class="n">f</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="k">struct</span> <span class="n">Node</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">sum</span><span class="p">,</span> <span class="n">inc</span><span class="p">;</span>
<span class="p">}</span><span class="n">tree</span><span class="p">[</span><span class="n">MAXN</span> <span class="o">*</span> <span class="mi">4</span> <span class="o">*</span> <span class="mi">4</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">mycount</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="n">MAXN</span> <span class="o">*</span> <span class="mi">2</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">build</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">=</span> <span class="n">r</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o"><</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">);</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">convert</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">left</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">right</span> <span class="o">=</span> <span class="n">mycount</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">left</span> <span class="o"><</span> <span class="n">right</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">left</span> <span class="o">+</span> <span class="n">right</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">></span> <span class="n">a</span><span class="p">[</span><span class="n">mid</span><span class="p">])</span> <span class="n">left</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span> <span class="n">right</span> <span class="o">=</span> <span class="n">mid</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">left</span> <span class="o">*</span> <span class="mi">2</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="n">getsegment</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="o">&</span><span class="n">s</span><span class="p">;,</span> <span class="kt">int</span> <span class="o">&</span><span class="n">t</span><span class="p">;)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">left</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">right</span> <span class="o">=</span> <span class="n">mycount</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">left</span> <span class="o"><=</span> <span class="n">right</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">left</span> <span class="o">+</span> <span class="n">right</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">==</span> <span class="n">a</span><span class="p">[</span><span class="n">mid</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">*</span> <span class="mi">2</span><span class="p">;</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">*</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">></span> <span class="n">a</span><span class="p">[</span><span class="n">mid</span><span class="p">]</span> <span class="o">&&</span> <span class="n">x</span> <span class="o"><</span> <span class="n">a</span><span class="p">[</span><span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">></span> <span class="n">a</span><span class="p">[</span><span class="n">mid</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">left</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">right</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="n">add</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">,</span> <span class="kt">int</span> <span class="n">value</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">l</span> <span class="o">&&</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">==</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">inc</span> <span class="o">+=</span> <span class="n">value</span><span class="p">;</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">></span> <span class="n">mid</span><span class="p">)</span> <span class="n">add</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">value</span><span class="p">);</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">r</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="n">add</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">value</span><span class="p">);</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">add</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span> <span class="p">,</span> <span class="n">mid</span><span class="p">,</span> <span class="n">value</span><span class="p">);</span>
<span class="n">add</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">query</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">&&</span> <span class="n">r</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">sum</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">inc</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">inc</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">add</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">inc</span><span class="p">);</span>
<span class="n">add</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">inc</span><span class="p">);</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">sum</span> <span class="o">+=</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">inc</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">inc</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">></span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">r</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span> <span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">)</span> <span class="o">+</span> <span class="n">query</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tt</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tt</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tt</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">tree</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">tree</span><span class="p">));</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d:</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">tt</span><span class="p">);</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">f</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">s</span><span class="p">,</span> <span class="o">&</span><span class="n">f</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">t</span><span class="p">);</span>
<span class="n">a</span><span class="p">[</span><span class="n">temp</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">s</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">temp</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">t</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">sort</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="n">temp</span><span class="p">);</span>
<span class="n">mycount</span> <span class="o">=</span> <span class="n">unique</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="n">temp</span><span class="p">)</span> <span class="o">-</span> <span class="n">a</span><span class="p">;</span>
<span class="n">build</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">(</span><span class="n">mycount</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">2</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">add</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">convert</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">s</span><span class="p">),</span> <span class="n">convert</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">t</span><span class="p">),</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">pos</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">pos</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">pos</span> <span class="o"><</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">||</span> <span class="n">pos</span> <span class="o">></span> <span class="n">a</span><span class="p">[</span><span class="n">mycount</span> <span class="o">-</span> <span class="mi">1</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"0</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">;</span>
<span class="n">getsegment</span><span class="p">(</span><span class="n">pos</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">query</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1009 <strong>Cut the cake</strong>
对于颜色相间的<strong>正方形</strong>,用dp[i][j]表示右下角为(i,j)的最大矩形边长,实时更新答案,首先判断(i,j),(i-1,j),(i,j-1)这三个点,若颜色不合法则记为1。若dp[i][j-1]等于dp[i-1][j],要判断左上角那个点的颜色是否符合。若dp[i][j-1]不等于dp[i-1][j],dp[i][j] = min(dp[i][j-1], dp[i-1][j]) + 1。
对于颜色相同的矩形,其实就是一个找最大子矩形的问题,推荐王知昆的论文《浅谈用极大化思想解决最大子矩形问题》,用到里面第二种方法。
定义悬线为从矩形上边,上端点覆盖了一个障碍点或达到整个矩形上端的有效竖线(不覆盖任何障碍点),把悬线尽量左右移动,就可以形成一个矩形。考虑每个悬线(最多N<em>M个)最多能移动多少就能求出最大子矩形。需要left[i][j],right[i][j],height[i][j]三个数组,分别记录,往左、往右、往上能移动到哪里。从上往下扫,然后每行从左往右、从右往左各扫一遍,leftmost记录最左非障碍点位置,left[i][j] = max(left[i-1][j], leftmost),右边同理。遇到障碍点就把left[i][j]置为1,right[i][j]置为m,height[i][j]置为0。O(N</em>M)</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">1010</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">map</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">height</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">l</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">r</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">work</span><span class="p">(</span><span class="kt">char</span> <span class="n">ch</span><span class="p">,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">m</span><span class="p">;)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">height</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">height</span><span class="p">));</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">leftmost</span> <span class="p">,</span> <span class="n">rightmost</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">m</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">r</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">m</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">leftmost</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">rightmost</span> <span class="o">=</span> <span class="n">m</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">m</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">!=</span> <span class="n">ch</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">leftmost</span> <span class="o">=</span> <span class="n">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">height</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="c1">//不影响下一行的min 和 max
</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">m</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">height</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">height</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">leftmost</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">m</span><span class="p">;</span> <span class="n">j</span> <span class="o">>=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="n">ch</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">rightmost</span><span class="p">);</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="p">(</span><span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">-</span> <span class="n">l</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">height</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="o">*</span> <span class="mi">2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">rightmost</span> <span class="o">=</span> <span class="n">j</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">char</span> <span class="n">s</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tt</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tt</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tt</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">m</span><span class="p">;);</span>
<span class="n">gets</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">gets</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">m</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">></span> <span class="mi">1</span> <span class="o">&&</span> <span class="n">j</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">count</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="n">count</span><span class="p">]</span> <span class="o">==</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">></span> <span class="n">ans</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">ans</span> <span class="o">*=</span> <span class="mi">4</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">work</span><span class="p">(</span><span class="sc">'B'</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">));</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">work</span><span class="p">(</span><span class="sc">'R'</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">));</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">tt</span><span class="p">,</span> <span class="n">ans</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>1010 <strong>MAP</strong>
我擦啊,这么简单的题意,说得这么恶心。用 map 和 set 写起来挺爽的,貌似数据都是按顺序的,用不到 map…
C++ 还有 istringstream 这么神奇的东西啊。貌似这题数据是\r\n,所以。。如果gets读换行符就会被坑了= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">;</span>
<span class="n">string</span> <span class="n">url</span><span class="p">;</span>
<span class="n">map</span><span class="o"><</span><span class="n">string</span><span class="p">,</span> <span class="kt">int</span><span class="o">></span> <span class="n">querymap</span><span class="p">;</span>
<span class="n">set</span> <span class="n">urlset</span><span class="p">[</span><span class="mi">105</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">c</span><span class="p">[</span><span class="mi">105</span><span class="p">];</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tt</span> <span class="o">=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tt</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tt</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="n">string</span> <span class="n">name</span><span class="p">;</span>
<span class="n">string</span> <span class="n">line</span><span class="p">;</span>
<span class="n">querymap</span><span class="p">.</span><span class="n">clear</span><span class="p">();</span>
<span class="n">memset</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">c</span><span class="p">));</span>
<span class="kt">double</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">name</span><span class="p">;</span>
<span class="n">querymap</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">pair</span><span class="o"><</span><span class="n">string</span><span class="p">,</span> <span class="kt">int</span><span class="o">></span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">i</span><span class="p">));</span>
<span class="n">urlset</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">clear</span><span class="p">();</span>
<span class="n">getline</span><span class="p">(</span><span class="n">cin</span><span class="p">,</span> <span class="n">line</span><span class="p">);</span>
<span class="n">istringstream</span> <span class="n">iss</span><span class="p">(</span><span class="n">line</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">iss</span> <span class="o">>></span> <span class="n">url</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//cout << url << endl;
</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="n">urlset</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">insert</span><span class="p">(</span><span class="n">url</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">name</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">index</span> <span class="o">=</span> <span class="n">querymap</span><span class="p">[</span><span class="n">name</span><span class="p">];</span>
<span class="n">getline</span><span class="p">(</span><span class="n">cin</span><span class="p">,</span> <span class="n">line</span><span class="p">);</span>
<span class="n">istringstream</span> <span class="n">iss</span><span class="p">(</span><span class="n">line</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">r</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">iss</span> <span class="o">>></span> <span class="n">url</span><span class="p">)</span>
<span class="p">{</span>
<span class="o">++</span><span class="n">r</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">urlset</span><span class="p">[</span><span class="n">index</span><span class="p">].</span><span class="n">count</span><span class="p">(</span><span class="n">url</span><span class="p">))</span>
<span class="p">{</span>
<span class="o">++</span><span class="n">count</span><span class="p">;</span>
<span class="n">sum</span> <span class="o">+=</span> <span class="n">count</span> <span class="o">/</span> <span class="p">(</span><span class="kt">double</span><span class="p">)</span><span class="n">r</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="n">ans</span> <span class="o">+=</span> <span class="n">sum</span> <span class="o">/</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: %.6lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">tt</span><span class="p">,</span> <span class="n">ans</span> <span class="o">/</span> <span class="n">n</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
Codeforces 78C Beaver Game
2012-08-06T16:08:12+00:00
http://greenmooon55.com/codeforces-78c-beaver-game
<p><a href="http://codeforces.com/problemset/problem/78/C">http://codeforces.com/problemset/problem/78/C</a></p>
<p>n块木头,每块长度为m,两人对战(呃,其实是beaver),每人选一块木头并把它分为<strong>长度相同</strong>的多块,每块长度不得小于k,不能继续分者输。</p>
<p>貌似yds讲过类似的题,第一想法就是如果是偶数块木头,先手输,因为此时后手可以完全复制先手的策略,先手必输。如果有奇数块木头,那么先手应该选一块,把它直接分成不可分割的各小块,这样问题转化成前一种情况(此时先手相当于新情况的后手)。如果不可分割先手直接输,否则胜。</p>
<p>于是从2到sqrt(m)枚举<strong>分成多少块</strong>即可,注意特殊情况:k=1时一定可分割。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="kt">bool</span> <span class="n">split</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">m</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">temp</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="n">m</span> <span class="o">%</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">m</span> <span class="o">/</span> <span class="n">i</span> <span class="o">>=</span> <span class="n">k</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">split</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">k</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">&&</span> <span class="n">m</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span> <span class="n">split</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">split</span> <span class="o">&&</span> <span class="n">n</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"Timur"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">puts</span><span class="p">(</span><span class="s">"Marsel"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>现在应该去做比赛的…刚才犹豫了一下没去做,于是睡觉去吧= =</p>
ZOJ Monthly, July 2012
2012-08-04T03:53:21+00:00
http://greenmooon55.com/zoj-monthly-july-2012
<p><a href="http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=339">118 - ZOJ Monthly, July 2012</a>
A <strong>Magic Number</strong>
找规律</p>
<p>B <strong>Battle Ships</strong>
敌人生命值为l,我们有n个船,每个船可以造无限个,造船时间为t[i],攻击力为attack[i]。
dp[i][j]表示攻击敌人i个生命值,当前攻击力为j时的时间最小花费。
dp[i + j * t[k]][j + attack[k]] = min(dp[i + j * t[k]][j + attack[k]], dp[i][j] + t[k])
比赛时想出来这个挺爽的,不过接下来就没出题目…</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">INF</span> <span class="o">=</span> <span class="mh">0x7f7f7f7f</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">POWERMAX</span> <span class="o">=</span> <span class="mi">330</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">l</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="mi">350</span><span class="p">][</span><span class="mi">350</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">[</span><span class="mi">50</span><span class="p">],</span> <span class="n">attack</span><span class="p">[</span><span class="mi">50</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">l</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">127</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">t</span><span class="p">;[</span><span class="n">i</span><span class="p">],</span> <span class="o">&</span><span class="n">attack</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">INF</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">l</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">POWERMAX</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="n">INF</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">+</span> <span class="n">attack</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o"><=</span> <span class="n">POWERMAX</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="n">j</span> <span class="o">*</span> <span class="n">t</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o"><</span> <span class="n">l</span><span class="p">)</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="n">j</span> <span class="o">*</span> <span class="n">t</span><span class="p">[</span><span class="n">k</span><span class="p">]][</span><span class="n">j</span> <span class="o">+</span> <span class="n">attack</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="n">j</span> <span class="o">*</span><span class="n">t</span><span class="p">[</span><span class="n">k</span><span class="p">]][</span><span class="n">j</span> <span class="o">+</span> <span class="n">attack</span><span class="p">[</span><span class="n">k</span><span class="p">]],</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="n">t</span><span class="p">[</span><span class="n">k</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="n">j</span> <span class="o">>=</span> <span class="n">l</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">j</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>E <strong>Treasure Hunt I</strong>
一棵树,某人从一点出发,在限定的时间内返回,求最大收益。
简单的树形DP,这种题目很少写,非常不熟练。dp[node][j]表示<strong>刚好</strong>用j个单位时间遍历node获得的最大值,具体思路见代码,j要递减,保证dp[node][j-l-map[node][i]*2]表示从node出发,走0到i-1节点后获得的最大值,</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">105</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">INF</span> <span class="o">=</span> <span class="mh">0x7f7f7f7f</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">v</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">map</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="mi">205</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">dfs</span><span class="p">(</span><span class="kt">int</span> <span class="n">node</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span><span class="p">[</span><span class="n">node</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">INF</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">dfs</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="n">m</span><span class="p">;</span> <span class="n">j</span> <span class="o">></span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">l</span> <span class="o">+</span> <span class="n">map</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span> <span class="o"><=</span> <span class="n">j</span><span class="p">;</span> <span class="n">l</span><span class="o">++</span><span class="p">)</span>
<span class="n">dp</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">l</span><span class="p">]</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="n">l</span><span class="o">-</span><span class="n">map</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="mi">2</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">v</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="kt">int</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">map</span><span class="p">,</span> <span class="mi">127</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">map</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">u</span><span class="p">;,</span> <span class="o">&</span><span class="n">v</span><span class="p">;,</span> <span class="o">&</span><span class="n">w</span><span class="p">;);</span>
<span class="n">map</span><span class="p">[</span><span class="n">u</span><span class="p">][</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="n">map</span><span class="p">[</span><span class="n">v</span><span class="p">][</span><span class="n">u</span><span class="p">]</span> <span class="o">=</span> <span class="n">w</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">k</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="n">dfs</span><span class="p">(</span><span class="n">k</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">m</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">dp</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">i</span><span class="p">]);</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>H <strong>Treasure Hunt IV</strong>
找规律,刚开始没发现和平方有关,交上去TLE,囧。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">bool</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">x</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">sum</span> <span class="o">+=</span> <span class="n">x</span> <span class="o">/</span> <span class="n">i</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="nf">getans</span><span class="p">(</span><span class="kt">long</span> <span class="kt">long</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">a</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="n">a</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">a</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span> <span class="o">-</span> <span class="n">a</span> <span class="o">*</span> <span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">else</span> <span class="k">return</span> <span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">a</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">a</span> <span class="o">>></span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="n">cout</span> <span class="o"><<</span> <span class="n">getans</span><span class="p">(</span><span class="n">b</span><span class="p">)</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">else</span> <span class="n">cout</span> <span class="o"><<</span> <span class="n">getans</span><span class="p">(</span><span class="n">b</span><span class="p">)</span> <span class="o">-</span> <span class="n">getans</span><span class="p">(</span><span class="n">a</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>J <strong>Watashi’s BG</strong>
原来BG是<a href="http://zhidao.baidu.com/question/40254871">请客的意思</a>啊。物品数为30,容量为10000000的背包。
原来…搜索就可以过。两个减枝,一是要排序,二是如果后面那些都取还没有当前答案大,那就不用搜索了。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">cost</span><span class="p">[</span><span class="mi">35</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">sum</span><span class="p">[</span><span class="mi">35</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">ans</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">search</span><span class="p">(</span><span class="kt">int</span> <span class="n">p</span><span class="p">,</span> <span class="kt">int</span> <span class="n">money</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//cout << p << " " << money << endl;
</span> <span class="k">if</span> <span class="p">(</span><span class="n">ans</span> <span class="o">==</span> <span class="n">m</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">money</span> <span class="o">></span> <span class="n">ans</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">money</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">p</span> <span class="o">==</span> <span class="n">n</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="o">+</span> <span class="n">money</span> <span class="o"><=</span> <span class="n">ans</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="n">search</span><span class="p">(</span><span class="n">p</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">money</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">money</span> <span class="o">+</span> <span class="n">cost</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="o"><=</span> <span class="n">m</span><span class="p">)</span> <span class="n">search</span><span class="p">(</span><span class="n">p</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">money</span> <span class="o">+</span> <span class="n">cost</span><span class="p">[</span><span class="n">p</span><span class="p">]);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">cost</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">sort</span><span class="p">(</span><span class="n">cost</span><span class="p">,</span> <span class="n">cost</span> <span class="o">+</span> <span class="n">n</span><span class="p">,</span> <span class="n">greater</span><span class="p">());</span>
<span class="n">memset</span><span class="p">(</span><span class="n">sum</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">sum</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">>=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sum</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">cost</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">search</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>另外一个想法,把物品分成两份,各15个,于是两侧各2^15种情况,对于每种情况在另外那边二分找最适合的,需要先排序。曾经把这个二分写错。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">55</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="mi">32768</span><span class="p">],</span> <span class="n">b</span><span class="p">[</span><span class="mi">32768</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">cost</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">calculate</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">ar</span><span class="p">,</span> <span class="kt">int</span> <span class="n">left</span><span class="p">,</span> <span class="kt">int</span> <span class="n">right</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">end</span> <span class="o">=</span> <span class="mi">2</span> <span class="o"><<</span> <span class="p">(</span><span class="n">right</span><span class="o">-</span><span class="n">left</span><span class="p">)</span> <span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">end</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">ar</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">i</span><span class="p">;</span> <span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">&</span> <span class="n">j</span><span class="p">)</span> <span class="n">ar</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="n">cost</span><span class="p">[</span><span class="n">left</span> <span class="o">+</span> <span class="n">count</span><span class="p">];</span>
<span class="n">j</span> <span class="o">=</span> <span class="n">j</span> <span class="o"><<</span> <span class="mi">1</span><span class="p">;</span>
<span class="o">++</span><span class="n">count</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">end</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">search</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">ar</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">,</span> <span class="kt">int</span> <span class="n">m</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//cout << l << " " << r << " " << m << endl;
</span> <span class="kt">int</span> <span class="n">left</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">right</span> <span class="o">=</span> <span class="n">r</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">left</span> <span class="o"><</span> <span class="n">right</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">left</span> <span class="o">+</span> <span class="n">right</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ar</span><span class="p">[</span><span class="n">mid</span><span class="p">]</span> <span class="o"><=</span> <span class="n">m</span> <span class="o">&&</span> <span class="n">ar</span><span class="p">[</span><span class="n">mid</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">></span> <span class="n">m</span><span class="p">)</span> <span class="k">return</span> <span class="n">ar</span><span class="p">[</span><span class="n">mid</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ar</span><span class="p">[</span><span class="n">mid</span><span class="p">]</span> <span class="o"><=</span> <span class="n">m</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">left</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">right</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ar</span><span class="p">[</span><span class="n">left</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">cost</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>
<span class="n">memset</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="mi">127</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">a</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="mi">127</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">b</span><span class="p">));</span>
<span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o"><=</span> <span class="mi">15</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">end</span> <span class="o">=</span> <span class="n">calculate</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">);</span>
<span class="n">sort</span><span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="n">end</span><span class="p">);</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">search</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">end</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">aend</span> <span class="o">=</span> <span class="n">calculate</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">15</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">bend</span> <span class="o">=</span> <span class="n">calculate</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="mi">16</span><span class="p">,</span> <span class="n">n</span><span class="p">);</span>
<span class="n">sort</span><span class="p">(</span><span class="n">b</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">b</span> <span class="o">+</span> <span class="n">bend</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">aend</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">></span> <span class="n">m</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="n">search</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">bend</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">m</span> <span class="o">-</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">+</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>也可以两边都排序,然后扫一遍就行,这种会更好写。</p>
<p>K <strong>Watermelon Full of Water</strong>
买西瓜的时候一定选西瓜延续到当天并且花费最少的策略。(西瓜放这么多天不会坏吗…)
贪心、堆。用一个结构体wm存延续到哪一天last,和总花费cost,根据cost构造最小堆。堆初始化为0 0,如果延续不到“今天”就pop,然后根据堆顶元素创建新的wm,再push进去就好了。xenocide 写的代码好短。。好强大。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">50010</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">wm</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">last</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">cost</span><span class="p">;</span>
<span class="p">};</span>
<span class="kt">bool</span> <span class="k">operator</span> <span class="o"><</span> <span class="p">(</span><span class="k">const</span> <span class="n">wm</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">wm</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">cost</span> <span class="o">></span> <span class="n">b</span><span class="p">.</span><span class="n">cost</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">last</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span> <span class="c1">// last[i] 表示第 i 天必须买瓜(从0开始)
</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">price</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="n">priority_queue</span> <span class="n">q</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">price</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">last</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">while</span> <span class="p">(</span><span class="o">!</span><span class="n">q</span><span class="p">.</span><span class="n">empty</span><span class="p">())</span> <span class="n">q</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
<span class="n">wm</span> <span class="n">temp</span><span class="p">;</span>
<span class="n">temp</span><span class="p">.</span><span class="n">cost</span> <span class="o">=</span> <span class="n">temp</span><span class="p">.</span><span class="n">last</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">q</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="n">q</span><span class="p">.</span><span class="n">top</span><span class="p">().</span><span class="n">last</span> <span class="o"><</span> <span class="n">i</span><span class="p">)</span> <span class="n">q</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
<span class="n">temp</span> <span class="o">=</span> <span class="n">q</span><span class="p">.</span><span class="n">top</span><span class="p">();</span>
<span class="n">temp</span><span class="p">.</span><span class="n">cost</span> <span class="o">+=</span> <span class="n">price</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">temp</span><span class="p">.</span><span class="n">last</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="n">last</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">q</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">while</span> <span class="p">(</span><span class="n">q</span><span class="p">.</span><span class="n">top</span><span class="p">().</span><span class="n">last</span> <span class="o"><</span> <span class="n">n</span><span class="p">)</span> <span class="n">q</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">q</span><span class="p">.</span><span class="n">top</span><span class="p">().</span><span class="n">cost</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>To do:
最后一题的线段树解法是什么意思
F题应该可以做,估计会很麻烦
C题xw给我讲了比较神奇的思路,应该也可做</p>
2012 Multi-University Training Contest 2
2012-07-28T13:20:29+00:00
http://greenmooon55.com/2012-multi-university-training-contest-2
<p>官方题解:<a href="http://blog.renren.com/blog/601081183/862977450">http://blog.renren.com/blog/601081183/862977450</a></p>
<p><strong>1001 Hero</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4310">HDU4310</a>
每个英雄都有HP和DPS,玩家有无穷HP,DPS为1。每回合玩家选择一个英雄攻击,该英雄HP减一,同时玩家HP减去当前活着的英雄的DPS和。问如何攻击对手,损失HP最少。
官方题解上写的是状态压缩DP,其实当时看那么多人都过了,果断贪心,按DPS/HP递减排序攻击就行,我感觉这个贪心是对的吧。。</p>
<blockquote>
<p>用dp[mask]表示杀死mask集合的敌人时,这些敌人造成的最小hp消耗。有转移方程dp[mask] = min{dp[mask - {i}] + hp_sum[mask] * dps[i], for all i in mask}</p>
</blockquote>
<p>额,相当于先攻击后那个{i}。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dp</span><span class="p">[</span><span class="mi">1</span> <span class="o"><<</span> <span class="mi">20</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">getdps</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="o">*</span><span class="n">dps</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">p</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o"><=</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">&</span> <span class="n">i</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">dps</span><span class="p">[</span><span class="n">p</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">i</span> <span class="o">=</span> <span class="n">i</span> <span class="o"><<</span> <span class="mi">1</span><span class="p">;</span>
<span class="o">++</span><span class="n">p</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dps</span><span class="p">[</span><span class="mi">25</span><span class="p">],</span> <span class="n">hp</span><span class="p">[</span><span class="mi">25</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">127</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">dps</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">>></span> <span class="n">hp</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="p">(</span><span class="mi">1</span> <span class="o"><<</span> <span class="n">n</span><span class="p">);</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">p</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dpssum</span> <span class="o">=</span> <span class="n">getdps</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">dps</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">j</span> <span class="o"><=</span> <span class="n">i</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">j</span> <span class="o">^</span> <span class="n">i</span><span class="p">;</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">dp</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span> <span class="o">+</span> <span class="n">dpssum</span> <span class="o">*</span> <span class="n">hp</span><span class="p">[</span><span class="n">p</span><span class="p">]);</span>
<span class="n">j</span> <span class="o">=</span> <span class="n">j</span> <span class="o"><<</span> <span class="mi">1</span><span class="p">;</span>
<span class="o">++</span><span class="n">p</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">dp</span><span class="p">[(</span><span class="mi">1</span> <span class="o"><<</span> <span class="n">n</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>1002 Meeting point-1</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4311">HDU4311</a>
用坐标表示每个人的住处,只能上下左右走。选择一个住处聚会,使所有人到达这里的距离和最小。
刚开始也是没思路,后来xw说,可以分别算x和y方向的距离,先按x排序,算出其他点到第一个点x方向的距离和(sumx[0]),然后递推算出每一个sumx,再按y排序,算出每个sumy。index记录到底是哪个点。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">100010</span><span class="p">;</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">point</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">index</span><span class="p">;</span>
<span class="p">}</span><span class="n">px</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">py</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">sumx</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">sumy</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">bool</span> <span class="n">compx</span><span class="p">(</span><span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">x</span> <span class="o"><</span> <span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">compy</span><span class="p">(</span><span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">y</span> <span class="o"><</span> <span class="n">b</span><span class="p">.</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span><span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">sumx</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">sumx</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">sumy</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">sumy</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">ans</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">px</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">,</span> <span class="o">&</span><span class="n">px</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">);</span>
<span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">index</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">sort</span><span class="p">(</span><span class="n">px</span><span class="p">,</span> <span class="n">px</span><span class="o">+</span><span class="n">n</span><span class="p">,</span> <span class="n">compx</span><span class="p">);</span>
<span class="n">sort</span><span class="p">(</span><span class="n">py</span><span class="p">,</span> <span class="n">py</span><span class="o">+</span><span class="n">n</span><span class="p">,</span> <span class="n">compy</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sumx</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">-</span> <span class="n">px</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">x</span><span class="p">;</span>
<span class="n">sumy</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="o">-</span> <span class="n">py</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">ans</span><span class="p">[</span><span class="n">px</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumx</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="n">ans</span><span class="p">[</span><span class="n">py</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumy</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sumx</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">sumx</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">-</span> <span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="kt">long</span> <span class="kt">long</span><span class="p">)(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span> <span class="o">-</span> <span class="n">n</span><span class="p">);</span>
<span class="n">sumy</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">sumy</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="o">-</span> <span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="n">y</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="kt">long</span> <span class="kt">long</span><span class="p">)(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span> <span class="o">-</span> <span class="n">n</span><span class="p">);</span>
<span class="c1">//sumx[i] = sumx[i-1] - (px[i].x - px[i-1].x) * (n - i) + ;
</span> <span class="c1">//sumy[i] = sumy[i-1] - (py[i].y - py[i-1].y) * (n - i);
</span> <span class="n">ans</span><span class="p">[</span><span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumx</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">ans</span><span class="p">[</span><span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumy</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="cm">/*
cout <<"sumx" << endl;
for (int i = 0; i < n; i++) cout << sumx[i] << endl;
cout << "sumy" << endl;
for (int i = 0; i < n; i++) cout << sumy[i] << endl;
*/</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">bestans</span> <span class="o">=</span> <span class="mi">999999999999999LL</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o"><</span> <span class="n">bestans</span><span class="p">)</span> <span class="n">bestans</span> <span class="o">=</span> <span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">bestans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>Meeting point-2</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4312">HDU4312</a>
和上一道题的意思基本一样,这次可以斜着走,斜着走距离仍为1而不是根号二。
看了题解才知道,原来还有<a href="http://zh.wikipedia.org/wiki/%E5%88%87%E6%AF%94%E9%9B%AA%E5%A4%AB%E8%B7%9D%E7%A6%BB">切比雪夫距离</a>、<a href="http://zh.wikipedia.org/zh-cn/%E6%9B%BC%E5%93%88%E9%A0%93%E8%B7%9D%E9%9B%A2">曼哈顿距离</a>。</p>
<blockquote>
<p>对于原坐标系中两点间的 Chebyshev 距离,是将坐标轴顺时针旋转45度并将所有点的坐标值放大sqrt(2)倍所得到的新坐标系中的Manhattan距离的二分之一。</p>
</blockquote>
<p>这个挺神奇的,现在曼哈顿距离为2的两个点在原坐标系里切比雪夫距离为1。新坐标为 (x-y, x+y),怎么算的呢?转换成极坐标然后就能算了,刚才我都忘了= =然后还用上道题的代码就可以了。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">100010</span><span class="p">;</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">point</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">index</span><span class="p">;</span>
<span class="p">}</span><span class="n">px</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">py</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">sumx</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">sumy</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">bool</span> <span class="n">compx</span><span class="p">(</span><span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">x</span> <span class="o"><</span> <span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">compy</span><span class="p">(</span><span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">point</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">y</span> <span class="o"><</span> <span class="n">b</span><span class="p">.</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span><span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">sumx</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">sumx</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">sumy</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">sumy</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">ans</span><span class="p">));</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">tempx</span><span class="p">,</span> <span class="n">tempy</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//cin >> tempx >> tempy;
</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%I64d%I64d"</span><span class="p">,</span> <span class="o">&</span><span class="n">tempx</span><span class="p">;,</span> <span class="o">&</span><span class="n">tempy</span><span class="p">;);</span>
<span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">index</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">=</span> <span class="n">tempx</span> <span class="o">-</span> <span class="n">tempy</span><span class="p">;</span>
<span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="o">=</span> <span class="n">tempx</span> <span class="o">+</span> <span class="n">tempy</span><span class="p">;</span>
<span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">sort</span><span class="p">(</span><span class="n">px</span><span class="p">,</span> <span class="n">px</span><span class="o">+</span><span class="n">n</span><span class="p">,</span> <span class="n">compx</span><span class="p">);</span>
<span class="n">sort</span><span class="p">(</span><span class="n">py</span><span class="p">,</span> <span class="n">py</span><span class="o">+</span><span class="n">n</span><span class="p">,</span> <span class="n">compy</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sumx</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">-</span> <span class="n">px</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">x</span><span class="p">;</span>
<span class="n">sumy</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="o">-</span> <span class="n">py</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">ans</span><span class="p">[</span><span class="n">px</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumx</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="n">ans</span><span class="p">[</span><span class="n">py</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumy</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sumx</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">sumx</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">-</span> <span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="kt">long</span> <span class="kt">long</span><span class="p">)(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span> <span class="o">-</span> <span class="n">n</span><span class="p">);</span>
<span class="n">sumy</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">sumy</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="p">(</span><span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="o">-</span> <span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">].</span><span class="n">y</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="kt">long</span> <span class="kt">long</span><span class="p">)(</span><span class="mi">2</span><span class="o">*</span><span class="n">i</span> <span class="o">-</span> <span class="n">n</span><span class="p">);</span>
<span class="n">ans</span><span class="p">[</span><span class="n">px</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumx</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">ans</span><span class="p">[</span><span class="n">py</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">index</span><span class="p">]</span> <span class="o">+=</span> <span class="n">sumy</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">bestans</span> <span class="o">=</span> <span class="mi">999999999999999LL</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o"><</span> <span class="n">bestans</span><span class="p">)</span> <span class="n">bestans</span> <span class="o">=</span> <span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">bestans</span> <span class="o">/</span> <span class="mi">2</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>1004 Matrix</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4313">HDU4313</a>
一棵树上有K个机器,要使这K个机器互不相连,使去掉的边的权值和最小。
类似于Kruskal求最小生成树,边由大到小排序,如果某条边使两个机器连通就放弃这条边。因为其它的边一定比这条边长。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">100010</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">e</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span><span class="p">;</span>
<span class="p">}</span><span class="n">edge</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">p</span><span class="p">[</span><span class="n">MAXN</span><span class="p">],</span> <span class="n">rank</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">bool</span> <span class="n">machine</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">bool</span> <span class="n">comp</span><span class="p">(</span><span class="k">const</span> <span class="n">e</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">e</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">w</span> <span class="o">></span> <span class="n">b</span><span class="p">.</span><span class="n">w</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="n">make_set</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="c1">// ?
</span> <span class="p">{</span>
<span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">rank</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">find_set</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">!=</span> <span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">])</span> <span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">find_set</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">]);</span>
<span class="k">return</span> <span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">kruskal</span><span class="p">(</span><span class="kt">int</span> <span class="n">edgecount</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">make_set</span><span class="p">();</span>
<span class="n">sort</span><span class="p">(</span><span class="n">edge</span><span class="p">,</span> <span class="n">edge</span> <span class="o">+</span> <span class="n">edgecount</span><span class="p">,</span> <span class="n">comp</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">edgecount</span> <span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">find_set</span><span class="p">(</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">u</span><span class="p">);</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">find_set</span><span class="p">(</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">machine</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">&&</span> <span class="n">machine</span><span class="p">[</span><span class="n">y</span><span class="p">])</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">machine</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">||</span> <span class="n">machine</span><span class="p">[</span><span class="n">y</span><span class="p">])</span>
<span class="n">machine</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">machine</span><span class="p">[</span><span class="n">y</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">!=</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">w</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rank</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">></span> <span class="n">rank</span><span class="p">[</span><span class="n">y</span><span class="p">])</span> <span class="n">p</span><span class="p">[</span><span class="n">y</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">=</span> <span class="n">y</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rank</span><span class="p">[</span><span class="n">x</span><span class="p">]</span> <span class="o">==</span> <span class="n">rank</span><span class="p">[</span><span class="n">y</span><span class="p">])</span> <span class="n">rank</span><span class="p">[</span><span class="n">y</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">ans</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">totaldis</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">edge</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">u</span><span class="p">,</span> <span class="o">&</span><span class="n">edge</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span><span class="p">,</span> <span class="o">&</span><span class="n">edge</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">w</span><span class="p">);</span>
<span class="n">totaldis</span> <span class="o">+=</span> <span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">w</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">memset</span><span class="p">(</span><span class="n">machine</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">machine</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">k</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">temp</span><span class="p">;);</span>
<span class="n">machine</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">totaldis</span> <span class="o">-</span> <span class="n">kruskal</span><span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>1009 Power transmission</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4318">HDU4318</a>
送电,每个边都有一个损耗的百分比,经过之后就会损失一些电能,每个点不能重复路过,从起始点到终点求一条损耗最小的路。
刚开始还搜索。。显然会TLE,后来xw有个小错误没写完。Dijkstra最短路,dist数组里存走到某个点剩下的百分比,每次选最大的。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">50010</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">dis</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="mi">55</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">edge</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="mi">55</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">bool</span> <span class="n">used</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">dist</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">s</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">m</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dist</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dist</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">edge</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]);</span>
<span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">edge</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="o">&</span><span class="n">temp</span><span class="p">;);</span>
<span class="n">dis</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">temp</span> <span class="o">*</span> <span class="mf">0.01</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">s</span> <span class="o">>></span> <span class="n">t</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="n">dist</span><span class="p">[</span><span class="n">s</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">used</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">used</span><span class="p">));</span>
<span class="kt">int</span> <span class="n">nodenow</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">mindis</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">mindis</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">used</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">&&</span> <span class="n">dist</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">></span> <span class="n">mindis</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">mindis</span> <span class="o">=</span> <span class="n">dist</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">nodenow</span> <span class="o">=</span> <span class="n">j</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">fabs</span><span class="p">(</span><span class="n">mindis</span><span class="p">)</span> <span class="o"><</span> <span class="mf">1e-6</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">used</span><span class="p">[</span><span class="n">nodenow</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">nodenow</span> <span class="o">==</span> <span class="n">t</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">edge</span><span class="p">[</span><span class="n">nodenow</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">newnode</span> <span class="o">=</span> <span class="n">edge</span><span class="p">[</span><span class="n">nodenow</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">dist</span><span class="p">[</span><span class="n">nodenow</span><span class="p">]</span> <span class="o">*</span> <span class="n">dis</span><span class="p">[</span><span class="n">nodenow</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">used</span><span class="p">[</span><span class="n">newnode</span><span class="p">]</span> <span class="o">&&</span> <span class="n">temp</span> <span class="o">></span> <span class="n">dist</span><span class="p">[</span><span class="n">newnode</span><span class="p">])</span> <span class="n">dist</span><span class="p">[</span><span class="n">newnode</span><span class="p">]</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="n">t</span><span class="p">])</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%.2lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">m</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">dist</span><span class="p">[</span><span class="n">t</span><span class="p">]));</span>
<span class="k">else</span> <span class="n">puts</span><span class="p">(</span><span class="s">"IMPOSSIBLE!"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
2012 Multi-University Training Contest 1
2012-07-28T11:59:42+00:00
http://greenmooon55.com/2012-multi-university-training-contest-1
<p>官方题解:<a href="http://page.renren.com/601081183/note/861865911">2012 Multi-University Training Contest 1 Solution Report</a></p>
<p><strong>1001 Clairewd’s message</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4300">HDU4300</a>
给出一个密码转换表和一个字符串(消息),这个消息由密文和原文组成,原文部分可能不完全,求最短可能的原文。
官方题解说要用到KMP,比赛的时候看到有那么多人过,根本没考虑复杂度,我是用给出的原文到密文的转换表求出密文的原文的转换表,然后随便搞搞就过了。</p>
<p><strong>1002 Divide Chocolate</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4301">HDU4301</a>
把2*n的巧克力分为k块,问有多少种方法?
f[i][j][0]表示前i行分成了j块,且第i行两格巧克力未被分开。
f[i][j][1]表示前i行分成了j块,且第i行两格巧克力属于不同的两块。
详见官方题解</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MOD</span> <span class="o">=</span> <span class="mi">100000007</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">f</span><span class="p">[</span><span class="mi">1010</span><span class="p">][</span><span class="mi">2020</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">));</span>
<span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">k</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span><span class="p">)</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span><span class="p">)</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="n">f</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">k</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">%</span> <span class="n">MOD</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>1003 Holedox Eating</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4302">HDU4302</a>
每个时刻有两种动作,放食物和吃食物,吃的时候选择离当前位置最近的食物。
线段树,区间里记录最左面和最右面的食物位置,曾经把MAX设得太大导致RUNTIME ERROR(ACCESS_VIOLATION),花了好久才明白是哪里错了。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">N</span> <span class="o">=</span> <span class="mi">100010</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">Node</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">leftmost</span><span class="p">,</span> <span class="n">rightmost</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">count</span><span class="p">;</span>
<span class="p">}</span><span class="n">tree</span><span class="p">[</span><span class="n">N</span> <span class="o">*</span> <span class="mi">4</span><span class="p">];</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAX</span> <span class="o">=</span> <span class="mi">1083647</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MIN</span> <span class="o">=</span> <span class="o">-</span><span class="n">MAX</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">LEFT_TO_RIGHT</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">RIGHT_TO_LEFT</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">build</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">=</span> <span class="n">l</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">=</span> <span class="n">r</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">leftmost</span> <span class="o">=</span> <span class="n">MAX</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">rightmost</span> <span class="o">=</span> <span class="n">MIN</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o"><</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">);</span>
<span class="n">build</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">insert</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">place</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">leftmost</span> <span class="o">></span> <span class="n">place</span><span class="p">)</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">leftmost</span> <span class="o">=</span> <span class="n">place</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">rightmost</span> <span class="o"><</span> <span class="n">place</span><span class="p">)</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">rightmost</span> <span class="o">=</span> <span class="n">place</span><span class="p">;</span>
<span class="o">++</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">count</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">place</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="n">insert</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">place</span><span class="p">);</span>
<span class="k">else</span> <span class="n">insert</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">place</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">remove</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">place</span><span class="p">)</span>
<span class="p">{</span>
<span class="o">--</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">count</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">// 这个位置没有蛋糕了,要恢复MAX和MIN
</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">count</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">leftmost</span> <span class="o">=</span> <span class="n">MAX</span><span class="p">;</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">rightmost</span> <span class="o">=</span> <span class="n">MIN</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">place</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="n">remove</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">place</span><span class="p">);</span>
<span class="k">else</span> <span class="n">remove</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">place</span><span class="p">);</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">leftmost</span> <span class="o">=</span> <span class="n">min</span><span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">].</span><span class="n">leftmost</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">].</span><span class="n">leftmost</span><span class="p">);</span>
<span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">rightmost</span> <span class="o">=</span> <span class="n">max</span><span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">].</span><span class="n">rightmost</span><span class="p">,</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">].</span><span class="n">rightmost</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">getleftmost</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//printf("%d %d %d %d %d\n", num, tree[num].l, tree[num].r, l, r);
</span> <span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">l</span> <span class="o">&&</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">==</span> <span class="n">r</span><span class="p">)</span> <span class="k">return</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">leftmost</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">r</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">getleftmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">></span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">getleftmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">return</span> <span class="n">min</span><span class="p">(</span><span class="n">getleftmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">),</span> <span class="n">getleftmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">));</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">getrightmost</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">l</span><span class="p">,</span> <span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//printf("%d %d %d %d %d\n", num, tree[num].l, tree[num].r, l, r);
</span> <span class="k">if</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">==</span> <span class="n">l</span> <span class="o">&&</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span> <span class="o">==</span> <span class="n">r</span><span class="p">)</span> <span class="k">return</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">rightmost</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">l</span> <span class="o">+</span> <span class="n">tree</span><span class="p">[</span><span class="n">num</span><span class="p">].</span><span class="n">r</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">r</span> <span class="o"><=</span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">getrightmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span> <span class="o">></span> <span class="n">mid</span><span class="p">)</span> <span class="k">return</span> <span class="n">getrightmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">r</span><span class="p">);</span>
<span class="k">return</span> <span class="n">max</span><span class="p">(</span><span class="n">getrightmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">mid</span><span class="p">),</span> <span class="n">getrightmost</span><span class="p">(</span><span class="n">num</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">r</span><span class="p">));</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span> <span class="n">l</span><span class="p">,</span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tcase</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tcase</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tcase</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">l</span><span class="p">;,</span> <span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="n">build</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">l</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">pos</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">direction</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">temp</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="c1">// 放蛋糕
</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">x</span><span class="p">;);</span>
<span class="n">insert</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="c1">// 吃蛋糕
</span> <span class="p">{</span>
<span class="kt">int</span> <span class="n">rightmost</span> <span class="o">=</span> <span class="n">getrightmost</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pos</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">leftmost</span> <span class="o">=</span> <span class="n">getleftmost</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">pos</span><span class="p">,</span> <span class="n">l</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rightmost</span> <span class="o">==</span> <span class="n">MIN</span> <span class="o">&&</span> <span class="n">leftmost</span> <span class="o">==</span> <span class="n">MAX</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">disleft</span> <span class="o">=</span> <span class="n">pos</span> <span class="o">-</span> <span class="n">rightmost</span><span class="p">;</span> <span class="c1">// 向左走的距离
</span> <span class="kt">int</span> <span class="n">disright</span> <span class="o">=</span> <span class="n">leftmost</span> <span class="o">-</span> <span class="n">pos</span><span class="p">;</span> <span class="c1">// 向右走的距离
</span> <span class="k">if</span> <span class="p">(</span><span class="n">disleft</span> <span class="o"><</span> <span class="n">disright</span> <span class="o">||</span> <span class="p">(</span><span class="n">disleft</span> <span class="o">==</span> <span class="n">disright</span> <span class="o">&&</span> <span class="n">direction</span> <span class="o">==</span> <span class="n">RIGHT_TO_LEFT</span><span class="p">))</span>
<span class="p">{</span>
<span class="c1">// 注意如果蛋糕就在当前位置就不需要更新方向,下同
</span> <span class="k">if</span> <span class="p">(</span><span class="n">disleft</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="n">direction</span> <span class="o">=</span> <span class="n">RIGHT_TO_LEFT</span><span class="p">;</span>
<span class="n">remove</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">rightmost</span><span class="p">);</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">disleft</span><span class="p">;</span>
<span class="n">pos</span> <span class="o">=</span> <span class="n">rightmost</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">disright</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="n">direction</span> <span class="o">=</span> <span class="n">LEFT_TO_RIGHT</span><span class="p">;</span>
<span class="n">remove</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">leftmost</span><span class="p">);</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">disright</span><span class="p">;</span>
<span class="n">pos</span> <span class="o">=</span> <span class="n">leftmost</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case %d: "</span><span class="p">,</span> <span class="n">tcase</span><span class="p">);</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>1009 Saving Princess claire_</strong>
<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4308">HDU4308</a>
把所有的P看成一个点(这里设为0),然后Dijkstra求最短路即可。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">5010</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXM</span> <span class="o">=</span> <span class="mi">500010</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">INF</span> <span class="o">=</span> <span class="mh">0x7f7f7f7f</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">map</span><span class="p">[</span><span class="n">MAXN</span><span class="p">][</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">head</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">edgecount</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">r</span><span class="p">,</span> <span class="n">c</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">edge</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">u</span><span class="p">,</span> <span class="n">v</span><span class="p">,</span> <span class="n">w</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">next</span><span class="p">;</span>
<span class="p">}</span><span class="n">e</span><span class="p">[</span><span class="n">MAXM</span><span class="p">];</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="nf">getpos</span><span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="p">,</span> <span class="kt">int</span> <span class="n">j</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'P'</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">return</span> <span class="n">i</span> <span class="o">*</span> <span class="n">c</span> <span class="o">+</span> <span class="n">j</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// 添加一条从u到v的边
</span><span class="kt">void</span> <span class="nf">addedge</span><span class="p">(</span><span class="kt">int</span> <span class="n">u</span><span class="p">,</span> <span class="kt">int</span> <span class="n">v</span><span class="p">,</span> <span class="kt">int</span> <span class="n">w</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">e</span><span class="p">[</span><span class="n">edgecount</span><span class="p">].</span><span class="n">u</span> <span class="o">=</span> <span class="n">u</span><span class="p">;</span>
<span class="n">e</span><span class="p">[</span><span class="n">edgecount</span><span class="p">].</span><span class="n">v</span> <span class="o">=</span> <span class="n">v</span><span class="p">;</span>
<span class="n">e</span><span class="p">[</span><span class="n">edgecount</span><span class="p">].</span><span class="n">w</span> <span class="o">=</span> <span class="n">w</span><span class="p">;</span>
<span class="n">e</span><span class="p">[</span><span class="n">edgecount</span><span class="p">].</span><span class="n">next</span> <span class="o">=</span> <span class="n">head</span><span class="p">[</span><span class="n">u</span><span class="p">];</span>
<span class="n">head</span><span class="p">[</span><span class="n">u</span><span class="p">]</span> <span class="o">=</span> <span class="n">edgecount</span><span class="p">;</span>
<span class="o">++</span><span class="n">edgecount</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">cost</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">dist</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">bool</span> <span class="n">used</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">maxn</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">cin</span> <span class="o">>></span> <span class="n">r</span> <span class="o">>></span> <span class="n">c</span> <span class="o">>></span> <span class="n">cost</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">getchar</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">r</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">gets</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">edgecount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">head</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">head</span><span class="p">));</span>
<span class="n">maxn</span> <span class="o">=</span> <span class="n">r</span> <span class="o">*</span> <span class="n">c</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">r</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="n">c</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'#'</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">w</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'*'</span><span class="p">)</span> <span class="n">w</span> <span class="o">=</span> <span class="n">cost</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">w</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'Y'</span><span class="p">)</span> <span class="n">start</span> <span class="o">=</span> <span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">);</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'C'</span><span class="p">)</span> <span class="n">end</span> <span class="o">=</span> <span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">></span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">!=</span> <span class="sc">'#'</span><span class="p">)</span> <span class="n">addedge</span><span class="p">(</span><span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">j</span><span class="p">),</span> <span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">),</span> <span class="n">w</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span> <span class="o">></span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="sc">'#'</span><span class="p">)</span> <span class="n">addedge</span><span class="p">(</span><span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">),</span> <span class="n">w</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span> <span class="o"><</span> <span class="n">r</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">!=</span> <span class="sc">'#'</span><span class="p">)</span> <span class="n">addedge</span><span class="p">(</span><span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">j</span><span class="p">),</span> <span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">),</span> <span class="n">w</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span> <span class="o"><</span> <span class="n">c</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="sc">'#'</span><span class="p">)</span> <span class="n">addedge</span><span class="p">(</span><span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">),</span> <span class="n">getpos</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">),</span> <span class="n">w</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dist</span><span class="p">,</span> <span class="mi">127</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dist</span><span class="p">));</span>
<span class="n">dist</span><span class="p">[</span><span class="n">start</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">nodenow</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mindis</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">used</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">used</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">maxn</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">mindis</span> <span class="o">=</span> <span class="n">INF</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">maxn</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">used</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o">&&</span> <span class="n">dist</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="o"><</span> <span class="n">mindis</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">mindis</span> <span class="o">=</span> <span class="n">dist</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">nodenow</span> <span class="o">=</span> <span class="n">j</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">mindis</span> <span class="o">==</span> <span class="n">INF</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">+=</span> <span class="n">mindis</span><span class="p">;</span>
<span class="n">used</span><span class="p">[</span><span class="n">nodenow</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">nodenow</span> <span class="o">==</span> <span class="n">end</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">edgenumber</span> <span class="o">=</span> <span class="n">head</span><span class="p">[</span><span class="n">nodenow</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">edgenumber</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">newdis</span> <span class="o">=</span> <span class="n">mindis</span> <span class="o">+</span> <span class="n">e</span><span class="p">[</span><span class="n">edgenumber</span><span class="p">].</span><span class="n">w</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">newnode</span> <span class="o">=</span> <span class="n">e</span><span class="p">[</span><span class="n">edgenumber</span><span class="p">].</span><span class="n">v</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">used</span><span class="p">[</span><span class="n">newnode</span><span class="p">]</span> <span class="o">&&</span> <span class="n">newdis</span> <span class="o"><</span> <span class="n">dist</span><span class="p">[</span><span class="n">newnode</span><span class="p">])</span> <span class="n">dist</span><span class="p">[</span><span class="n">newnode</span><span class="p">]</span> <span class="o">=</span> <span class="n">newdis</span><span class="p">;</span>
<span class="n">edgenumber</span> <span class="o">=</span> <span class="n">e</span><span class="p">[</span><span class="n">edgenumber</span><span class="p">].</span><span class="n">next</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="n">end</span><span class="p">])</span> <span class="n">cout</span> <span class="o"><<</span> <span class="n">dist</span><span class="p">[</span><span class="n">end</span><span class="p">]</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">else</span> <span class="n">puts</span><span class="p">(</span><span class="s">"Damn teoy!"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>比赛的时候只做了1001,然后就没什么想法了。。那时候刚过一小时左右。然后去洗澡,还有点感冒了。当天早上还断网了,刚好用完一年的网费。1003想到是线段树不过不会写。</p>
2011-2012学年第2学期总结
2012-07-04T03:58:37+00:00
http://greenmooon55.com/2011-2012%e5%ad%a6%e5%b9%b4%e7%ac%ac2%e5%ad%a6%e6%9c%9f%e6%80%bb%e7%bb%93
<p>成绩终于都出完了,大一那时候总是想着能不能到3.5…总把成绩往差了想,每出一门成绩都觉得挺开心的,现在总想着成绩最好是多少,于是出了好成绩没感觉,比自己想像得差就觉得很不爽。。先总结一下这学期。</p>
<p>真是比较苦逼的一学期,整个一寒假过得很不爽,Win程和操作系统课程设计都不会做也不想做。开学那几天只好疯狂做了。。最后Win程我做得比较简单,<a href="http://albusshin.com/">AlbusShin</a>做得比较多,上了这门课,感觉<a href="http://gcers.org/wiki/Windows_%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/">什么都没学到</a>= =操作系统课程设计不太会。。几乎全部都是 <a href="http://www.euyuil.com/">Euyuil</a> 做的,他肯定很后悔跟我一组。。</p>
<p>然后就是正常的生活了。这学期花了一些时间在JavaEE上,pjx组长很认真,最开始总是给我们留作业,还叫我们学各种框架。我学了一点点CSS,好吧几乎相当于没学。。太佩服这种为了追求完美花了那么多时间写的人了。最后弄个Ubuntu VPS,配置挺方便的。还是挺讨厌Java的,最主要的原因是太慢了。。。打开Netbeans——上会人人微博等它出现——咦?怎么还没打开,我是不是忘了点它?——哦,还在载入中。。看来该换电脑了。后面刘岩讲的JSF什么的就没怎么听,没兴趣。。</p>
<p>图形学,最开始是想模仿<a href="http://greenmoon55.com/waiting-for-kart-online/">卡通赛车</a>,想“尽早做完”,想得挺好,最后根本没时间做,答辩前一晚我们还在导入模型,这个项目我花的时间不多,最后这个成绩虽然比较意外,也可以接受。。dl花了很多时间做模型,组长做了地形和联机,我觉得这成绩太对不起他们了。这门课没学到什么,老师讲得有点水,上课我也没怎么听。。唉。挺后悔选了图形学。</p>
<p>Linux程序设计,lyg的英语真让人受不了。本来我是想通过这门课比较熟练的使用vim的。。结果也没怎么用,也就会个方向键。这是第一次当组长做期末项目,我们选的是下载器,最初的想法是通过这个学会socket programming,问了lyg,lyg说一定要做界面,感觉他挺重视界面的,感觉时间来不及,就放弃了。后来我们还考虑过<a href="http://curl.haxx.se/libcurl/">libcurl</a>,最后发现Qt自带网络的库,就直接用Qt来做了。前期我写得比较多,后面<a href="http://albusshin.com/">AlbusShin</a>写了分块下载,最后其实dzy一行都没写,经讨论还是给了他20%的比例,然后他请我们吃顿饭,刚开始觉得不太好,后来想想自己也在这么多项目里打过酱油,得有多少人恨我。。当组长的感觉没什么特别的,当时win程答辩那天中午,由于头文件的原因编译不过,我就想着<a href="http://albusshin.com/">AlbusShin</a>肯定能弄好的,这次Linux下午发现重大bug,我也觉得他能弄好。。在430从一点多呆到五点多才答辩完。当时我还没有看yls写的文档,于是助教直接把服务器地址给我们,说我们可以第二天把文档传上去。服务器没密码啊,我可以看到别人的源代码啊,28号答辩的组就能看到25号答辩完的代码了啊。。不知道是不是助教只把地址告诉我了,反正我是没告诉dl。。</p>
<p>数据库课程设计,挺无聊的一门课,一学分的课花了大家很多时间。不过大家github上一起写挺好玩的,答辩之前还发现了我的bug。。。于是先想好怎么演示在上去讲,写的时候怎么那么脑残。</p>
<p>数据库,考试前一天,上午把论文写完,虽然内容不深,还是注意了一下排版和语言。为啥一定要写Oracle和Sybase呢,写MySQL不好吗。。下午去图书馆从零开始复习,不明白那时候为什么不紧张。。还好最后考试题不太难,结果挺不错。</p>
<p>编译原理,wym上课总接电话挺烦人,讲得还不错。课程中间那段没怎么听。最后考试LR(0)忘了写S’,书上那个例子貌似是给出来了。。考试的时候忘了,我是知道的。。最后一题第二个问优化什么的以为不会考就没看,感觉其他不能有问题啊,结果成绩出来是这样。。一直在看Coursera上的编译原理,做Problem Set什么的,到考试周实在坚持不下去了。Coursera上和wym讲得差不多,差别主要是网上这个讲了SLR(1),呃。。现在基本全忘了,中间代码生成那块没怎么讲,主要讲了wym没讲的 Type Checking…从这里开始就听不懂了。。感觉 Coursera 上难度差异比较大。。可能是因为我没做Programming Assignments,对课程中用到的COOL语言不太熟悉,也可能是语言原因或者是不习惯形式化证明。Coursera每周的习题还是要花很多时间做的,感觉看这种公开课还是没有看书效率高,不过可以做题,这倒挺好的。期中考还不错呢,拿到8.x/9呢。</p>
<p>其他就不想说什么了,毛邓三拿良挺不错了,论文写得挺认真的呢。软件架构开始讲得很简单,中间正好,最后比较难,因为接近考试没怎么听。</p>
<p>这学期终于又想出去玩,和xltom去了一次上海海洋大学、上海海事大学,还和一些同学去了奉贤看油菜花,这个。。我不该去的,人家wyr和sbh在一起我去干什么。。五一想去苏州的,因为数学建模没去成,我这种数学这么烂的人还是别搞这个了,不好玩。</p>
<p>算法方面,这学期做了CodeJam和百度之星第一轮,CodeJam三次机会都没进。。差一点。。明年努力吧。好想还做过Codeforces。这学期在这方面花的时间太少了,不过觉得做这些比赛很好玩。下学期多花时间吧。</p>
<p>这学期的收获不少,也有很多遗憾,下半年加油吧。瞬间觉得时间好少啊,十号左右还准备去长白山呢,这回来不就只剩一周了吗,能做完吗。。暑假事情也不少,首先是算法方面多做题,然后“<a href="http://www.wotongji.com">我同济</a>”还想继续做,答应别人的Html5游戏也得做,然后还报了8月的托福。。</p>
<p>2012.06.02。希望以后还有机会。</p>
2012暑假回家记
2012-07-03T16:46:57+00:00
http://greenmooon55.com/2012%e6%9a%91%e5%81%87%e5%9b%9e%e5%ae%b6%e8%ae%b0
<p>上次回家是和xltom以及dtr,这次是7月1日K516次,与zxy和lyq一起回吉林。某天晚上十一点前买到的下铺。</p>
<p>6月30号回本部一中聚会,晚上北安跨回来,九点二十多到嘉定,回到宿舍感觉好累,没怎么收拾东西。夜里还停电了。。过了12点还断网了,只好充点钱继续用。。想过通宵的,只是太累了,定个闹钟,七点钟起来,八点半出发。其实没拿什么东西回来。。一些书和衣服、还有点吃的。</p>
<p>走到马桶楼那里,保安还问我为什么不坐短驳车。。八点的车太早,十点的太晚,而且我还没收拾完东西。。进地铁站前刚好走了一班江苏路方向的车。。等车的时候遇到去浦东机场的包子剑客,十点多一点进站,这次上海站北广场还是没多少人,进站前也不查身份证了。</p>
<p>上海站居然有回味,要是早上没在食堂吃饭就该去吃一顿的,买了一份报纸,车上发现报纸没什么意思。。过一会他们两个就来了,再过一会就检票了,K516貌似还是二站台,旁边就是封浜小客车啊,还没等我拍照它就开了。。大约在十点四十几分。上车之后发现一站台还是沪港Q99,水牌也是纸的了。</p>
<p>考完试之后也没调整好,这次比较能睡,上车迷迷糊糊睡到南京,中间不少人买上海的票上来,泡的面被打翻了。。于是得到一个咸鸭蛋,好久没吃了。中铺居然是到天津。。买到塘沽的票,貌似是为了和她妈妈一起走。。过长江的时候又是朝东看,雾好大,真的像海一样。和上次一样,早点到徐州,停半小时,出去感受一下,比上海凉快多了。</p>
<p>车上好多大学生,东华、上海电力等等等等,还有很多小孩子,都是上海的幼儿园放假了,<strong>在上海照顾孩子的爷爷奶奶或姥姥姥爷带孩子回东北</strong>,以前还以为都是带着小孩出去玩呢。还有为了考职称作弊的高中老师。。还有人聊哈尔滨、长春的人好打扮,买很贵的衣服,南方人都攒钱买房子等等。。</p>
<p>熄灯前居然来卖苞米~很馋,犹豫了一下没有买,于是第二天真的不卖了。。上次是第二天卖的,xltom想等会再买,结果就没有了。。516真是个好车啊,装饰比上次还好,还配备了洗手液,据说沈哈两局的车都很干净。这次有点不理解的是没登记身份证,倒是登记谁带了八宝粥或者玻璃瓶,说是怕旅客扔出去,不过这新空25G到哪往外扔啊。。</p>
<p>半夜他们貌似还看了欧洲杯文字直播,我睡得很踏实,或许是因为在下铺,上次在天津站是清醒的,是睡到北戴河、山海关左右才起。这次睡到塘沽左右就行了,五点多起来喝八宝粥,再躺一会,还是在秦皇岛左右起来洗漱,不知道哪里晚了二十多分钟,于是提前在台安待避三个D,过了辽中就基本正点了,早点一点点到沈阳北。</p>
<p>在秦沈上和旁边的人聊天,说他女婿是FDU的硕士,学的是数学,当时就在搞计算机。。毕业之后去盛大干了两年,然后现在自己干了。。每天晚上十点回家。还要跟我聊盛大和网易的纳斯达克股价。。我怎么知道。。车上不少人都是到沈阳,看来是K188太慢了= =有人聊天说吉林比长春好、吉林环境好,看来这是很多人的共识嘛。</p>
<p>中午没吃上饭。。貌似盒饭只卖了一趟就卖没了,我们在玩牌。等我从2车走到14车餐车,人家说餐车也不卖东西了,连泡面都不卖了。。</p>
<p>沈阳北下车呆一会,感觉挺凉快。到公主岭有些晚点,貌似T183晚点了,最后到长春晚了5分钟进站。显然赶不上10分的动车了,K75就在旁边的站台,当时没太想坐也赶不上了。长春站东西两个地道都有人骗我们过不去,西面还有人很凶地说没票得出站买,不让我们过去上车补。。等了半天上了D5049,长吉客流太火爆了,完全没位置,站在车厢连接处。过了龙嘉一会列车长才来补票。我手上都拿着学生证和前一段车票呢,您还说机器不能补学生票,那不好意思了,我只好投诉了。</p>
<p>到了吉林,看那些等活的出租车特别不爽,走到岔路乡再打车。路过KFC,好想去吃点东西啊!这司机说,他媳妇在上海公交车上小心踩到别人,对方不依不饶的,于是停车时他就把那个人踹下去了,然后下一站他们打车跑了。。好吧或许这只是个故事。。</p>
<p>11点睡,又是一觉睡到中午12点。起来打电话投诉,我先问了一下可不可以补学生票,然后告诉她我昨天补了全票。对方记下了两段的车票编号,学生证优惠区间以及学校。下午三点多有人来核实情况,然后是长春动车段某书记了解情况并道歉,询问有什么要求,我当然说退差价就可以了,好像是九块钱吧。然后是当时的列车长来道歉,说当时忙着补票,没有解释清楚,补票机坏了,开代用票太麻烦什么的。还说直接把三个人的花销退回来,让她的同事给我钱,让我撤销投诉。后来沈阳局又来电话说列车长会作检讨,还会扣工资等等。于是晚上去车站出站口领回了102块钱。</p>
<p>我们都知道铁路基层员工不容易,要求不少、工作强度大、工资不高什么的,跑动车环境好一点,不过好像也挺累。但是我手里都拿着学生证和前一段的票啊,不是没给您看啊,再说上次坐车也是这么补的学生票,这没办法,我只好投诉了。</p>
<p>回家天天还是很困,今天写日志写到这个点。赶快去睡了。</p>
<p>对了,最后吐槽一下车上某人。还是上海某名校的呢。。口音有点怪,一点都不像长春人,重点是听她说话有点难受,怎么说呢,不要太张扬吧。行为也有点怪,在车上看一本泛黄的菜谱= =</p>
Google Code Jam 2012
2012-05-12T04:12:33+00:00
http://greenmooon55.com/google-code-jam-2012
<p><strong>Qualification Round</strong>
Problem A. Speaking in Tongues
简单的按规律替换字符串
Problem B. Dancing With the Googlers
忘记了具体内容了,反正要注意边界特殊情况。
Problem C. Recycled Numbers
比赛时想不明白 Case #4,于是没交大数据,后来看了 Contest Analysis 才知道有1212这种情况,会重复。比赛的时候移位是用字符串实现的。。后来才改过来。看了代码 Contest Analysis 的才知道不用数组记录数字是否出现的,<strong>只要移回原数就退出</strong>,即可避免循环节的问题。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">temp</span> <span class="o">=</span> <span class="n">num</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">base</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">digit</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">temp</span> <span class="o">/</span> <span class="mi">10</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">base</span> <span class="o">*=</span> <span class="mi">10</span><span class="p">;</span>
<span class="n">temp</span> <span class="o">/=</span> <span class="mi">10</span><span class="p">;</span>
<span class="o">++</span><span class="n">digit</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">move</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span>
<span class="n">temp</span> <span class="o">=</span> <span class="n">num</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">digit</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">move</span> <span class="o">=</span> <span class="n">temp</span> <span class="o">%</span> <span class="mi">10</span><span class="p">;</span>
<span class="n">temp</span> <span class="o">/=</span> <span class="mi">10</span><span class="p">;</span>
<span class="n">temp</span> <span class="o">+=</span> <span class="n">base</span> <span class="o">*</span> <span class="n">move</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span> <span class="o">></span> <span class="n">num</span> <span class="o">&&</span> <span class="n">temp</span> <span class="o"><=</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span><span class="o">++</span><span class="p">;</span>
<span class="c1">// 判断 temp 是否出现过
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="n">i</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">])</span>
<span class="p">{</span>
<span class="o">--</span><span class="n">ans</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tcase</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tcase</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tcase</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="o">&</span><span class="n">b</span><span class="p">;);</span>
<span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">b</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">work</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: "</span><span class="p">,</span> <span class="n">tcase</span><span class="p">);</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>Round 1B</strong>
Problem A. Safety in Numbers
这道题非常好玩。题意是这样的:每位选手的得分 = 评委给分 + 所有选手得到的评委给分和 * 这位选手的观众投票率(0-100%)。每个观众只能投一个选手,现在要淘汰得分最低的选手,若有多位选手得分相同,且都为最低分数,那么没人会被淘汰。求每位选手至少需要得到多少观众投票才能不被淘汰。</p>
<p>第一个想法就是先不考虑观众投票,对于当前选手A,找现在得分最低的选手B,算一下A要多少投票率才能超过剩下的票都投B的得分。这个想法是错误的。因为算完之后,其他多个选手可能比A、B得分都少,只需要让A的得分大于等于所有人都最低分数即可。</p>
<p>看看 Case #4,</p>
<blockquote>
<p>Input: 3 24 30 21
Output: 34.666667 26.666667 38.666667</p>
</blockquote>
<p>每个人的得分是相同的!这是一个巧合吗?不是的,由于评委给分已知,每个观众只能投一票,所有选手的得分总和是固定的,那么每个选手只要得到 所有选手的得分总和 / 选手个数 即可保证不被淘汰。那么,先求出平均得分,然后对每个选手解方程求投票率即可。</p>
<p>小数据里有这样一种情况。</p>
<blockquote>
<p>8 0 0 0 0 72 0 0 0</p>
</blockquote>
<p>每位选手的平均得分是(72 + 72) / 8 = 18,显然72已经远远超过18了。那么此时就不考虑72(也就是说72不需要观众投票),平均得分为(0 + 72) /7 = 10.2857143,然后投票率为 (10.2857143 - 0) / 72 = 14.2857143%。</p>
<p>这样就可以过小数据了,不过还有一个问题,如果去掉72之后,仍然有数字大于平均得分怎么办?
先从大到小排个序,然后依次考虑即可,大于平均得分就说明这位选手不需要投票,答案为 0。最后的就肯定需要投票啦,不管他的评委得分是多少,如果得到100%的观众投票就肯定不会被淘汰,如:</p>
<blockquote>
<p>2 10 0</p>
</blockquote>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">num</span><span class="p">[</span><span class="mi">250</span><span class="p">],</span><span class="n">num2</span><span class="p">[</span><span class="mi">250</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tcase</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tcase</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tcase</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">sum</span> <span class="o">+=</span> <span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">memcpy</span><span class="p">(</span><span class="n">num2</span><span class="p">,</span> <span class="n">num</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">num2</span><span class="p">));</span>
<span class="n">sort</span><span class="p">(</span><span class="n">num</span><span class="p">,</span> <span class="n">num</span><span class="o">+</span><span class="n">n</span><span class="p">,</span> <span class="n">greater</span><span class="p">());</span>
<span class="kt">double</span> <span class="n">temp</span> <span class="o">=</span> <span class="p">(</span><span class="n">sum</span> <span class="o">*</span> <span class="mi">2</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="kt">double</span><span class="p">)</span><span class="n">n</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">count</span> <span class="o">=</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">total</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span> <span class="o"><</span> <span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">total</span><span class="o">-=</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="o">--</span><span class="n">count</span><span class="p">;</span>
<span class="n">temp</span> <span class="o">=</span> <span class="p">(</span><span class="n">total</span> <span class="o">+</span> <span class="n">sum</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="kt">double</span><span class="p">)</span><span class="n">count</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: "</span><span class="p">,</span> <span class="n">tcase</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">></span> <span class="n">temp</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"0"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%lf"</span><span class="p">,</span> <span class="p">(</span><span class="n">temp</span> <span class="o">-</span> <span class="n">num2</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">/</span> <span class="n">sum</span> <span class="o">*</span> <span class="mi">100</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num2</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">></span> <span class="n">temp</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">" 0"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">" %lf"</span><span class="p">,</span> <span class="p">(</span><span class="n">temp</span> <span class="o">-</span> <span class="n">num2</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">/</span> <span class="n">sum</span> <span class="o">*</span> <span class="mi">100</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>Round 1C</strong>
Problem A. Diamond Inheritance
判断是否有这种情况发生:D类继承自B类和C类,B类继承自A类,C类也继承自A类,这就形成了一个菱形。
我用并查集做的…DFS,如果结点被访问时已经和上一个结点在同一个集合里就说明出现了这种情况。
呃,似乎用不到并查集啊,用个bool used[]标记就行了吧。。
虽然共有1000个类,但每个类最多继承自10个类。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">nodeMax</span> <span class="o">=</span> <span class="mi">1010</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">p</span><span class="p">[</span><span class="n">nodeMax</span><span class="p">];</span><span class="c1">//p:parent
</span><span class="kt">int</span> <span class="n">rank</span><span class="p">[</span><span class="n">nodeMax</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">map</span><span class="p">[</span><span class="n">nodeMax</span><span class="p">][</span><span class="n">nodeMax</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">make_set</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="c1">//pay attention!
</span> <span class="p">{</span>
<span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="n">rank</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">find_set</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span><span class="o">!=</span><span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">])</span> <span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">=</span><span class="n">find_set</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">]);</span>
<span class="k">return</span> <span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span><span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">temp</span> <span class="o">=</span> <span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="n">i</span><span class="p">];</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">find_set</span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">find_set</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="n">i</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">!=</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rank</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">></span><span class="n">rank</span><span class="p">[</span><span class="n">y</span><span class="p">])</span> <span class="n">p</span><span class="p">[</span><span class="n">y</span><span class="p">]</span><span class="o">=</span><span class="n">x</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">p</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">=</span><span class="n">y</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rank</span><span class="p">[</span><span class="n">x</span><span class="p">]</span><span class="o">==</span><span class="n">rank</span><span class="p">[</span><span class="n">y</span><span class="p">])</span> <span class="n">rank</span><span class="p">[</span><span class="n">y</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">work</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="n">i</span><span class="p">]))</span> <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tcase</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tcase</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">tcase</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">yes</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">make_set</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="n">work</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
<span class="p">{</span>
<span class="n">yes</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: "</span><span class="p">,</span> <span class="n">tcase</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">yes</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"Yes</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">"No</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>Problem B. Out of Gas
这完全是个物理题,读题很费时间。
你开一辆车,给定最大加速度,减速的加速度随意,也就是说可以瞬间停车。前面有一辆车一直匀速运动,不过它的速度在特定的点可以突然改变。求从起始点到指定位置的最短时间。
Small Input 最多只有两个点,比一下前面的车还是自己的车一直加速先到指定位置即可。刚花了一晚上写大数据,越写越烦,一看才73人A了这个。。还是算了吧。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">point</span>
<span class="p">{</span>
<span class="kt">double</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">x</span><span class="p">;</span>
<span class="p">}</span><span class="n">p</span><span class="p">[</span><span class="mi">5</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">acc</span><span class="p">[</span><span class="mi">15</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">d</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">a</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tcase</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tcase</span> <span class="o"><=</span><span class="n">t</span><span class="p">;</span> <span class="n">tcase</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d:</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">tcase</span><span class="p">);</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">d</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">a</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%lf%lf"</span><span class="p">,</span> <span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">t</span><span class="p">,</span> <span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%lf"</span><span class="p">,</span> <span class="o">&</span><span class="n">acc</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="kt">double</span> <span class="n">t1</span><span class="p">,</span> <span class="n">t2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">t2</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">t</span> <span class="o">+</span> <span class="p">(</span><span class="n">d</span> <span class="o">-</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">t</span> <span class="o">-</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">t</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">x</span> <span class="o">-</span> <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">x</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">t1</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">d</span><span class="o">/</span><span class="n">acc</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">t1</span> <span class="o">></span> <span class="n">t2</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%.7lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">t1</span><span class="p">);</span>
<span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%.7lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">t2</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">t1</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">d</span><span class="o">/</span><span class="n">acc</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%.7lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">t1</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>Code Jam 还是挺好玩的,而且比赛结束之后马上出排名。最后1015没进,明年再来吧。
还想看看 Round 1C 的 Problem C. Box Factory 和 Round 1B 的 Problem C. Equal Sums。</p>
练习曲 (2006)
2012-05-08T08:04:47+00:00
http://greenmooon55.com/lianxiqu-2006
<p><a href="http://greenmoon55.com/wp-content/uploads/2012/05/lianxiqu.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2012/05/lianxiqu.jpg" alt="练习曲海报" /></a>
图片来源:<a href="http://www.wretch.cc/blog/EtudeBike">http://www.wretch.cc/blog/EtudeBike</a></p>
<p>评分:4/5
很像一部纪录片,没想到骑行的主人公听力不好,说话也不清楚。环岛游倒没什么特别,肯定在路上遇到一些好心人,电影后面一小段节奏有点慢。。</p>
<p>几个印象深刻的情节:小虫爬过地图、镜头(小女孩)透过啤酒看别人、一条鱼从天而降,貌似是从海鸥嘴里掉下来的(?)、抗议女工租车,半价优惠。</p>
<p>另外感觉台湾人讲话跟以前室友的闽南话确实有点像。。</p>
<p>===
好久没看电影,好久没看<a href="http://www.daolan.net/">纪录片</a>了。
以前不知道在这里发海报算不算侵权,现在觉得应该算<a href="http://zh.wikipedia.org/wiki/%E5%90%88%E7%90%86%E4%BD%BF%E7%94%A8">合理使用</a>吧。</p>
数学建模邀请赛
2012-05-05T19:10:24+00:00
http://greenmooon55.com/mathematical-contest-in-modeling
<p>从上周六到这周六,折腾一周<a href="http://www.mcmm.fudan.edu.cn/?p=306">数学建模</a>。</p>
<p>两道题目,第一个是说水滴的高度和体积之间的关系,随着体积的增大高度先增大后减小,没注意具体什么问了什么。。
第二个什么条件都没给,直接问如何在城市布局 PM2.5 监测站。</p>
<p>完全是去打酱油,前几天每天晚上都语音好几个小时,查查论文,英文的看不懂,中文的没什么资料。大家都不怎么说话,。因为没思路。。我觉得非常非常痛苦。。后来H提出个想法,就是按风向和温度对 PM2.5 监测的影响,对上海地图拉伸两次,然后在地图里面画N个圆,要求半径相同,求出每个圆的位置,然后再把这些坐标转换到原来的上海地图上。</p>
<p>我就写了个凸包,让地图拉伸之后仍然是个凸多边形,不过由于我们没取几个点,其实肉眼看一下就行的…还写了一个显示这些点的程序,不过没用上,原来 MATLAB 直接就能弄。求圆的位置用的是 LINGO,貌似是线性规划,原来还有这种神奇的软件。。当然这些都不是我弄的。</p>
<p>最后我发的第一份pdf排版有点问题。。只好最后几分钟再发一遍。囧。。其实还有个大问题,这里就不说了= =</p>
<p>我们的假设是扩散快的地方少放监测站,因为这些地方的代表性不强。感觉怪怪的,不过细想还是有道理的。当然还要看环保局怎么想了,哪里有地方放设备,哪里空气质量比较好(貌似<a href="http://news.sina.com.cn/c/2012-02-26/025823997941.shtml">北京把一个监测站从前门挪到郊区</a>了)。</p>
<p>找资料的时候还谈到了热岛效应、盛行风向、迎风坡背风坡(为啥迎风坡降水多、背风坡降水少来着?完全忘了!!)高中学地理那段时光多好啊~高中还选了地理选修课呢。。</p>
<p>还是对数学建模不太感兴趣。。当时想着为我们那个创新项目学点MATLAB,结果现在一点都没学,我也不想学。。</p>
<p>这一周大约在这上面花了多于(1号一天+3小时/天(其余天)),而且很影响心情。。好不容易有个作业这么少的假期啊。也是因为这个间接导致图形学作业没按时交。。就是不想做了。。晚了两天交,而且只写了旋转。当然很感谢两位队友~程序和论文基本都是他们写的。</p>
<p>以后还要不要参加数学建模呢…看到一个例子是根据客流量安排公交班次,那个倒是很好玩的。不过其他的都不好玩。</p>
<p>话说本来准备这周六从安亭北去苏州运转呢,结果没起来,还好没起来,否则被问到就尴尬了= =</p>
<p>====================
今天 codejam 太悲剧了。。纠结了半天到底睡不睡觉,在床上躺着玩手机没睡着,于是就起来喝杯咖啡写比赛。(第一次喝这种,雀巢醇品五毛钱一袋冲出来的味道和麦当劳的一样哦!)
A题想了半天才明白,大数据居然还挂了,不知道存在哪里。(输出里居然有-0.000333,难道是精度问题)
B不想看
C写了一半不想写了,于是过来写blog…</p>
<p>于是晚上再来一次吧~重在参与。。</p>
<p>====================
晚上搞完数学建模玩了会 openBVE,没想到这么小!听说很多年了,第一次玩。画面效果不错,就是。。AI不会动,而且限速提示、停站提示不清楚。玩到九点有点头晕就算了。</p>
<p>====================
呃。。最近在看Coursera上的编译原理。。视频大约两个多小时,作业还要花一两个小时啊,有的题目有点难/tricky,有论坛,不知道以后能不能坚持下去。</p>
USTC1305 Maximum income
2012-04-19T16:20:22+00:00
http://greenmooon55.com/ustc1305-maximum-income
<p>来自 xw 和 wh:
维护一个递减的单调队列,因为后入队的数只有比前面所有的数小才有可能成为符合条件区间的起点,若不满足这个条件,就二分找当前最大区间。复杂度 nlogn。</p>
<p>===
最近好忙= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">100010</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">queue</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">day</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">c</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">p</span><span class="p">,</span> <span class="n">ans</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">c</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">a</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">queue</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="n">day</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">p</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o"><</span> <span class="n">queue</span><span class="p">[</span><span class="n">p</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">queue</span><span class="p">[</span><span class="o">++</span><span class="n">p</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">day</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">r</span> <span class="o">=</span> <span class="n">p</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mid</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">l</span> <span class="o"><</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">l</span> <span class="o">+</span> <span class="n">r</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">queue</span><span class="p">[</span><span class="n">mid</span><span class="p">]</span> <span class="o"><=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">mid</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="n">l</span> <span class="o">=</span> <span class="n">mid</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">-</span> <span class="n">day</span><span class="p">[</span><span class="n">l</span><span class="p">]</span> <span class="o">></span> <span class="n">ans</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="n">day</span><span class="p">[</span><span class="n">l</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ans</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="o">++</span><span class="n">ans</span><span class="p">)</span><span class="o">*</span><span class="n">c</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">ans</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
USTC1300 Big grid
2012-04-19T16:10:30+00:00
http://greenmooon55.com/ustc1300-big-grid
<p><a href="http://acm.ustc.edu.cn/ustcoj/problem.php?id=1300">USTC1300</a></p>
<p>DP,dp[i][SAME 或 DIFF] 表示格子[0][i]和[1][i-1]相同颜色或不同颜色有多少种情况。然后就很好写了。</p>
<p>数学解法不会= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">SAME</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">DIFF</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">dp</span><span class="p">[</span><span class="mi">10010</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">k</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">ans</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">dp</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">dp</span><span class="p">));</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;,</span> <span class="o">&</span><span class="n">m</span><span class="p">;,</span> <span class="o">&</span><span class="n">k</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">k</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">*=</span> <span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">ans</span> <span class="o">%=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">m</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span> <span class="o">=</span> <span class="n">k</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">ans</span> <span class="o">%=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">SAME</span><span class="p">]</span> <span class="o">=</span> <span class="n">k</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">SAME</span><span class="p">]</span> <span class="o">%=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">DIFF</span><span class="p">]</span> <span class="o">=</span> <span class="n">k</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">2</span><span class="p">);</span>
<span class="n">dp</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">DIFF</span><span class="p">]</span> <span class="o">%=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">m</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">SAME</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">DIFF</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">SAME</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">);</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">SAME</span><span class="p">]</span> <span class="o">%=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">DIFF</span><span class="p">]</span> <span class="o">=</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">SAME</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">DIFF</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">2</span><span class="p">);</span>
<span class="n">dp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">DIFF</span><span class="p">]</span> <span class="o">%=</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">ans</span> <span class="o">=</span> <span class="p">(</span><span class="n">dp</span><span class="p">[</span><span class="n">m</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">SAME</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="n">dp</span><span class="p">[</span><span class="n">m</span> <span class="o">-</span> <span class="mi">1</span><span class="p">][</span><span class="n">DIFF</span><span class="p">]</span><span class="o">*</span><span class="p">(</span><span class="n">k</span> <span class="o">-</span> <span class="mi">2</span><span class="p">))</span> <span class="o">%</span> <span class="mi">1000000007</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
HDU4193 Non-negative Partial Sums
2012-04-14T15:39:19+00:00
http://greenmooon55.com/hdu4193-non-negative-partial-sums
<p><a href="http://acm.hdu.edu.cn/showproblem.php?pid=4193">HDU4193</a>
终于知道单调队列了!其实挺简单的。搜到了这个:<a href="http://www.felix021.com/blog/read.php?1965">补缺补漏:单调队列- Blog of Felix021 - TechOnly</a></p>
<p>因为每个元素最多入队出队一次,所以复杂度是O(n)的。</p>
<p>这道题怎么做呢?开一个 2n 的数组,sum[i] 记录 a[1] 到 a[i] 的和。若在某个长度为 n 的区间里的最小 sum 大于等于区间左侧的 sum,也就是说区间里没有负数,答案计数加一。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="c1">// cin 会超时,不用 deque 会快一点
</span><span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAXN</span> <span class="o">=</span> <span class="mi">2000010</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="n">MAXN</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">n</span><span class="p">;))</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">a</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="n">n</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">deque</span> <span class="n">q</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">ans</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="o">!</span><span class="n">q</span><span class="p">.</span><span class="n">empty</span><span class="p">()</span> <span class="o">&&</span> <span class="n">a</span><span class="p">[</span><span class="n">q</span><span class="p">.</span><span class="n">back</span><span class="p">()]</span><span class="o">>=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="n">q</span><span class="p">.</span><span class="n">pop_back</span><span class="p">();</span>
<span class="n">q</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">></span> <span class="n">n</span> <span class="o">&&</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="n">n</span><span class="p">]</span> <span class="o"><=</span> <span class="n">a</span><span class="p">[</span><span class="n">q</span><span class="p">.</span><span class="n">front</span><span class="p">()])</span> <span class="o">++</span><span class="n">ans</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">q</span><span class="p">.</span><span class="n">empty</span><span class="p">()</span> <span class="o">&&</span> <span class="n">i</span> <span class="o">-</span> <span class="n">q</span><span class="p">.</span><span class="n">front</span><span class="p">()</span> <span class="o">>=</span> <span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="n">q</span><span class="p">.</span><span class="n">pop_front</span><span class="p">();</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">ans</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>===
还有一些问题</p>
<ol>
<li>
<p>单调队列的英文是什么</p>
</li>
<li>
<p>队尾去掉元素的时候等号可以不考虑吧,貌似那个文章有很多问题…</p>
</li>
<li>
<p>好像还有什么,突然忘了…</p>
</li>
</ol>
HDU4190 Distributing Ballot Boxes
2012-04-14T14:47:11+00:00
http://greenmooon55.com/hdu4190-distributing-ballot-boxes
<p><a href="http://acm.hdu.edu.cn/showproblem.php?pid=4190">HDU 4190</a>
举行大选,N (1<=N<=500,000) 个城市,一共 B(N<=B<=2,000,000) 个投票箱,每个城市人口为 ai(1<=ai<=5,000,000),求怎么分配投票箱,使放选票最多的那个投票箱里的选票最少。</p>
<p>怎么办呢?xw想到的,二分答案就行…然后算投票箱个数。</p>
120405
2012-04-05T14:33:05+00:00
http://greenmooon55.com/120405
<p>这么快一天就过去了,今天大部分时间都在看Struts、Spring、Hibernate框架,结果还没弄好最简单的login…</p>
<p>原计划第七节上课之前看完,然后想晚饭之前看完,结果最后也没弄好…</p>
<p>我没搜到特别靠谱的教程,英文的搜到了一个,还是印度的网站,中午去图书馆借了本书,太厚完全没用。看了以前借的比较薄的书。感觉今天还是太着急了,虽然不是老师留的作业,我心里还是当成有个deadline那样写的,想着早点写完早点结束。欲速则不达= =</p>
<p>我对Java、JavaEE不是很感兴趣,以前觉得最有可能退掉这门课,老师的英语不错,很幸运进了非常靠谱的组,希望能在这学期多学点html, css, js等等等。。以前连css和html有什么关系都不知道,高中的时候觉得ul、li特别神秘…当时我怎么就不知道去搜搜呢…</p>
Codeforces Round #104 (Div. 2)
2012-03-16T12:54:02+00:00
http://greenmooon55.com/codeforces-round-104-div-2
<p><a href="http://codeforces.com/contest/146">Codeforces Round #104 (Div. 2) </a>
<a href="http://codeforces.com/blog/entry/3746">Editorial</a></p>
<p>比赛时做出三题</p>
<p>A略 B忘了题意,也略吧…</p>
<p><strong>C Lucky Conversion</strong>
只需记录两字符串相应位置分别出现47和74的次数,输出这两个数的最大值</p>
<p><strong>D Lucky Number 2</strong>
这个看了题解
想象删除所有相邻重复数字,可以得到形如47474747474747的串,所以 a3 与 a4 的差的绝对值一定小于等于1。然后分三种情况讨论:</p>
<ol>
<li>
<p>a3 = a4,若 a1 = a3,则说明4不够多,生成的串以7开头,如74747,多余的7插入到最右面,多余的4放在最左边的4。。否则形如47474,多余的7插入到最右面的7,多余的4放在最左边。</p>
</li>
<li>
<p>a3 > a4,形如47474747,多余的4放在最前面,7放在最后面</p>
</li>
<li>
<p>a3 < a4,形如74747474,多余的4插入到1位置,7插入到最后面的7</p>
</li>
</ol>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">a3</span><span class="p">,</span> <span class="n">a4</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">a1</span> <span class="o">>></span> <span class="n">a2</span> <span class="o">>></span> <span class="n">a3</span> <span class="o">>></span> <span class="n">a4</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">abs</span><span class="p">(</span><span class="n">a3</span> <span class="o">-</span> <span class="n">a4</span><span class="p">)</span> <span class="o">></span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">puts</span><span class="p">(</span><span class="s">"-1"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">string</span> <span class="n">str</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a3</span> <span class="o">==</span> <span class="n">a4</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">((</span><span class="n">a1</span> <span class="o">==</span> <span class="n">a3</span> <span class="o">&&</span> <span class="n">a2</span> <span class="o">==</span> <span class="n">a3</span><span class="p">)</span> <span class="o">||</span>
<span class="n">a1</span> <span class="o"><</span> <span class="n">a3</span> <span class="o">||</span> <span class="n">a2</span> <span class="o"><</span> <span class="n">a3</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">puts</span><span class="p">(</span><span class="s">"-1"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// '4' is not enough
</span> <span class="k">if</span> <span class="p">(</span><span class="n">a1</span> <span class="o">==</span> <span class="n">a3</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a3</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">str</span> <span class="o">+=</span> <span class="s">"74"</span><span class="p">;</span>
<span class="n">str</span> <span class="o">+=</span> <span class="s">"7"</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a2</span> <span class="o">></span> <span class="n">a3</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">string</span> <span class="n">temp</span><span class="p">(</span><span class="n">a2</span> <span class="o">-</span> <span class="n">a3</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="sc">'7'</span><span class="p">);</span>
<span class="n">str</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="c1">// '4' is enough
</span> <span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a3</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">str</span> <span class="o">+=</span> <span class="s">"47"</span><span class="p">;</span>
<span class="n">str</span> <span class="o">+=</span> <span class="s">"4"</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a1</span> <span class="o">></span> <span class="n">a3</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="cm">/*
string ( size_t n, char c );
Content is initialized as a string formed
by a repetition of character c, n times.
*/</span>
<span class="n">string</span> <span class="n">temp</span><span class="p">(</span><span class="n">a1</span> <span class="o">-</span> <span class="n">a3</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="sc">'4'</span><span class="p">);</span>
<span class="n">str</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a2</span> <span class="o">></span> <span class="n">a3</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">string</span> <span class="n">temp</span><span class="p">(</span><span class="n">a2</span> <span class="o">-</span> <span class="n">a3</span><span class="p">,</span> <span class="sc">'7'</span><span class="p">);</span>
<span class="n">str</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">str</span><span class="p">.</span><span class="n">find_last_of</span><span class="p">(</span><span class="sc">'7'</span><span class="p">),</span> <span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">a3</span> <span class="o"><</span> <span class="n">a4</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a4</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">str</span> <span class="o">+=</span> <span class="s">"74"</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a1</span> <span class="o"><</span> <span class="n">a4</span> <span class="o">||</span> <span class="n">a2</span> <span class="o"><</span> <span class="n">a4</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">puts</span><span class="p">(</span><span class="s">"-1"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a1</span> <span class="o">></span> <span class="n">a4</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">string</span> <span class="n">temp</span><span class="p">(</span><span class="n">a1</span> <span class="o">-</span> <span class="n">a4</span><span class="p">,</span> <span class="sc">'4'</span><span class="p">);</span>
<span class="n">str</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a2</span> <span class="o">></span> <span class="n">a4</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">string</span> <span class="n">temp</span><span class="p">(</span><span class="n">a2</span> <span class="o">-</span> <span class="n">a4</span><span class="p">,</span> <span class="sc">'7'</span><span class="p">);</span>
<span class="n">str</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">str</span><span class="p">.</span><span class="n">find_last_of</span><span class="p">(</span><span class="sc">'7'</span><span class="p">),</span> <span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="c1">// a3 > a4
</span> <span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a3</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">str</span> <span class="o">+=</span> <span class="s">"47"</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a1</span> <span class="o"><</span> <span class="n">a3</span> <span class="o">||</span> <span class="n">a2</span> <span class="o"><</span> <span class="n">a3</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">puts</span><span class="p">(</span><span class="s">"-1"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a1</span> <span class="o">></span> <span class="n">a3</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">string</span> <span class="n">temp</span><span class="p">(</span><span class="n">a1</span> <span class="o">-</span> <span class="n">a3</span><span class="p">,</span> <span class="sc">'4'</span><span class="p">);</span>
<span class="n">str</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a2</span> <span class="o">></span> <span class="n">a3</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">string</span> <span class="n">temp</span><span class="p">(</span><span class="n">a2</span> <span class="o">-</span> <span class="n">a3</span><span class="p">,</span> <span class="sc">'7'</span><span class="p">);</span>
<span class="n">str</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">str</span><span class="p">.</span><span class="n">find_last_of</span><span class="p">(</span><span class="sc">'7'</span><span class="p">),</span> <span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">str</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
HDU4096 Universal Question Answering System
2012-03-11T06:27:07+00:00
http://greenmooon55.com/hdu4096-universal-question-answering-system
<p>其实是2010年<a href="http://acm.hdu.edu.cn/showproblem.php?pid=4096">上海赛区F题</a>,现场读入数据就写了很久…交上去之后是个诡异的错误,现在忘了是啥错误了…</p>
<p>连边判断连通性即可。这个题比较坑人…输入数据就比较恶心,当时还不会sscanf。名词和动词可能一样,所以需要两个map来存,还可能直接问are cat cat?要输出Y…</p>
<p>BFS和DFS时间差不多…
<a href="http://acm.fudan.edu.cn">http://acm.fudan.edu.cn</a> 还有数据呢。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
#include
</span><span class="c1">//#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">N</span> <span class="o">=</span> <span class="mi">205</span><span class="p">;</span>
<span class="n">map</span><span class="o"><</span><span class="n">string</span><span class="p">,</span> <span class="kt">int</span><span class="o">></span> <span class="n">nmap</span><span class="p">,</span> <span class="n">vmap</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">mapcount</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">getn</span><span class="p">(</span><span class="kt">char</span><span class="o">*</span> <span class="n">ch</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">nmap</span><span class="p">.</span><span class="n">count</span><span class="p">(</span><span class="n">ch</span><span class="p">))</span> <span class="n">nmap</span><span class="p">[</span><span class="n">ch</span><span class="p">]</span> <span class="o">=</span> <span class="n">mapcount</span><span class="o">++</span><span class="p">;</span>
<span class="k">return</span> <span class="n">nmap</span><span class="p">[</span><span class="n">ch</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">getv</span><span class="p">(</span><span class="kt">char</span><span class="o">*</span> <span class="n">ch</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">vmap</span><span class="p">.</span><span class="n">count</span><span class="p">(</span><span class="n">ch</span><span class="p">))</span> <span class="n">vmap</span><span class="p">[</span><span class="n">ch</span><span class="p">]</span> <span class="o">=</span> <span class="n">mapcount</span><span class="o">++</span><span class="p">;</span>
<span class="k">return</span> <span class="n">vmap</span><span class="p">[</span><span class="n">ch</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">struct</span> <span class="n">edge</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">v</span><span class="p">,</span> <span class="n">next</span><span class="p">;</span>
<span class="p">}</span><span class="n">e</span><span class="p">[</span><span class="n">N</span> <span class="o">*</span> <span class="n">N</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">head</span><span class="p">[</span><span class="n">N</span><span class="p">],</span> <span class="n">edgenum</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">addedge</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">e</span><span class="p">[</span><span class="n">edgenum</span><span class="p">].</span><span class="n">v</span> <span class="o">=</span> <span class="n">b</span><span class="p">;</span>
<span class="n">e</span><span class="p">[</span><span class="n">edgenum</span><span class="p">].</span><span class="n">next</span> <span class="o">=</span> <span class="n">head</span><span class="p">[</span><span class="n">a</span><span class="p">];</span>
<span class="n">head</span><span class="p">[</span><span class="n">a</span><span class="p">]</span> <span class="o">=</span> <span class="n">edgenum</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">workstatement</span><span class="p">(</span><span class="kt">char</span> <span class="o">*</span><span class="n">buf</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">char</span> <span class="n">n1</span><span class="p">[</span><span class="mi">20</span><span class="p">],</span> <span class="n">n2</span><span class="p">[</span><span class="mi">20</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"%s are %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"%s can %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"everything which can %s can %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"everything which can %s are %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">//else assert("workstatement error");
</span> <span class="n">addedge</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">vis</span><span class="p">[</span><span class="n">N</span><span class="p">];</span>
<span class="cm">/*
bool dfs(int a, int b)
{
vis[a] = true;
if (a == b) return true;
for (int i = head[a]; i != -1; i = e[i].next)
{
if (!vis[e[i].v])
{
if (dfs(e[i].v, b)) return true;
}
}
return false;
}
*/</span>
<span class="kt">bool</span> <span class="nf">bfs</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="n">b</span><span class="p">)</span> <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">q</span><span class="p">[</span><span class="n">N</span><span class="p">],</span> <span class="n">begin</span><span class="p">,</span> <span class="n">end</span><span class="p">;</span>
<span class="n">begin</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">end</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">q</span><span class="p">[</span><span class="n">end</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="n">vis</span><span class="p">[</span><span class="n">a</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">begin</span> <span class="o">!=</span> <span class="n">end</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="n">q</span><span class="p">[</span><span class="n">begin</span><span class="o">++</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">head</span><span class="p">[</span><span class="n">x</span><span class="p">];</span> <span class="n">i</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">=</span> <span class="n">e</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">next</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">vis</span><span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">vis</span><span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">e</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span> <span class="o">==</span> <span class="n">b</span><span class="p">)</span> <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="n">q</span><span class="p">[</span><span class="n">end</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">e</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">v</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">workquestion</span><span class="p">(</span><span class="kt">char</span><span class="o">*</span> <span class="n">buf</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">char</span> <span class="n">n1</span><span class="p">[</span><span class="mi">20</span><span class="p">],</span> <span class="n">n2</span><span class="p">[</span><span class="mi">20</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"can everything which can %s %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"are everything which can %s %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"are %s %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">sscanf</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="s">"can %s %s"</span><span class="p">,</span> <span class="n">n1</span><span class="p">,</span> <span class="n">n2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">getn</span><span class="p">(</span><span class="n">n1</span><span class="p">);</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">getv</span><span class="p">(</span><span class="n">n2</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">//else assert("workquestion error");
</span> <span class="n">memset</span><span class="p">(</span><span class="n">vis</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">vis</span><span class="p">));</span>
<span class="k">if</span> <span class="p">(</span><span class="n">bfs</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">))</span> <span class="n">printf</span><span class="p">(</span><span class="s">"Y"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">"M"</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">read</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">char</span> <span class="n">buf</span><span class="p">[</span><span class="mi">200</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">length</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="nb">true</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">gets</span><span class="p">(</span><span class="n">buf</span><span class="p">);</span>
<span class="n">length</span> <span class="o">=</span> <span class="n">strlen</span><span class="p">(</span><span class="n">buf</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">buf</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'!'</span><span class="p">)</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">else</span>
<span class="k">if</span> <span class="p">(</span><span class="n">buf</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'.'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">buf</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">workstatement</span><span class="p">(</span><span class="n">buf</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">buf</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">workquestion</span><span class="p">(</span><span class="n">buf</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="c1">//freopen("universal.in","r",stdin);
</span> <span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span> <span class="o">&</span><span class="n">t</span><span class="p">;);</span>
<span class="n">getchar</span><span class="p">();</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tcase</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">tcase</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="o">++</span><span class="n">tcase</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d:</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">tcase</span><span class="p">);</span>
<span class="n">mapcount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">edgenum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">head</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">head</span><span class="p">));</span>
<span class="n">nmap</span><span class="p">.</span><span class="n">clear</span><span class="p">();</span>
<span class="n">vmap</span><span class="p">.</span><span class="n">clear</span><span class="p">();</span>
<span class="k">while</span> <span class="p">(</span><span class="n">read</span><span class="p">());</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
Codeforces Round #111 (Div. 2)
2012-03-11T05:32:25+00:00
http://greenmooon55.com/codeforces-round-111-div-2
<p><a href="http://codeforces.com/contest/160">Codeforces Round #111 (Div. 2)</a></p>
<p>AB略
<a href="http://codeforces.com/contest/160/problem/C">C</a>
看起来挺简单的一道题,看样例显然就是输出a[k/n]和a[k%n],于是WA了两遍…
其实这样是不对的,比如:</p>
<blockquote>
<p>1 1 2
11
11
11
11
12
12
21
21
22
1 2 2 2 3
11
12
12
12
13
21
21
21
22
22
22
22
22
22
22
22
22
23
23
23
31
32
32
32
33</p>
</blockquote>
<p>test3就是这种数据…
其实应该是a[k/n] a[(k - 重复数字区开始位置(21处))/重复数字个数],还要注意long long…</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">k</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">[</span><span class="mi">100005</span><span class="p">];</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">b</span><span class="p">[</span><span class="mi">100005</span><span class="p">];</span> <span class="c1">//重复段开始数字位置
</span> <span class="kt">long</span> <span class="kt">long</span> <span class="n">c</span><span class="p">[</span><span class="mi">100005</span><span class="p">];</span> <span class="c1">//重复数字个数,存在开始位置
</span>
<span class="n">memset</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">b</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">c</span><span class="p">));</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">sort</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="n">n</span><span class="p">);</span>
<span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
<span class="k">else</span> <span class="c1">//重复段结束时处理
</span> <span class="p">{</span>
<span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">c</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="n">i</span> <span class="o">-</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">c</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="n">n</span> <span class="o">-</span> <span class="n">b</span><span class="p">[</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span> <span class="c1">//处理最后的数字
</span> <span class="o">--</span><span class="n">k</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">start</span> <span class="o">=</span> <span class="n">b</span><span class="p">[</span><span class="n">k</span><span class="o">/</span><span class="n">n</span><span class="p">]</span> <span class="o">*</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">long</span> <span class="kt">long</span> <span class="n">count</span> <span class="o">=</span> <span class="n">c</span><span class="p">[</span><span class="n">b</span><span class="p">[</span><span class="n">k</span><span class="o">/</span><span class="n">n</span><span class="p">]];</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="o">/</span><span class="n">n</span><span class="p">]</span> <span class="o"><<</span> <span class="s">" "</span> <span class="o"><<</span> <span class="n">a</span><span class="p">[(</span><span class="n">k</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">/</span> <span class="n">count</span><span class="p">]</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="c1">//cout << a[k/n] << " " << a[k%n] << endl; 错误做法
</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>DE还没做,看起来D是个好题。</p>
Codeforces Beta Round #97 (Div. 2)
2012-03-08T10:03:23+00:00
http://greenmooon55.com/codeforces-beta-round-97-div-2
<p><a href="http://codeforces.com/contest/136">Codeforces Beta Round #97 (Div. 2)</a></p>
<p>AB略,现在都忘了是啥题了。。</p>
<p>C
选择数组中的一个数,并把它改为另一个值(和原值不同),排序后求数组所有位置的最小可能值。
显然就是把最大的数改成1。注意特殊情况:数组里所有的数都是1。
当时把10^5的数组开成10^4了。。</p>
<p>D
判断给出的8个点能否构成一个矩形和一个正方形。
用next_permutation搞出排列,用两个向量数量积是否为零判断垂直,四个角都是直角,说明是矩形,四条边长度相等就是菱形,既是矩形又是菱形就是正方形。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">double</span> <span class="n">eps</span> <span class="o">=</span> <span class="mf">1e-9</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">TPoint</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">;</span>
<span class="p">}</span><span class="n">point</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">index</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">};</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="nf">sgn</span><span class="p">(</span><span class="kt">double</span> <span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">x</span><span class="o">></span><span class="n">eps</span><span class="o">?</span><span class="mi">1</span><span class="o">:</span><span class="n">x</span><span class="o"><-</span><span class="n">eps</span><span class="o">?-</span><span class="mi">1</span><span class="o">:</span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//点积
</span><span class="kt">int</span> <span class="n">dot</span><span class="p">(</span><span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">c</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">c</span><span class="p">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">y</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">c</span><span class="p">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">y</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">//ab是否与cb垂直(b为交点)
</span><span class="kt">bool</span> <span class="n">isPerpendicular</span><span class="p">(</span><span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">c</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="o">!</span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">isRect</span><span class="p">(</span><span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">c</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">d</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">isPerpendicular</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span> <span class="o">&&</span> <span class="n">isPerpendicular</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="o">&&</span> <span class="n">isPerpendicular</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span>
<span class="o">&&</span> <span class="n">isPerpendicular</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="n">dis</span><span class="p">(</span><span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">b</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">y</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">b</span><span class="p">.</span><span class="n">y</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">isRhombus</span><span class="p">(</span><span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">c</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">d</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="p">(</span><span class="n">dis</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="o">==</span> <span class="n">dis</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">))</span> <span class="o">&&</span> <span class="p">(</span><span class="n">dis</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span> <span class="o">==</span> <span class="n">dis</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span> <span class="o">&&</span> <span class="p">(</span><span class="n">dis</span><span class="p">(</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="o">==</span> <span class="n">dis</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">a</span><span class="p">));</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">isSquare</span><span class="p">(</span><span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">c</span><span class="p">;,</span> <span class="k">const</span> <span class="n">TPoint</span> <span class="o">&</span><span class="n">d</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">isRect</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span> <span class="o">&&</span> <span class="n">isRhombus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">8</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">cin</span> <span class="o">>></span> <span class="n">point</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">>></span> <span class="n">point</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">;</span>
<span class="k">do</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">isSquare</span><span class="p">(</span><span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">0</span><span class="p">]],</span> <span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">1</span><span class="p">]],</span> <span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">2</span><span class="p">]],</span> <span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">3</span><span class="p">]])</span> <span class="o">&&</span>
<span class="n">isRect</span><span class="p">(</span><span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">4</span><span class="p">]],</span> <span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">5</span><span class="p">]],</span> <span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">6</span><span class="p">]],</span> <span class="n">point</span><span class="p">[</span><span class="n">index</span><span class="p">[</span><span class="mi">7</span><span class="p">]]))</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"YES</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="mi">8</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">index</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d %d %d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">index</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">index</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">index</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">index</span><span class="p">[</span><span class="mi">3</span><span class="p">]);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d %d %d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">index</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span> <span class="n">index</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span> <span class="n">index</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span> <span class="n">index</span><span class="p">[</span><span class="mi">7</span><span class="p">]);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span> <span class="k">while</span> <span class="p">(</span><span class="n">next_permutation</span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">index</span> <span class="o">+</span> <span class="mi">8</span><span class="p">));</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"NO</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>E
这个题很不错。
输入数据由’0’, ‘1’, ‘?’组成。’?’可能是’0’或’1’。两人轮流取数字,直到最后只剩两个数字,先取的人希望最后剩下的数字最小,后取的人希望剩下的数字最大。
以下基本是<a href="http://codeforces.ru/blog/entry/3353?locale=en">官方题解</a>的翻译…</p>
<p>先取的人显然会取最左面的1,后取的人显然会取最右面的0。
首先考虑没有问号的情况,设1有a个,0有b个,若a>=b+2,结果就是11;若a<=b-1,结果就是00。若a=b+1或a=b,结果可能是01或10,那么到底是哪种呢?因为每次都从左取0和1,而且最后剩下的两个数字里0和1都有,所以肯定没取到最右边的数字。那么如果最后一位是1,结果就是01,最后一位是0,结果就是10。</p>
<p>接下来考虑有问号的情况,设问号有c个。首先判断能不能出现00和11。判断a+c>=b+2和a<=b-1+c即可。然后考虑01和10,若最后一位不是问号,设问号中有x个是1,则c-x个是0。根据a+x=b+(c-x)+(a+b+c)%2,也就是以前的a=b+1或a=b,解出x的值,x必须大于等于零并小于等于c,根据最后一位的数字就能判断是否可能出现01和10。如果最后一位是问号,可以把它看成是0和1分别考虑,即–c后++a或++b,然后再判断x是否合法。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">char</span> <span class="n">ch</span><span class="p">[</span><span class="mi">100005</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="c1">// 1 count
</span> <span class="kt">int</span> <span class="n">b</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="c1">// 0 count
</span> <span class="kt">int</span> <span class="n">c</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="c1">// ? count
</span> <span class="kt">int</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">length</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%s"</span><span class="p">,</span> <span class="n">ch</span><span class="p">);</span>
<span class="n">length</span> <span class="o">=</span> <span class="n">strlen</span><span class="p">(</span><span class="n">ch</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">length</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">switch</span> <span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">case</span> <span class="sc">'1'</span><span class="p">:</span>
<span class="o">++</span><span class="n">a</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'0'</span><span class="p">:</span>
<span class="o">++</span><span class="n">b</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'?'</span><span class="p">:</span>
<span class="o">++</span><span class="n">c</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">c</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o"><</span> <span class="n">b</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"00"</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="n">b</span> <span class="o">||</span> <span class="n">a</span> <span class="o">==</span> <span class="n">b</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'1'</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"01"</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'0'</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"10"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">></span> <span class="n">b</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"11"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o"><</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"00"</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'1'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">b</span> <span class="o">+</span> <span class="n">c</span> <span class="o">-</span> <span class="n">a</span> <span class="o">+</span> <span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">x</span> <span class="o"><=</span> <span class="n">c</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"01"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'0'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">b</span> <span class="o">+</span> <span class="n">c</span> <span class="o">-</span> <span class="n">a</span> <span class="o">+</span> <span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">x</span> <span class="o"><=</span> <span class="n">c</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"10"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span><span class="p">[</span><span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'?'</span><span class="p">)</span>
<span class="p">{</span>
<span class="o">--</span><span class="n">c</span><span class="p">;</span>
<span class="o">++</span><span class="n">a</span><span class="p">;</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">b</span> <span class="o">+</span> <span class="n">c</span> <span class="o">-</span> <span class="n">a</span> <span class="o">+</span> <span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">x</span> <span class="o"><=</span> <span class="n">c</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"01"</span><span class="p">);</span>
<span class="o">--</span><span class="n">a</span><span class="p">;</span>
<span class="o">++</span><span class="n">b</span><span class="p">;</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">b</span> <span class="o">+</span> <span class="n">c</span> <span class="o">-</span> <span class="n">a</span> <span class="o">+</span> <span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span><span class="p">)</span> <span class="o">%</span> <span class="mi">2</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">>=</span> <span class="mi">0</span> <span class="o">&&</span> <span class="n">x</span> <span class="o"><=</span> <span class="n">c</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"10"</span><span class="p">);</span>
<span class="o">--</span><span class="n">b</span><span class="p">;</span>
<span class="o">++</span><span class="n">c</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">c</span> <span class="o">></span> <span class="n">b</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"11"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
HDU3687 National Day Parade
2012-02-14T13:41:59+00:00
http://greenmooon55.com/hdu3687-national-day-parade
<p>国庆游行,学生们本来排成n<em>n的队形,休息时他们仅左右移动,现在求在什么位置恢复n</em>n队形,使所有学生当前位置到目标位置的距离的和最短。
n<=56,m<=200,左上角为(1, 1),右下角为(n, m),每位学生的位置 1<=Xi<=n,1<= Yi<=m</p>
<p>最开始以为是平均数,后来发现就是枚举目标位置。
每行一个vector,存该行点的y坐标。读入后排序,然后枚举队伍最左边的那一列。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">MAX</span> <span class="o">=</span> <span class="mi">2147483647</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">count</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="nb">true</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">n</span> <span class="o">&&</span> <span class="o">!</span><span class="n">m</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">vector</span> <span class="n">line</span><span class="p">[</span><span class="mi">60</span><span class="p">];</span>
<span class="n">count</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="n">n</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">count</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">a</span> <span class="o">>></span> <span class="n">b</span><span class="p">;</span>
<span class="n">line</span><span class="p">[</span><span class="n">a</span><span class="p">].</span><span class="n">push_back</span><span class="p">(</span><span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">sort</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">begin</span><span class="p">(),</span> <span class="n">line</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">end</span><span class="p">());</span>
<span class="kt">int</span> <span class="n">sum</span><span class="p">,</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">MAX</span><span class="p">;</span>
<span class="c1">//起始位置
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">m</span> <span class="o">-</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="c1">//行
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">j</span> <span class="o"><=</span> <span class="n">n</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">//列
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">k</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="n">sum</span> <span class="o">+=</span> <span class="n">abs</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">]</span> <span class="o">-</span> <span class="n">i</span> <span class="o">-</span> <span class="n">k</span><span class="p">);</span> <span class="c1">//-(i+k)
</span> <span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span> <span class="o"><</span> <span class="n">ans</span><span class="p">)</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">sum</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">ans</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
HDU3682 To Be an Dream Architect
2012-02-14T13:30:04+00:00
http://greenmooon55.com/hdu3682-to-be-an-dream-architect
<p>题意:一个 n x n x n 的立方体,每次消除一行(平行于坐标轴),共消除 m 次,求共消除了多少 1 * 1 * 1 的小块。(1 <= n <= 1000, 0 <= m <= 1000)</p>
<p>第一想法是三维布尔数组数组存状态,然后模拟。不会超时但会MLE。
北大的题解里说了两种方法,第一种是考虑线段的交点,然后用容斥原理,我还没想具体怎么写。第二种是一层一层考虑,把垂直于某层的线和在这个面上的线分开考虑,比较好理解。</p>
<p>经过搜索,搜到了这两个题解:
<a href="http://blog.csdn.net/liuwei_nefu/article/details/6009644">http://blog.csdn.net/liuwei_nefu/article/details/6009644</a>
<a href="http://www.cnblogs.com/FreeAquar/archive/2011/09/15/2178029.html">http://www.cnblogs.com/FreeAquar/archive/2011/09/15/2178029.html</a></p>
<p>做法就是把点坐标映射为int,比如x * 1000000 + y * 1000 + z。然后把所有直线上的点丢到一个vector里,排序后再用<a href="http://www.cplusplus.com/reference/algorithm/unique/">unique</a>函数,然后<a href="http://www.cplusplus.com/reference/stl/vector/erase/">删去</a>不需要的部分,求出vector的大小,这就是真正删掉的点。用set做会超时,而且内存占用很多。。
这几个函数只是知道名字,用法一点都不熟悉。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kr">inline</span> <span class="kt">bool</span> <span class="n">illegal</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">x</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="o">!</span><span class="p">(</span><span class="n">x</span> <span class="o"><=</span> <span class="mi">1000</span> <span class="o">&&</span> <span class="n">x</span> <span class="o">></span> <span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
<span class="kr">inline</span> <span class="kt">int</span> <span class="n">getint</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">x</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">y</span><span class="p">;,</span> <span class="k">const</span> <span class="kt">int</span> <span class="o">&</span><span class="n">z</span><span class="p">;)</span>
<span class="p">{</span>
<span class="c1">//cout<> t;
</span> <span class="k">while</span><span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">vector</span> <span class="n">myvector</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span><span class="p">;</span>
<span class="n">getchar</span><span class="p">();</span>
<span class="k">while</span> <span class="p">(</span><span class="n">m</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%c=%d,%c=%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="o">&</span><span class="n">ch1</span><span class="p">;,</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="o">&</span><span class="n">ch2</span><span class="p">;,</span> <span class="o">&</span><span class="n">b</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">illegal</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">||</span> <span class="n">illegal</span><span class="p">(</span><span class="n">b</span><span class="p">))</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">a</span><span class="o">--</span><span class="p">;</span>
<span class="n">b</span><span class="o">--</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch1</span> <span class="o">==</span> <span class="sc">'X'</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch2</span> <span class="o">==</span> <span class="sc">'Y'</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">myvector</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">getint</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">i</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">else</span> <span class="c1">//X=a,Z=b
</span> <span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">myvector</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">getint</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">b</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch1</span> <span class="o">==</span> <span class="sc">'Y'</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch2</span> <span class="o">==</span> <span class="sc">'X'</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">myvector</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">getint</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">i</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="c1">//Y=a,Z=b
</span> <span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">myvector</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">getint</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch1</span> <span class="o">==</span> <span class="sc">'Z'</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch2</span> <span class="o">==</span> <span class="sc">'X'</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">myvector</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">getint</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">a</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">myvector</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">getint</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">sort</span><span class="p">(</span><span class="n">myvector</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">myvector</span><span class="p">.</span><span class="n">end</span><span class="p">());</span>
<span class="n">myvector</span><span class="p">.</span><span class="n">erase</span><span class="p">(</span><span class="n">unique</span><span class="p">(</span><span class="n">myvector</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">myvector</span><span class="p">.</span><span class="n">end</span><span class="p">()),</span> <span class="n">myvector</span><span class="p">.</span><span class="n">end</span><span class="p">());</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="n">myvector</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
HDU4119 Isabella's Message
2012-02-12T04:46:47+00:00
http://greenmooon55.com/hdu4119-isabellas-message
<p>给定密文和密文中可能出现的单词,按题意输出原文。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">map</span><span class="p">[</span><span class="mi">55</span><span class="p">][</span><span class="mi">55</span><span class="p">],</span><span class="n">temp</span><span class="p">[</span><span class="mi">55</span><span class="p">][</span><span class="mi">55</span><span class="p">],</span><span class="n">newmap</span><span class="p">[</span><span class="mi">55</span><span class="p">][</span><span class="mi">55</span><span class="p">],</span><span class="n">mask</span><span class="p">[</span><span class="mi">55</span><span class="p">][</span><span class="mi">55</span><span class="p">];</span>
<span class="kt">char</span> <span class="n">word</span><span class="p">[</span><span class="mi">5</span><span class="p">][</span><span class="mi">2555</span><span class="p">];</span>
<span class="kt">char</span> <span class="n">list</span><span class="p">[</span><span class="mi">105</span><span class="p">][</span><span class="mi">25</span><span class="p">];</span>
<span class="kt">char</span> <span class="n">s</span><span class="p">[</span><span class="mi">5</span><span class="p">][</span><span class="mi">10100</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">ans</span><span class="p">[</span><span class="mi">5</span><span class="p">][</span><span class="mi">10100</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">rotate</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="n">newmap</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">getword</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">pos</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">newmap</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">==</span><span class="sc">'*'</span><span class="p">)</span> <span class="n">word</span><span class="p">[</span><span class="n">num</span><span class="p">][</span><span class="n">pos</span><span class="o">++</span><span class="p">]</span><span class="o">=</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">wordnum</span><span class="p">;</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"1009.txt"</span><span class="p">,</span><span class="s">"r"</span><span class="p">,</span><span class="n">stdin</span><span class="p">);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">t</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">tcase</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span> <span class="n">tcase</span><span class="o"><=</span><span class="n">t</span><span class="p">;</span><span class="n">tcase</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">s</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">s</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">word</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">word</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">ans</span><span class="p">));</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%s"</span><span class="p">,</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%s"</span><span class="p">,</span><span class="n">mask</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">wordnum</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">wordnum</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%s"</span><span class="p">,</span><span class="n">list</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">memcpy</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span><span class="n">mask</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">mask</span><span class="p">));</span>
<span class="n">memcpy</span><span class="p">(</span><span class="n">newmap</span><span class="p">,</span><span class="n">mask</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">mask</span><span class="p">));</span>
<span class="n">getword</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">4</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">rotate</span><span class="p">();</span>
<span class="n">getword</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="n">memcpy</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span><span class="n">newmap</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">newmap</span><span class="p">));</span>
<span class="p">}</span>
<span class="c1">//连接四句话
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">4</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o"><</span><span class="n">i</span><span class="o">+</span><span class="mi">4</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">strcat</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">word</span><span class="p">[</span><span class="n">j</span><span class="o">%</span><span class="mi">4</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">char</span> <span class="n">tempword</span><span class="p">[</span><span class="mi">10100</span><span class="p">];</span>
<span class="cm">/*
strcpy(s[0],"the..love..you....forever");
strcpy(s[1],"love..you..forever");
strcpy(s[2],"..love.the.forever");
strcpy(s[3],"the.forver..love");
*/</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">4</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">==</span><span class="sc">'.'</span> <span class="o">&&</span> <span class="n">j</span><span class="o"><</span><span class="n">strlen</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span> <span class="n">j</span><span class="o">++</span><span class="p">;</span> <span class="c1">//找到第一个单词...
</span> <span class="k">if</span> <span class="p">(</span><span class="n">j</span><span class="o">>=</span><span class="n">strlen</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span> <span class="k">continue</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">tpos</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">j</span><span class="o"><</span><span class="n">strlen</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">tempword</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">tempword</span><span class="p">));</span>
<span class="n">tpos</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">j</span><span class="o"><</span><span class="n">strlen</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&&</span> <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">!=</span><span class="sc">'.'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">tempword</span><span class="p">[</span><span class="n">tpos</span><span class="o">++</span><span class="p">]</span><span class="o">=</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">++</span><span class="p">];</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">find</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o"><</span><span class="n">wordnum</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">tempword</span><span class="p">,</span><span class="n">list</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
<span class="p">{</span>
<span class="n">find</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">++</span><span class="p">;</span> <span class="c1">//单词个数
</span> <span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span><span class="o">=</span><span class="n">k</span><span class="p">;</span> <span class="c1">//第几个单词
</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">find</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//多余的点
</span> <span class="k">while</span> <span class="p">(</span><span class="n">j</span><span class="o"><</span><span class="n">strlen</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">&&</span> <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">==</span><span class="sc">'.'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">j</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">find</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">ar</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span> <span class="c1">//存符合条件的方向
</span> <span class="n">memset</span><span class="p">(</span><span class="n">ar</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">ar</span><span class="p">));</span>
<span class="kt">int</span> <span class="n">arsize</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">4</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">find</span> <span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="n">ar</span><span class="p">[</span><span class="o">++</span><span class="n">arsize</span><span class="p">]</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d:"</span><span class="p">,</span><span class="n">tcase</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">find</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">" FAIL TO DECRYPT</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">continue</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">nar</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">index</span> <span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">minnode</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">arsize</span><span class="o">></span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">minnode</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span> <span class="c1">//字典序最小的序号
</span> <span class="c1">//不停地找出字典序最小的那个...
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">arsize</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">list</span><span class="p">[</span><span class="n">ans</span><span class="p">[</span><span class="n">ar</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="n">index</span><span class="p">]],</span><span class="n">list</span><span class="p">[</span><span class="n">ans</span><span class="p">[</span><span class="n">ar</span><span class="p">[</span><span class="n">minnode</span><span class="p">]][</span><span class="n">index</span><span class="p">]])</span><span class="o"><</span><span class="mi">0</span><span class="p">)</span> <span class="n">minnode</span><span class="o">=</span><span class="n">j</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">p</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="c1">//生成新数组(第一个单词是字典序最小的单词,且相同...)
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">arsize</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">strcmp</span><span class="p">(</span><span class="n">list</span><span class="p">[</span><span class="n">ans</span><span class="p">[</span><span class="n">ar</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="n">index</span><span class="p">]],</span><span class="n">list</span><span class="p">[</span><span class="n">ans</span><span class="p">[</span><span class="n">ar</span><span class="p">[</span><span class="n">minnode</span><span class="p">]][</span><span class="n">index</span><span class="p">]])</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="n">nar</span><span class="p">[</span><span class="o">++</span><span class="n">p</span><span class="p">]</span><span class="o">=</span><span class="n">ar</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">arsize</span><span class="o">=</span><span class="n">p</span><span class="p">;</span>
<span class="n">memcpy</span><span class="p">(</span><span class="n">ar</span><span class="p">,</span><span class="n">nar</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">nar</span><span class="p">));</span><span class="c1">//新数组覆盖旧数组
</span> <span class="n">index</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">ans</span><span class="p">[</span><span class="n">ar</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="mi">0</span><span class="p">];</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">" %s"</span><span class="p">,</span><span class="n">list</span><span class="p">[</span><span class="n">ans</span><span class="p">[</span><span class="n">ar</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="n">i</span><span class="p">]]);</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>模拟题。
以前写的,我是怎么写出这么恶心的代码的…</p>
HDU4112 Break the Chocolate
2012-02-12T03:27:05+00:00
http://greenmooon55.com/hdu4112-break-the-chocolate
<p>将N<em>M</em>K的巧克力分成1<em>1</em>1,用刀切可以同时切多块,用手掰每次只能将一块掰成两块。</p>
<p>思路:用刀切显然是log2(m)+log2(n)+log2(k)(每个都取上整),手掰的话,首先n-1次掰成n块,然后m-1次掰成m<em>n块,最后k-1次掰成m</em>n<em>k块,(n-1)+n</em>(m-1)+m<em>n</em>(k-1),整理得m<em>n</em>k-1。后来看到一种想法,每掰一块多一个,所以就是m<em>n</em>k-1次。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">ans</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="kt">int</span> <span class="n">m</span><span class="p">,</span> <span class="kt">int</span> <span class="n">k</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">ceil</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="kt">double</span><span class="p">(</span><span class="n">n</span><span class="p">))</span><span class="o">/</span><span class="n">log</span><span class="p">(</span><span class="mf">2.0</span><span class="p">))</span> <span class="o">+</span> <span class="n">ceil</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="kt">double</span><span class="p">(</span><span class="n">m</span><span class="p">))</span><span class="o">/</span><span class="n">log</span><span class="p">(</span><span class="mf">2.0</span><span class="p">))</span> <span class="o">+</span> <span class="n">ceil</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="kt">double</span><span class="p">(</span><span class="n">k</span><span class="p">))</span><span class="o">/</span><span class="n">log</span><span class="p">(</span><span class="mf">2.0</span><span class="p">));</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">k</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">t</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><=</span> <span class="n">t</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">m</span> <span class="o">>></span> <span class="n">k</span><span class="p">;</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Case #%d: %lld %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="p">(</span><span class="kt">long</span> <span class="kt">long</span><span class="p">)</span><span class="n">n</span> <span class="o">*</span> <span class="n">m</span> <span class="o">*</span> <span class="n">k</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">ans</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">k</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>写的时候把t和k弄混过……
还要注意用long long。</p>
HDU4121 Xiangqi
2012-02-02T01:52:27+00:00
http://greenmooon55.com/hdu4121-xiangqi
<p>只有四种棋子:将、车、马、炮,黑方只有一个将,现在被红方将,红方有2至7个棋子,判断黑方是否被将死。</p>
<p>考虑黑将的四个行动方向,判断每个位置是否被将死即可。</p>
<p>将:判断两个将之间是否有棋子
车:同上
马:八个方向,容易出错,详见代码
炮:将与炮之间是否只有一个棋子</p>
<p>//不考虑黑方飞将也能过,不知道到底该不该考虑。。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
#include
#include
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">point</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">;</span>
<span class="p">}</span><span class="n">g</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="n">r</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="n">h</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="n">c</span><span class="p">[</span><span class="mi">10</span><span class="p">];</span> <span class="c1">//bg:black general
</span><span class="kt">int</span> <span class="n">gcount</span><span class="p">,</span> <span class="n">rcount</span><span class="p">,</span> <span class="n">hcount</span><span class="p">,</span> <span class="n">ccount</span><span class="p">;</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">dx</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">};</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">dy</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">};</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">hx</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">};</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">hy</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">};</span>
<span class="kt">bool</span> <span class="n">map</span><span class="p">[</span><span class="mi">10</span><span class="p">][</span><span class="mi">10</span><span class="p">];</span> <span class="c1">//红旗子
</span>
<span class="c1">//将是否在范围内
</span><span class="kt">bool</span> <span class="nf">isValid</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">y</span> <span class="o">>=</span> <span class="mi">4</span> <span class="o">&&</span> <span class="n">y</span> <span class="o"><=</span> <span class="mi">6</span> <span class="o">&&</span> <span class="n">x</span> <span class="o">>=</span> <span class="mi">1</span> <span class="o">&&</span> <span class="n">x</span> <span class="o"><=</span> <span class="mi">3</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//[a,y]到[b,y]的棋子个数(不含端点)
</span><span class="kt">int</span> <span class="nf">betweenX</span><span class="p">(</span><span class="kt">int</span> <span class="n">y</span><span class="p">,</span> <span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o"><</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">b</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">y</span><span class="p">])</span> <span class="n">sum</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">b</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">y</span><span class="p">])</span> <span class="n">sum</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">sum</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//[x,a]到[x,b]的棋子个数(不含端点)
</span><span class="kt">int</span> <span class="nf">betweenY</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span> <span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o"><</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">b</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">i</span><span class="p">])</span> <span class="n">sum</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="n">b</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">a</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">i</span><span class="p">])</span> <span class="n">sum</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">sum</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//将的新位置newbg是否会被红方飞将
</span><span class="kt">bool</span> <span class="n">isSafeGeneral</span><span class="p">(</span><span class="n">point</span> <span class="k">const</span> <span class="o">&</span><span class="n">newbg</span><span class="p">;)</span>
<span class="p">{</span>
<span class="c1">//其实只有一个嘛
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">gcount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">y</span> <span class="o">==</span> <span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">betweenX</span><span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">y</span><span class="p">,</span> <span class="n">newbg</span><span class="p">.</span><span class="n">x</span><span class="p">,</span> <span class="n">g</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//是否会被车吃(中间没有其他棋子)
</span><span class="kt">bool</span> <span class="n">isSafeChariot</span><span class="p">(</span><span class="n">point</span> <span class="k">const</span> <span class="o">&</span><span class="n">newbg</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">rcount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">x</span> <span class="o">==</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">&&</span> <span class="n">newbg</span><span class="p">.</span><span class="n">y</span> <span class="o">==</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span> <span class="c1">//这就是吃掉了
</span> <span class="k">if</span> <span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">x</span> <span class="o">==</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">betweenY</span><span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">x</span><span class="p">,</span> <span class="n">newbg</span><span class="p">.</span><span class="n">y</span><span class="p">,</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">y</span> <span class="o">==</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">betweenX</span><span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">y</span><span class="p">,</span> <span class="n">newbg</span><span class="p">.</span><span class="n">x</span><span class="p">,</span> <span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//是否会被炮打(中间棋子为1)
</span><span class="kt">bool</span> <span class="n">isSafeCannon</span><span class="p">(</span><span class="n">point</span> <span class="k">const</span> <span class="o">&</span><span class="n">newbg</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">ccount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">x</span> <span class="o">==</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">&&</span> <span class="n">newbg</span><span class="p">.</span><span class="n">y</span> <span class="o">==</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span> <span class="c1">//这就是吃掉了
</span> <span class="k">if</span> <span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">x</span> <span class="o">==</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">betweenY</span><span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">x</span><span class="p">,</span> <span class="n">newbg</span><span class="p">.</span><span class="n">y</span><span class="p">,</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">y</span> <span class="o">==</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">betweenX</span><span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">y</span><span class="p">,</span> <span class="n">newbg</span><span class="p">.</span><span class="n">x</span><span class="p">,</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">bool</span> <span class="n">isSafeHorse</span><span class="p">(</span><span class="n">point</span> <span class="k">const</span> <span class="o">&</span><span class="n">newbg</span><span class="p">;)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">newx</span><span class="p">,</span> <span class="n">newy</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">hcount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o"><</span> <span class="mi">8</span><span class="p">;</span> <span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">newx</span> <span class="o">=</span> <span class="n">h</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">+</span> <span class="n">dx</span><span class="p">[</span><span class="n">j</span> <span class="o">/</span> <span class="mi">2</span><span class="p">];</span>
<span class="n">newy</span> <span class="o">=</span> <span class="n">h</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="o">+</span> <span class="n">dy</span><span class="p">[</span><span class="n">j</span> <span class="o">/</span> <span class="mi">2</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">newx</span><span class="p">][</span><span class="n">newy</span><span class="p">])</span> <span class="k">continue</span><span class="p">;</span> <span class="c1">//别马腿
</span> <span class="n">newx</span> <span class="o">=</span> <span class="n">h</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="o">+</span> <span class="n">hx</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">newy</span> <span class="o">=</span> <span class="n">h</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="o">+</span> <span class="n">hy</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">newx</span> <span class="o">==</span> <span class="n">newbg</span><span class="p">.</span><span class="n">x</span> <span class="o">&&</span> <span class="n">newy</span> <span class="o">==</span> <span class="n">newbg</span><span class="p">.</span><span class="n">y</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//如果不被将,返回真
</span><span class="kt">bool</span> <span class="n">check</span><span class="p">(</span><span class="n">point</span> <span class="k">const</span> <span class="o">&</span><span class="n">newbg</span><span class="p">;)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="n">isSafeGeneral</span><span class="p">(</span><span class="n">newbg</span><span class="p">)</span> <span class="o">&&</span> <span class="n">isSafeCannon</span><span class="p">(</span><span class="n">newbg</span><span class="p">)</span> <span class="o">&&</span> <span class="n">isSafeHorse</span><span class="p">(</span><span class="n">newbg</span><span class="p">)</span> <span class="o">&&</span> <span class="n">isSafeChariot</span><span class="p">(</span><span class="n">newbg</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">ch</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="nb">true</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">point</span> <span class="n">bg</span><span class="p">,</span> <span class="n">newbg</span><span class="p">;</span> <span class="c1">//bg:black general
</span> <span class="n">gcount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">rcount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">hcount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">ccount</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">map</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">map</span><span class="p">));</span>
<span class="kt">bool</span> <span class="n">checkmate</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">n</span> <span class="o">>></span> <span class="n">bg</span><span class="p">.</span><span class="n">x</span> <span class="o">>></span> <span class="n">bg</span><span class="p">.</span><span class="n">y</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">n</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">cin</span> <span class="o">>></span> <span class="n">ch</span> <span class="o">>></span> <span class="n">a</span> <span class="o">>></span> <span class="n">b</span><span class="p">;</span>
<span class="n">map</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="n">b</span><span class="p">]</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span> <span class="o">==</span> <span class="sc">'G'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">g</span><span class="p">[</span><span class="n">gcount</span><span class="p">].</span><span class="n">x</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="n">g</span><span class="p">[</span><span class="n">gcount</span><span class="p">].</span><span class="n">y</span> <span class="o">=</span> <span class="n">b</span><span class="p">;</span>
<span class="n">gcount</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span> <span class="o">==</span> <span class="sc">'R'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">r</span><span class="p">[</span><span class="n">rcount</span><span class="p">].</span><span class="n">x</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="n">r</span><span class="p">[</span><span class="n">rcount</span><span class="p">].</span><span class="n">y</span> <span class="o">=</span> <span class="n">b</span><span class="p">;</span>
<span class="n">rcount</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span> <span class="o">==</span> <span class="sc">'H'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">h</span><span class="p">[</span><span class="n">hcount</span><span class="p">].</span><span class="n">x</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="n">h</span><span class="p">[</span><span class="n">hcount</span><span class="p">].</span><span class="n">y</span> <span class="o">=</span> <span class="n">b</span><span class="p">;</span>
<span class="n">hcount</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ch</span> <span class="o">==</span> <span class="sc">'C'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">c</span><span class="p">[</span><span class="n">ccount</span><span class="p">].</span><span class="n">x</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="n">c</span><span class="p">[</span><span class="n">ccount</span><span class="p">].</span><span class="n">y</span> <span class="o">=</span> <span class="n">b</span><span class="p">;</span>
<span class="n">ccount</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="c1">//不考虑飞将也能过
</span> <span class="cm">/*
if (!isSafeGeneral(bg))
{
puts("NO");
continue;
}
*/</span>
<span class="c1">//将的四个方向
</span> <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">4</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">newbg</span><span class="p">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">bg</span><span class="p">.</span><span class="n">x</span> <span class="o">+</span> <span class="n">dx</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">newbg</span><span class="p">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">bg</span><span class="p">.</span><span class="n">y</span> <span class="o">+</span> <span class="n">dy</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">isValid</span><span class="p">(</span><span class="n">newbg</span><span class="p">.</span><span class="n">x</span><span class="p">,</span> <span class="n">newbg</span><span class="p">.</span><span class="n">y</span><span class="p">))</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">check</span><span class="p">(</span><span class="n">newbg</span><span class="p">))</span>
<span class="p">{</span>
<span class="n">checkmate</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">checkmate</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"YES"</span><span class="p">);</span>
<span class="k">else</span> <span class="n">puts</span><span class="p">(</span><span class="s">"NO"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>敲代码的时候曾经把g、r、h、c数组弄混过。。以后这种题还是用拼音算了。
测了样例和马的情况就交了。
第一次WA错在puts里面写了\n…
又测了几个数据都正常,然后看了一遍代码,还是没发现错误。
试了黑棋直接飞将,还是WA,看别人题解突然想到我还考虑将走斜线的情况了。。
最后,似乎是否考虑黑棋直接飞将都可以。</p>
<p>这题我没着急慢慢写的,如果现场的话至少两小时吧,很有可能有个小错找不出来,不确定到底能不能写好。
还是边写边想,还好没犯大错误,betweenX等是写了很多之后才想到单独写个函数的。。</p>
<p>只有两周了,时间好紧张= =</p>
2012新年快乐
2011-12-31T15:54:51+00:00
http://greenmooon55.com/2012-happy-new-year
<p>新年快乐~</p>
<p>2011这一年,收获很多。学到了很多东西、转了专业、去了两次ACM现场赛打酱油等等等等</p>
<p>每天都过得很充实。晚上写日记回顾一天的时候常常感觉早上的事是很久以前发生的。现在差不多在OhLife上记了365篇日记了~</p>
<p>希望明年每天都开开心心的,假期好好玩、好好学。参加更多的活动,让生活更精彩~</p>
<p>期末考加油,另外希望明天买到火车票。</p>
用字符数组存int
2011-12-09T13:40:08+00:00
http://greenmooon55.com/store-an-int-in-a-char-array
<p><a href="http://euyuil.com">EUYUIL</a>告诉我可以用字符数组存int。挺好玩。</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>unsigned char test[100];
memset(test, 0, sizeof(test));
int a = 2147483647;
int *p = (int*)&test;
*p = a;
int b = *p;
cout << b << endl;
```
此时test数组为{255, 255, 255, <strong>127</strong>, 0...}
当然,如果a是1的话,test就是{1, 0, 0, 0, 0...}
这是VS2010编译的结果。。不知道其他编译器其他平台结果怎么样。。
刚刚在stackoverflow搜到<a href="http://stackoverflow.com/questions/1522994/store-an-int-in-a-char-array" title="Store an int in a char array?">这个问题</a>,以后有空再看看吧。
总感觉我C++好弱,指针几乎没用过= =
Update @ 2011/12/13 23:39
如果放入TCHAR里,就是{65535, 32767, ...}。
</code></pre></div></div>
20111101
2011-11-01T15:43:45+00:00
http://greenmooon55.com/20111101
<p>这么就十一月了,这学期过得好快啊。</p>
<p>转到软院也没什么特别的感觉。。本来以为这学期会比较轻松比较爽,只是英语交流有点烦人,不过极少数情况下背课文会背到很开心。。特别是在机房…
PS:换了新键盘打字爽多了!</p>
<p>写着到这里都忘了想说啥…囧</p>
<p>感觉现在还是在铜牌和铁牌的边缘= =</p>
<p>概率课又是听不进去…还不如不去呢..期中考怎么办。
OS期中项目挑了个简单的写,自学GUI神马的,写完之后一点成就感都没有,就是一种码农的感觉…
Win程还没开始写,得到deadline再说吧= = 到时候得疯狂一阵,看起来比Java难写多了。
周四英语期中演讲说点啥呢,周四翻了半天Read it later的收藏(顺便整理一下)也没想好,本来想说C语言之父什么的,想想还是算了吧,还是说火车迷吧。</p>
<p>老妈刚才问我看没看F1,才想到都好久没看直播了。火星车还是这么猛= = 大一还加了个F1车迷协会,曾经想过买个方向盘玩F1呢。</p>
<p>福州完了之后好好学英语、好好学数学、好好敲代码。。以后TopCoder之类的比赛多写写吧…</p>
<p>一会把北京A题敲了吧…</p>
<p>数据结构有两节课没听了吧…明天上课的时候看看以前讲的PPT吧。</p>
<p>PS:不喜欢GR和Gmail的新版!字怎么这么大</p>
ICPC 2011
2011-10-13T14:24:24+00:00
http://greenmooon55.com/icpc-2011
<p>随便写个标题吧。。算不算标题党? 整理一下最近写的题目。</p>
<p><strong>大连网络赛</strong>:
<strong>To Miss Our Children Time</strong>
背包问题,排个序就行了,题目描述不清。。</p>
<p><strong>Find Metal Mineral</strong>
树形动归,f[x][j]表示以x为根的树,前i个子树放j个机器人不回来的最小值,DFS的感觉。f[x][0]表示放一个再出来。做的第一个树形动归,参照别人的代码,很巧妙的写法嘛。刚才看题目忘了具体怎么写了= =</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="kt">void</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span><span class="kt">int</span> <span class="n">prev</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="n">head</span><span class="p">[</span><span class="n">x</span><span class="p">];</span><span class="n">i</span><span class="o">!=-</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o">=</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">next</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="o">==</span><span class="n">prev</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">work</span><span class="p">(</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">,</span><span class="n">x</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="n">k</span><span class="p">;</span><span class="n">j</span><span class="o">>=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">+=</span><span class="n">f</span><span class="p">[</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">w</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">l</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">l</span><span class="o"><</span><span class="n">j</span><span class="p">;</span><span class="n">l</span><span class="o">++</span><span class="p">)</span>
<span class="n">f</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">min</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">j</span><span class="p">],</span><span class="n">f</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">l</span><span class="p">]</span><span class="o">+</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">w</span><span class="o">*</span><span class="p">(</span><span class="n">j</span><span class="o">-</span><span class="n">l</span><span class="p">)</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">edge</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="n">l</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
<p>PS:原来这个叫做分组背包= =</p>
<p><strong>The Frog’s Games</strong>
比赛的时候以为是DP,结果就是个二分…</p>
<p><strong>The kth great number</strong>
最简单的办法就是弄一个最小堆,堆顶就是答案,priority_queue用起来很爽。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="n">priority_queue</span> <span class="o"><</span><span class="kt">int</span><span class="p">,</span> <span class="n">vector</span><span class="p">,</span> <span class="n">greater</span> <span class="o">></span> <span class="n">heap</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">heap</span><span class="p">.</span><span class="n">size</span><span class="p">()</span><span class="o"><</span><span class="n">k</span><span class="p">)</span> <span class="n">heap</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
<span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="n">temp</span><span class="o">></span><span class="n">heap</span><span class="p">.</span><span class="n">top</span><span class="p">())</span>
<span class="p">{</span>
<span class="n">heap</span><span class="p">.</span><span class="n">pop</span><span class="p">();</span>
<span class="n">heap</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
<p>还可以写个treap..treap的删除还不会写= =</p>
<p><strong>Dave</strong>
注意正方形的顶点不一定是题中的点。
把点分别按x和y排序,四条线扫描,写得比较乱= =</p>
<p><strong>The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup</strong>
Working in Beijing
Parsing URL
两道水题,第一题题目说明不清楚= = 做做调节心情</p>
<p><strong>上海网络赛</strong>
<strong>24 Puzzle</strong>
如果空位在角上则挪到中间的正方形里,然后比较8个角是否相同,相同才有可能有解。对于4*4,左右交换不改变逆序对,上下交换时逆序数的奇偶性改变一次(0-3,3-0,1-2,2-1)。
<a href="http://zhyu.me/acm/hdu-4021.html">http://zhyu.me/acm/hdu-4021.html</a>
觉得这个证明不完备,没想好怎么证。</p>
<p><strong>Bombing</strong>
multiset真的很爽…</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">typedef</span> <span class="n">map</span><span class="o"><</span><span class="kt">int</span><span class="p">,</span> <span class="n">multiset</span> <span class="o">></span> <span class="n">dict</span><span class="p">;</span>
<span class="kt">void</span> <span class="n">work</span><span class="p">(</span><span class="n">dict</span> <span class="o">&</span><span class="n">a</span><span class="p">;,</span> <span class="n">dict</span> <span class="o">&</span><span class="n">b</span><span class="p">;,</span> <span class="kt">int</span> <span class="o">&</span><span class="n">x</span><span class="p">;)</span> <span class="c1">//delete a(x) from b
</span><span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">].</span><span class="n">size</span><span class="p">());</span>
<span class="k">for</span> <span class="p">(</span><span class="n">multiset</span><span class="o">::</span><span class="n">iterator</span> <span class="n">iter</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">].</span><span class="n">begin</span><span class="p">();</span><span class="n">iter</span><span class="o">!=</span><span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">].</span><span class="n">end</span><span class="p">();</span><span class="n">iter</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">b</span><span class="p">[</span><span class="o">*</span><span class="n">iter</span><span class="p">].</span><span class="n">erase</span><span class="p">(</span><span class="n">x</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">].</span><span class="n">clear</span><span class="p">();</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="n">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;,</span><span class="o">&</span><span class="n">m</span><span class="p">;)</span><span class="o">!=</span><span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="o">==</span><span class="mi">0</span> <span class="o">&&</span> <span class="n">m</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">dict</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">x</span><span class="p">;,</span><span class="o">&</span><span class="n">y</span><span class="p">;);</span>
<span class="n">a</span><span class="p">[</span><span class="n">x</span><span class="p">].</span><span class="n">insert</span><span class="p">(</span><span class="n">y</span><span class="p">);</span>
<span class="n">b</span><span class="p">[</span><span class="n">y</span><span class="p">].</span><span class="n">insert</span><span class="p">(</span><span class="n">x</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">m</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">x</span><span class="p">;,</span><span class="o">&</span><span class="n">y</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="n">work</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">y</span><span class="p">);</span>
<span class="k">else</span> <span class="n">work</span><span class="p">(</span><span class="n">b</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">y</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>Game</strong>
比较简单的博弈问题,比赛的时候没静下心来想。
分组讨论,注意一个细节,9、10如果竖着的放好了,对方就不用抢这种了。</p>
<p><strong>成都网络赛</strong>
<strong>Graph</strong>
给最短边求原图,原来可以这样写</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="kt">void</span> <span class="nf">work</span><span class="p">(</span><span class="k">const</span> <span class="kt">int</span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">==</span><span class="n">j</span> <span class="o">||</span> <span class="n">i</span><span class="o">==</span><span class="n">k</span> <span class="o">||</span> <span class="n">k</span><span class="o">==</span><span class="n">j</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">((</span><span class="o">!</span><span class="n">visited</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])</span> <span class="o">&&</span> <span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">+</span><span class="n">map</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">==</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">])</span>
<span class="p">{</span>
<span class="o">++</span><span class="n">c</span><span class="p">;</span>
<span class="n">visited</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">n</span><span class="o">*</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">-</span><span class="n">c</span><span class="p">);</span>
</code></pre></div></div>
<p><strong>Rolling Hongshu</strong>
物理题,考虑顶点和所有bitter potato。题目描述挺好玩…</p>
<p><strong>The Social Network</strong>
第一次用map。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="n">map</span><span class="o"><</span><span class="n">string</span><span class="p">,</span><span class="kt">int</span><span class="o">></span> <span class="n">num</span><span class="p">;</span>
</code></pre></div></div>
<p>读入:</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="n">cin</span><span class="o">>></span><span class="n">s1</span><span class="o">>></span><span class="n">s2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="p">.</span><span class="n">count</span><span class="p">(</span><span class="n">s1</span><span class="p">))</span> <span class="n">n1</span><span class="o">=</span><span class="n">num</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="n">s1</span><span class="p">)</span><span class="o">-></span><span class="n">second</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">num</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">make_pair</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="o">++</span><span class="n">count</span><span class="p">));</span>
<span class="n">n1</span><span class="o">=</span><span class="n">count</span><span class="p">;</span>
<span class="n">sn</span><span class="p">[</span><span class="n">n1</span><span class="p">]</span><span class="o">=</span><span class="n">s1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="p">.</span><span class="n">count</span><span class="p">(</span><span class="n">s2</span><span class="p">))</span> <span class="n">n2</span><span class="o">=</span><span class="n">num</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="n">s2</span><span class="p">)</span><span class="o">-></span><span class="n">second</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">num</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">make_pair</span><span class="p">(</span><span class="n">s2</span><span class="p">,</span> <span class="o">++</span><span class="n">count</span><span class="p">));</span>
<span class="n">n2</span><span class="o">=</span><span class="n">count</span><span class="p">;</span>
<span class="n">sn</span><span class="p">[</span><span class="n">n2</span><span class="p">]</span><span class="o">=</span><span class="n">s2</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">f</span><span class="p">[</span><span class="n">n1</span><span class="p">][</span><span class="o">++</span><span class="n">f</span><span class="p">[</span><span class="n">n1</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span><span class="o">=</span><span class="n">n2</span><span class="p">;</span><span class="c1">//f[n1]存n1的朋友们
</span><span class="n">f</span><span class="p">[</span><span class="n">n2</span><span class="p">][</span><span class="o">++</span><span class="n">f</span><span class="p">[</span><span class="n">n2</span><span class="p">][</span><span class="mi">0</span><span class="p">]]</span><span class="o">=</span><span class="n">n1</span><span class="p">;</span>
</code></pre></div></div>
<p>接下来就慢慢弄吧…</p>
<p><strong>北京网络赛</strong>
<strong>Eliminate Witches!</strong>
模拟,递归处理,WA好几次= =
不过这个是我在今年网络赛时作出的第一道题= =</p>
<p><strong>Panda</strong>
树状数组。a[i]表示以i开头的是不是wbw。自己没想到这种方法。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">if</span> <span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">==</span><span class="sc">'w'</span> <span class="o">&&</span> <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">==</span><span class="sc">'b'</span> <span class="o">&&</span> <span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">]</span><span class="o">==</span><span class="sc">'w'</span><span class="p">)</span> <span class="n">add</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
</code></pre></div></div>
<p><strong>Tourism Planning</strong>
第一个状态压缩DP,把某人去不去用二进制表示。
f[15][1030];//f[i][j]前i个景点,第j个状态的最大值
预处理当前状态能由哪些状态得到,如果不预处理HDU可以很快AC,BOJ会TLE= =</p>
<p><strong>wolf5x</strong>
概率DP。
比赛时就想对了方法,读题不认真,以为第一步左右概率相同呢。
赛后写好,发现还是看错题了,以为是求停止位置,原来是求步数的期望,可以直接把所有状态的概率加起来!</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">ans</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">p</span><span class="p">[</span><span class="mi">2010</span><span class="p">][</span><span class="mi">4</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">f</span><span class="p">[</span><span class="mi">2010</span><span class="p">][</span><span class="mi">4</span><span class="p">];</span>
<span class="kt">double</span> <span class="n">temp1</span><span class="p">,</span><span class="n">temp2</span><span class="p">,</span><span class="n">temp3</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">t</span><span class="p">;);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">t</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;,</span><span class="o">&</span><span class="n">a</span><span class="p">;,</span><span class="o">&</span><span class="n">b</span><span class="p">;);</span>
<span class="n">ans</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%lf%lf%lf%lf"</span><span class="p">,</span><span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span><span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span><span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">],</span><span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]);</span>
<span class="n">memset</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">));</span>
<span class="n">temp1</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">a</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">b</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">></span><span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span><span class="o">+=</span><span class="n">temp1</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="mi">3</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">temp1</span><span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">];</span>
<span class="n">temp1</span><span class="o">*=</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">a</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">temp1</span><span class="o">=</span><span class="n">temp2</span><span class="o">=</span><span class="n">temp3</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="n">i</span><span class="o">+</span><span class="n">a</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">i</span><span class="o">+</span><span class="n">b</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span><span class="o">></span><span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">ans</span><span class="o">+=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">temp1</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="n">temp2</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">temp3</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+=</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="n">temp2</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">temp3</span><span class="p">)</span><span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">];</span> <span class="c1">//表示以这种状态踩在j
</span> <span class="n">f</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">+=</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">temp1</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">temp3</span><span class="p">)</span><span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="n">f</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span><span class="o">+=</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">temp1</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="n">temp2</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span><span class="o">*</span><span class="n">temp3</span><span class="p">)</span><span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">3</span><span class="p">];</span>
<span class="n">temp1</span><span class="o">*=</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">];</span> <span class="c1">//tempi表示f[prev][i]不能走的概率
</span> <span class="n">temp2</span><span class="o">*=</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="n">temp3</span><span class="o">*=</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">ans</span><span class="o">+=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">3</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%.8lf</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">ans</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>大连现场赛</strong>
<strong>The Last Puzzle</strong>
对于任意一段,都是从任意一端开始到中间,因为如果从中间开始,还是要先到两端再到最终节点。想通了这个就很好写了。
f[i][j][k]表示从i到j这一段,k表示从左或从右开始,所需的最短时间。不可能则记为-1。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
f[i][j][1] 表示先按右端点的所需时间
f[i][j][0] 表示先按左端点的所需时间
r[i][j][0] (i,j)区间先左端点的话,(i+1,j)选哪个端点
r[i][j][1] (i,j)区间先右端点的话,(i,j-1)选哪个端点
*/</span>
<span class="kt">int</span> <span class="n">t</span><span class="p">[</span><span class="mi">210</span><span class="p">],</span><span class="n">d</span><span class="p">[</span><span class="mi">210</span><span class="p">],</span><span class="n">f</span><span class="p">[</span><span class="mi">210</span><span class="p">][</span><span class="mi">210</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">r</span><span class="p">[</span><span class="mi">210</span><span class="p">][</span><span class="mi">210</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">print</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">,</span> <span class="kt">int</span> <span class="n">c</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">b</span><span class="o">-</span><span class="n">a</span><span class="o">==</span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">a</span><span class="p">);</span>
<span class="k">else</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d "</span><span class="p">,</span><span class="n">b</span><span class="p">);</span>
<span class="n">print</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">r</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="n">b</span><span class="p">][</span><span class="n">c</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d "</span><span class="p">,</span><span class="n">a</span><span class="p">);</span>
<span class="n">print</span><span class="p">(</span><span class="n">a</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">r</span><span class="p">[</span><span class="n">a</span><span class="p">][</span><span class="n">b</span><span class="p">][</span><span class="n">c</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"zoj3541.txt"</span><span class="p">,</span><span class="s">"r"</span><span class="p">,</span><span class="n">stdin</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;)</span><span class="o">!=</span><span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">t</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">d</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="c1">// 相邻的
</span> <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">>=</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">>=</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=-</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">k</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">k</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="o">-</span><span class="n">k</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">j</span><span class="o">=</span><span class="n">i</span><span class="o">+</span><span class="n">k</span><span class="p">;</span>
<span class="c1">// f[i][j][0]
</span> <span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">!=-</span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">!=-</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">!=-</span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">></span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">!=-</span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">!=-</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">!=-</span><span class="mi">1</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">></span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">d</span><span class="p">[</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
<span class="n">r</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">>=</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">=-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">>=</span><span class="n">t</span><span class="p">[</span><span class="n">j</span><span class="p">])</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=-</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">n</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">==-</span><span class="mi">1</span> <span class="o">&&</span> <span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">n</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">==-</span><span class="mi">1</span><span class="p">)</span> <span class="n">puts</span><span class="p">(</span><span class="s">"Mission Impossible"</span><span class="p">);</span>
<span class="k">else</span>
<span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">n</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">!=-</span><span class="mi">1</span><span class="p">)</span> <span class="n">print</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="mi">0</span><span class="p">);</span>
<span class="k">else</span> <span class="n">print</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p><strong>Hexadecimal View</strong>
水题,不知道可以用 %x 输出…</p>
<p><strong>Number String</strong>
f[i][j]存当前所有可能情况,即i=n时只有f[n][1]。表示字符串中第i位是,表中第j个有几种情况。f[i+1]保存的数量比f[i]少一个,因为有一个数字被选走了。</p>
<div class="language-cpp highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">f</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">ii</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">ii</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">ii</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">i</span><span class="o">=</span><span class="n">ii</span><span class="o">+</span><span class="mi">2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">str</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span><span class="o">==</span><span class="sc">'I'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">str</span><span class="p">[</span><span class="n">ii</span><span class="p">]</span><span class="o">==</span><span class="sc">'D'</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">];</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">>=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o">--</span><span class="p">)</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">sum</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">sum</span><span class="o">=</span><span class="p">(</span><span class="n">sum</span><span class="o">+</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">])</span><span class="o">%</span><span class="n">MOD</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">n</span><span class="o">-</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">sum</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="mi">1</span><span class="p">]);</span>
</code></pre></div></div>
<p><strong>福州网络赛</strong>
<strong>SanguoSHA</strong>
当时不爽,写这题写了好久= = 最后写好了觉得会WA,于是没交,回宿舍交了发现过了。
STL里居然有全排列… <a href="http://www.cplusplus.com/reference/algorithm/next_permutation/">next_permutation</a> 和 <a href="http://www.cplusplus.com/reference/algorithm/prev_permutation/">prev_permutation</a>。</p>
<p>===
仔细想想有些题还是可以做的,并不是不会算法,而是想不到。另外数学太烂了。</p>
<p>大二,作业没大一多了,更加觉得时间不够用。平时训练做题效率很低。还有好多想学的东西呢。</p>
2011暑假做的ACM题目
2011-08-13T17:37:46+00:00
http://greenmooon55.com/2011-summer-programming-problems
<p>去了北大那个暑期课程… 对于我来说还是难了点,我觉得还不如自己看PPT= =。早知道能找得到10年的PPT就预习一下了。。
发现不会的好多,慢慢学吧。</p>
<p>部分题目:
8.7
HDU <a href="http://acm.hdu.edu.cn/showproblem.php?pid=3836">3836</a> Equivalent Sets Tarjan强连通分量</p>
<p>8.8
POJ <a href="http://poj.org/problem?id=1273">1273</a> Drainage Ditches 最简单的网络流
POJ <a href="http://poj.org/problem?id=3436">3436</a> ACM Computer Factory 把机器拆成两个点求最大流
POJ <a href="http://poj.org/problem?id=2112">2112</a> Optimal Milking Floyd求最短路,然后二分答案,求最大流判断是否满足</p>
<p>8.9
POJ <a href="http://poj.org/problem?id=1149">1149</a> PIGS 建图不好想
POJ <a href="http://poj.org/problem?id=2396">2396</a> Budget 建图也不好想,有流量限制的最大流,用邻接矩阵写得很痛苦= =
//终于知道网络流是啥意思了。。感觉还得多做题
TopCoder SRM513 DIV2 第一题 这也算是我第一道TopCoder题</p>
<p>8.10
POJ <a href="http://poj.org/problem?id=2135">2135</a> Farm Tour 最小费用最大流,用SPFA选最短路增广
POJ <a href="http://poj.org/problem?id=2318">2318</a> TOYS
POJ <a href="http://poj.org/problem?id=2398">2398</a> Toy Storage 这两题是很简单的计算几何,用叉乘判断左右+二分
POJ <a href="http://poj.org/problem?id=1113">1113</a> Wall 做的第一个凸包,自己写的~</p>
<p>8.11
POJ <a href="http://poj.org/problem?id=2349">2349</a> Arctic Network 最小生成树,第一次写Prim…
TopCoder SRM512和513 DIV2 的前两题</p>
<p>8.12
POJ <a href="http://poj.org/problem?id=1204">1204</a> Word Puzzles Trie树,这东西太神奇了。。真快,(现在对KMP还不是很理解= =)</p>
<p>8.13
POJ <a href="http://poj.org/problem?id=3987">3987</a> Computer Virus on Planet Pandora Trie树
POJ <a href="http://poj.org/problem?id=3691">3691</a> DNA repair 在Trie树上DP,看了答案还想了很久</p>
淘宝密码被盗
2011-07-06T08:34:06+00:00
http://greenmooon55.com/taobao-password-stolen
<p>其实没什么好说的,就是淘宝密码被盗和绑定的手机被改,应该是在图书馆登录过一次支付宝。。现在觉得支付宝还是挺安全的,发现异地登录就自动关闭余额支付功能了。最开始我还以为和foursquare一样,把嘉定和上海误会成两个城市了。。一直用支付宝转账+提现来转生活费,这样节省手续费,以后更得注意安全了= =</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2011/07/20110706154901912.png"><img src="http://greenmoon55.com/wp-content/uploads/2011/07/20110706154901912.png" alt="" /></a>
我好像登录的就是支付宝。。而支付宝密码没有被改。</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2011/07/20110706153808217.png"><img src="http://greenmoon55.com/wp-content/uploads/2011/07/20110706153808217.png" alt="" /></a>
这是淘宝信息,这时间,显然不是我。。手机号也不对。</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2011/07/20110706161501432.png"><img src="http://greenmoon55.com/wp-content/uploads/2011/07/20110706161501432.png" alt="" /></a>
由于超时被关闭的交易</p>
<p>============</p>
<p>第一次感到丢失密码的可怕是看这个:http://www.storyday.com/html/y2008/1405_hutchison-lost-password-gmail.html</p>
<p>这是好办法:http://www.storyday.com/html/y2007/581_manage-your-password.html</p>
<p>============</p>
<p>1换什么密码好?想个自己记得住别人记不住的密码及安全问题很难啊。。而且不同网站密码最好不要相同,至少要保证找回密码邮箱的安全性,还不能忘了安全问题。最好还得大小写数字特殊符号。</p>
<p>2尽量不要使用公用电脑,这才是最重要的吧。在任何情况下我都不会在非本人电脑上登录gmail(好像去年9月初在网吧上过一次= =),现在看来。。其他的也不太安全,图书馆的电脑连进程都不能看= = 上人人的话问题不大吧。。不过要是日志被删也不爽呃,应该没人这样吧…记得删除cookies、浏览记录什么的。</p>
Tongji University Programming Contest 2011
2011-05-11T16:26:42+00:00
http://greenmooon55.com/tongji-university-programming-contest-2011
<p>周四晚预赛。。之前几乎无准备,四月份只写了4道acm题。。。TOJ服务器太烂,交完题要pending一小时= = 所以说用小号交题意义也不大= =</p>
<p>http://acm.tongji.edu.cn/contest?cid=1043</p>
<p>过了A:字符串水题 和 D:硬币翻转。。都算水题。C看起来是个简单的DP,但不知道为什么不对= =</p>
<p>热身赛,A:判断线段是否在圆内,直接判断端点就行了 B:已知每题的AC率,求做出题目数的期望。那么。。直接求和就行了.. 很快就AC了,然后我和队友徐伟就去图书馆睡觉了~(PS:嘉定食堂扑克花色型的鸡块和鸡蛋糕都挺好吃^_^,校车本部到嘉定走中环和京沪高速仅需40分!)</p>
<p><img src="http://greenmoon55.com/wp-content/uploads/2011/05/p_large_oItM_547300039ba35c6f.jpg" alt="p_large_oItM_547300039ba35c6f" /></p>
<p>下午决赛,发题目之前在电脑上看到H题叫“GPA计算器”,感觉应该会很简单,所以先看这题,果然很简单,很快AC,拿到黄色气球,心情很棒。然后开始看A,求(N-1)! % N(N <= 10,000,000),两次都TLE,没想法,此时发现很多人把B也过掉了,有点着急了。B是给出三个矩形顶点坐标,求覆盖面积,感觉情况太多了,没法考虑全。其实见过这类题,不过没细想过,到最后也没做出来。接下来就是队友继续想A题,我看其他题目,感觉F题的最小生成树应该差不多,不过这题各顶点是用字符串表示的,处理可能稍稍麻烦。而且对最小生成树还是不太熟,尽管前一天晚上刚刚复习了一下并且手里有源代码,暂时放弃。</p>
<p>这时非常痛苦,大部分人都已经至少作出两题了,我俩不知道该做啥= = 发现身后的女生组挂上了红色的气球,以为她们做出了C,看了下题,感觉也是可以做的,就是麻烦点。C是字符串题,需要递归处理括号什么的。对C++的字符串处理不熟悉,弄了半天终于写好一小半,然后发现还有负数的情况…果断放弃了= =发现最后C只有3个提交,没人做对= =看来我是看错了…</p>
<p>这时只剩一个多小时了,我基本上准备放弃了。又看了一遍E题,发现有希望。。第一遍看怎么没发现= = E题是从矩阵中找出正方形,数据范围很小。直接暴力了。。没想到调了半天都不对,最后时刻发现M和N搞反了= =呃在调E的时候队友终于找到A的规律了,这两道题都是最后才做好的,要是我的话肯定早放弃A了= =。</p>
<p>http://acm.tongji.edu.cn/files/tongji2011_finalstanding.html</p>
<p>最终排名40,前35有奖。感觉其实还可以吧,毕竟最近做题太少了,唔,最晚暑假起全力ACM,拿成绩估计没啥希望,不过作为CS的学生,至少要熟练掌握常用算法吧。再认真想一下。。从预选赛到决赛,所有做出来的题目都没用到任何稍稍高级的算法,都算比较水的题= =</p>
<p>这算是我第一次参加这类现场赛,随时判题出成绩和排名,还有气球。现场很刺激,还有饼干牛奶水。虽然可以带纸质材料,可是…在这么紧张的时候用处不大= = 难道还能新学个算法?当作备忘录还差不多= =</p>
<p><img src="http://greenmoon55.com/wp-content/uploads/2011/05/p_large_8vAw_60d9000430f15c71.jpg" alt="p_large_8vAw_60d9000430f15c71" /></p>
<p>明年再来:)</p>
<p>Update @ 2011-05-08 0:39 第一次用C++…因为现在学C++呢…估计以后也不会用C了。</p>
2010游记(1)——K518吉林到上海
2011-04-16T11:27:32+00:00
http://greenmooon55.com/2010-journey-1-k518-jilin-to-shanghai
<p>[caption id=”attachment_286” align=”aligncenter” width=”600” caption=”20100413,出发的前一天,东北还有雪。。”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1482.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1482-600x450.jpg" alt="我家窗外" /></a>[/caption]</p>
<p>[caption id=”attachment_296” align=”aligncenter” width=”578” caption=”当时的时刻表”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/20110416182636560.png"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/20110416182636560.png" alt="时刻表" /></a>[/caption]</p>
<p>接下来是个非常好玩的事情,如图(来自盛名时刻表,数据日期:2010.04.15),K7322由K76套跑,T5316由T271套跑。现在时间长了真的记不清了,好象是因为已经在12306.cn上查到了K76晚点,所以买了T5316的票,如果没有记错的话。候车的时候K76来了,哪个先发车呢?车站让所有旅客都上了K7322,军人候车室的检票员听到手台里说T5316先发车,于是我妈和我跑过K76车尾上了二站台的T5316,下轨道的时候还被问。。不过没管他直接上了车。所以说..到九台之前,很可能T5316只有我们这两个旅客。。</p>
<p>[caption id=”attachment_287” align=”aligncenter” width=”600” caption=”空无一人的T5316”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1485.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1485-600x450.jpg" alt="空无一人的T5316" /></a>[/caption]</p>
<p>[caption id=”attachment_288” align=”aligncenter” width=”600” caption=”K7322,拜拜”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1487.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1487-600x450.jpg" alt="K7322,拜拜" /></a>[/caption]</p>
<p>[caption id=”attachment_289” align=”aligncenter” width=”600” caption=”长吉城际施工情况1”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1488.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1488-600x450.jpg" alt="长吉城际施工情况1" /></a>[/caption]</p>
<p>[caption id=”attachment_290” align=”aligncenter” width=”600” caption=”轨道车?不太懂”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1489.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1489-600x450.jpg" alt="轨道车?不太懂" /></a>[/caption]</p>
<p>到了长春,去桂林路买了三本杂志,应该有《第一财经周刊》和《中国国家地理》,然后差不多就去车站了。和预想的一样,杂志基本没看。。每次在火车上都一直看着窗外风景,哪有空看杂志玩扑克。。中午坐上K518,如果没记错的话。。2010.01的塞拉门25G,比较新的车。</p>
<p>[caption id=”attachment_291” align=”aligncenter” width=”600” caption=”根据EXIF的时间,这应该是四平站”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1490.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1490-600x450.jpg" alt="四平站" /></a>[/caption]</p>
<p>[caption id=”attachment_292” align=”aligncenter” width=”600” caption=”白天看秦沈,激动啊!”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1491.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1491-600x450.jpg" alt="白天看秦沈" /></a>[/caption]</p>
<p>[caption id=”attachment_293” align=”aligncenter” width=”600” caption=”硬卧灯,当时觉得很漂亮。。”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1495.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1495-600x450.jpg" alt="硬卧灯" /></a>[/caption]</p>
<p>似乎快到天津才睡着,早上醒来已经进入济南市区(没看到黄河= =),然后再济南站再次看到追踪运行的K55(55是我的幸运数字哎~其实是我的小学学号。。)</p>
<p>[caption id=”attachment_294” align=”aligncenter” width=”600” caption=”江南~13:26快到南京了”]<a href="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1498.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2011/04/DSCF1498-600x450.jpg" alt="江南~" /></a>[/caption]
过长江时拍下了下面这段视频,感觉效果很好(主要指声音),可惜的是没进站我就关相机了。。没拍全,好想听听进站的道岔声。</p>
<p>接下来就是旅途中最激动人心的时刻了,沪宁铁路。曾经在MSTS(2001年微软出的模拟火车游戏)中跑过无数次沪宁线,可能耗费了几十个小时。过了南京发现。。沪宁其实也没有那么繁忙,可能下午不是最忙的时候?为什么我觉得还没京哈(沈长段)忙呢?K515在这里都很多待避,301公里开了5个多小时。。现在能记起来的就是在镇江有个,然后再安亭大约待避了半小时。。被N趟动车踩。实际在车上待避时不觉得烦。PS:K515过了山东后的卧铺也有人买。。</p>
<p>很喜欢华东,可能是从中学地理课开始的。。曾经多次查上海、杭州、苏州之间的时刻表规划行程。。那时候好像还没有动车呢。所以,第一次踩在上海站的站台上,心里很激动。最后说下,第一次坐的上海地铁是三号线~上海火车站到曹杨路。因为第二天一早就从这里去看F1咯~武宁路这边很热闹。</p>
<p>我对公共交通很感兴趣,特别是轨道交通~</p>
2010游记(0)
2011-04-16T10:02:24+00:00
http://greenmooon55.com/2010-journey-0
<p>还剩10分钟熄灯,终于决定不能再拖了。。。</p>
<p>去年很重要的一件事就是跑出去转了一大圈,正好一年整。</p>
<p>4月14日——5月8日:吉林——长春——上海——西塘——杭州——南昌——香港——澳门——珠海——广州——长沙——武汉——青岛——吉林</p>
<p>其实主要目的就是看场F1,上赛场的合同是签到去年的,想着票价这么便宜(相对于其他国家),万一今年没有了怎么办。。</p>
<p>这篇日志,从去年5月拖到6月,到暑假,再到寒假,再到现在。。都一年了。其实好多东西都忘了,只是发发照片吧。</p>
<p>其实一共也没照多少照片,有时像个完美主义者,觉得拍不好于是就不拍了。全程都没有智能手机、没有GPS导航、没有提前计划。每天晚上在旅店计划下一天的出行路线、公共交通、订下一天住的地方。。很辛苦。在每个地方呆的时间太短了,有点对不起花的这些钱。。。本来是只想来上海的,看完F1之后有点觉得在浪费时间。。什么都没学。。所以后来玩得也不太爽,很快回来了。</p>
<h1 id="快熄灯了慢慢发吧争取年内发完">快熄灯了,慢慢发吧。争取年内发完。。</h1>
<p>首发于人人网。。。2011-04-14 23:00</p>
HDU3560一直TLE
2011-03-31T02:57:41+00:00
http://greenmooon55.com/20110331-tle
<p>冒个泡。。。这里几个月没更新了吧?= =
http://acm.hdu.edu.cn/showproblem.php?pid=3560
是这个题。。一直TLE
看起来是个简单的并查集题目。。周日刚学的
昨晚开始写,参照是学长的union函数,今天看了CRLS上这一部分,改了改。
网上搜了几个程序,看起来和我的都差不多嘛,删删改改交了十几次都是TLE= =
似乎。。很少遇到这种情况啊。</p>
<p>这是<strong>TLE</strong>代码,求助= =</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
#include
</span>
<span class="cp">#define maxn 100005
</span><span class="kt">int</span> <span class="n">father</span><span class="p">[</span><span class="n">maxn</span><span class="p">],</span><span class="n">rank</span><span class="p">[</span><span class="n">maxn</span><span class="p">];</span> <span class="c1">//father初始化为-1,<del>其实还不太理解rank为什么只在相等的时候加1</del>。懂了!“Maintain rank(x) as an upper bound on the depth of the tree rooted at x. ” 可以google一下 union by rank. 有个PPT
</span>
<span class="kt">int</span> <span class="nf">findfather</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">father</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o"><</span><span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="n">a</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">father</span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="o">=</span><span class="n">findfather</span><span class="p">(</span><span class="n">father</span><span class="p">[</span><span class="n">a</span><span class="p">]);</span>
<span class="k">return</span> <span class="n">father</span><span class="p">[</span><span class="n">a</span><span class="p">];</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">un</span> <span class="p">(</span><span class="kt">int</span> <span class="n">u</span><span class="p">,</span> <span class="kt">int</span> <span class="n">v</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">rx</span><span class="o">=</span><span class="n">findfather</span><span class="p">(</span><span class="n">u</span><span class="p">),</span><span class="n">ry</span><span class="o">=</span><span class="n">findfather</span><span class="p">(</span><span class="n">v</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rx</span><span class="o">!=</span><span class="n">ry</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rank</span><span class="p">[</span><span class="n">rx</span><span class="p">]</span><span class="o">></span><span class="n">rank</span><span class="p">[</span><span class="n">ry</span><span class="p">])</span> <span class="n">father</span><span class="p">[</span><span class="n">ry</span><span class="p">]</span><span class="o">=</span><span class="n">rx</span><span class="p">;</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">father</span><span class="p">[</span><span class="n">rx</span><span class="p">]</span><span class="o">=</span><span class="n">ry</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">rank</span><span class="p">[</span><span class="n">rx</span><span class="p">]</span><span class="o">==</span><span class="n">rank</span><span class="p">[</span><span class="n">ry</span><span class="p">])</span> <span class="n">rank</span><span class="p">[</span><span class="n">ry</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">u</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="n">ans1</span><span class="p">,</span><span class="n">ans2</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">degree</span><span class="p">[</span><span class="n">maxn</span><span class="p">],</span><span class="n">flag</span><span class="p">[</span><span class="n">maxn</span><span class="p">];</span>
<span class="k">while</span><span class="p">(</span><span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;,</span><span class="o">&</span><span class="n">m</span><span class="p">;)</span><span class="o">!=</span><span class="n">EOF</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">memset</span><span class="p">(</span><span class="n">father</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">father</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">degree</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">degree</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">flag</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">flag</span><span class="p">));</span>
<span class="n">memset</span><span class="p">(</span><span class="n">rank</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">rank</span><span class="p">));</span>
<span class="n">ans1</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">ans2</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="o">==</span><span class="mi">0</span> <span class="o">&&</span> <span class="n">m</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">m</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">u</span><span class="p">;,</span><span class="o">&</span><span class="n">v</span><span class="p">;);</span>
<span class="n">un</span><span class="p">(</span><span class="n">u</span><span class="p">,</span><span class="n">v</span><span class="p">);</span>
<span class="n">degree</span><span class="p">[</span><span class="n">u</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="n">degree</span><span class="p">[</span><span class="n">v</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">degree</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">!=</span><span class="mi">2</span><span class="p">)</span> <span class="n">flag</span><span class="p">[</span><span class="n">findfather</span><span class="p">(</span><span class="n">i</span><span class="p">)]</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span> <span class="c1">//度不为二,则不是环
</span> <span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">father</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o"><</span><span class="mi">0</span><span class="p">)</span> <span class="c1">//如果是树根
</span> <span class="p">{</span>
<span class="n">ans1</span><span class="o">++</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">flag</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="n">ans2</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">ans1</span><span class="p">,</span><span class="n">ans2</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
同济饮食推荐
2010-12-18T05:52:30+00:00
http://greenmooon55.com/%e5%90%8c%e6%b5%8e%e9%a5%ae%e9%a3%9f%e6%8e%a8%e8%8d%90
<p><strong>西北食堂</strong>
就在宿舍旁边所以常去。一楼貌似比较便宜但是很少去。常去二楼右面吃,两个菜+二两/三两饭大约五六块钱。特色菜:最右面臭豆腐(貌似不臭..)1.6四个,大约11:50前有。早上烧卖也算特色菜吧。早饭我一般肉包+烧卖+粥=2.7。</p>
<p>早上高峰期不清楚,反正除了周末早上只开一个口,好像人都不多。平时中午11:30小高峰,中间人少,12:00左右人最多。周末人更少。</p>
<p><strong>留学生食堂</strong>
石锅拌饭吃过一次,和一中三楼的真的没法比。右面的菜太贵基本没吃过。豆腐汤+饭比较好吃。8块。</p>
<p>中午人比较多,建议别去了。晚上高峰在17:00左右,可以看情况早去或晚去。</p>
<p><strong>学苑食堂</strong>
离教学楼比较近,所以中午就别考虑了。不过貌似一楼很便宜,有七毛钱的菜。少吃点三四块钱就够了。一楼的面供应到很晚,以前常吃4.4的鸡丁面。21:50图书馆准备关门时一楼左面的点心、肉包还有,几乎每天都会去吃肉包。</p>
<p>二楼的铁板饭同样和一中的没法比,不好吃还咸。三楼西餐部超级棒。常吃:咖喱鸡饭5块、红烩牛肉饭/咖喱牛肉饭6.5。不过这个时间很重要,平时只有晚上有,如果七八节有课快点去来得及,五点左右一分钟可能就会多很多人排队。人最多我猜是五点十分吧。强烈推荐周末中午去,今天中午去才不到五个人排队。</p>
<p><strong>西苑食堂</strong>
这个去得比较少。早上特色:蛋饼(不知道是不是这么叫..)、肉包(馅比其他食堂大)、豆浆(别的食堂没有)。一般周三早上去南校区上课前顺便去,貌似晚了就没蛋饼了= =</p>
<p><strong>南校区食堂</strong>
就去过一两次,早上有生煎,不过嘛显然没小杨生煎好吃。。</p>
<p><strong>校外</strong>
小杨生煎:大连路西南农行旁边。5.5四个,上海特色。酸辣粉一般,还贵。。馄饨、汤还可以
四海游龙:锅贴
新亚大包:貌似一般,还有点贵。
麦当劳:南京路中段在地下那个,还有豆瓣上“麦当劳我就喜欢上海”的照片,而且一般人很少,闹中取静的地方。。</p>
<p>上面这几家人均十几块就够了</p>
<p>牛肉面:四平路过赤峰路往南,路口西南角有一家,复旦一条街南面也有一家不错,价格五六块钱一大碗很便宜。
复旦一条街那个鸡蛋灌饼没我家楼下那个好吃。。而且貌似上海没有卖凉皮的,连大润发都没有。。
麻辣烫米线从来不敢吃,这个不清楚。</p>
<p>其实很少去校外吃,吃在同济嘛,食堂已经够好的了。其实我觉得一中食堂就不错了。。</p>
同济大学上海电信无法上网的快速解决办法
2010-12-01T09:04:38+00:00
http://greenmooon55.com/a-fast-solution-to-campus-internet-connection-problem
<p>本月初要扣九十块,没钱的先去冲吧。。</p>
<p>访问:<a href="http://sh.ct10000.com/">http://sh.ct10000.com/</a> 选择网页客服教他刷新密码。 96861人太多打不通= = 再次BS上海电信。。这服务态度、这渣网速= =</p>
<blockquote>
<p>您已进入服务队列,在您前面还有0位咨询者在等待!
等待时间:86
akweb009 正在为您服务
AKWEB009说:(2010-12-01 16:35:17)
您好,欢迎使用中国电信网上营业厅在线客服。
您说:(2010-12-01 16:35:19)
帮我重置一下密码 ad43<strong>**</strong>@college
akweb009说:(2010-12-01 16:35:21)
我是今天的值班客服,很高兴为您服务。请问您需要咨询哪方面的问题?为了更好的跟踪服务效果,请在对话结束后对我的服务满意度进行评价,非常感谢您的支持。
您说:(2010-12-01 16:36:02)
上个月存了100,发现扣了90 但是无法上网
akweb009说:(2010-12-01 16:36:27)
麻烦您提供一下户名、地址,需要核实下,好吗?
您说:(2010-12-01 16:36:39)
哦 <strong>**</strong>*
您说:(2010-12-01 16:36:59)
是不是什么八位初始密码啊?
您说:(2010-12-01 16:39:07)
?
akweb009说:(2010-12-01 16:40:20)
非常抱歉,目前系统繁忙,让您久等了。
akweb009说:(2010-12-01 16:41:05)
校园宽带余额我处查询不到的 麻烦您自行查询下
akweb009说:(2010-12-01 16:41:15)
我处为您刷新了一下 建议您重启电脑试一下
您说:(2010-12-01 16:41:22)
还是这个密码吗?
您说:(2010-12-01 16:41:38)
初始密码是什么?
akweb009说:(2010-12-01 16:43:37)
是您宽带上网密码
akweb009说:(2010-12-01 16:43:50)
我处查询不到 抱歉 需要的话 可以拨打10000号查询下
您说:(2010-12-01 16:43:57)
哦。。</p>
</blockquote>
OhLife——在线日记本
2010-11-17T16:08:59+00:00
http://greenmooon55.com/ohlife-the-easiest-way-to-write-your-life-story
<p>很想记日记吧,坚持不下去吧?貌似我就幼儿园不会写字的时候真正给自己写过日记。
<a href="http://greenmoon55.com/wp-content/uploads/2010/11/20101117233643991.png"><img src="http://greenmoon55.com/wp-content/uploads/2010/11/20101117233643991.png" alt="" /></a>
自从用了OhLife,从11月5号到现在一天都没落过。为啥这东西这么神奇呢?它会每晚八点(可以调整)给你发一封邮件,回复这封邮件就会把你的日记发到网站上。每晚将近十一点查邮箱的时候我就会顺手回复几句。可以回复邮件多次,还可以添加图片附件。尽管有Twitter、人人、QQ空间等等等等,还是需要一个私人空间吧~</p>
<p>默认的在邮件里包含以前的日记,正好一周前的,看着很爽。在网站上还可以添加图片、修改日记。(个人觉得不实用。。)</p>
<p>国外的服务应该比较靠谱吧,还可以随时export成txt,经测试,中文无乱码,可放心使用^_^</p>
<p>网址还是留一下吧。。<a href="http://ohlife.com/">http://ohlife.com/</a></p>
<p>Have a nice day!</p>
南京路走回本部
2010-10-31T10:13:49+00:00
http://greenmooon55.com/walking-nanjing-road-to-tongji-university
<p>10月30号。</p>
<p>早上阳光明媚,怎能宿舍宅,果断出去~没坐过公交去市中心呢,于是买杯咖啡去坐123,等了两趟,貌似十分钟才一趟,还没座= =没吃早饭,于是到福州路都要吐了= =</p>
<p>中午果断继续去南京路地下的那家麦当劳去吃,居然差点没座。。以前去好几次人都很少的嘛。本人突发奇想,想着以前最多走过13KM,反正下午没啥事,走回学校怎么样?可惜手机电量不多,没敢开RunKeeper,否则肯定破纪录了。</p>
<p><a href="http://maps.google.com.hk/maps?f=d&source=embed&saddr=%E4%B8%AD%E5%9B%BD%E4%B8%8A%E6%B5%B7%E5%B8%82%E9%BB%84%E6%B5%A6%E5%8C%BA%E5%8D%97%E4%BA%AC%E4%B8%9C%E8%B7%AF588%E5%8F%B7+(%E9%BA%A6%E5%BD%93%E5%8A%B3%E5%8D%97%E4%BA%AC%E4%B8%9C%E8%B7%AF%E5%BA%97)&daddr=31.24538004341833,121.49137984961271+to:31.245981137254372,121.49141538888216+to:31.24827741233756,121.49330299347639+to:31.25570989787114,121.49327985942364+to:%E6%9C%AA%E7%9F%A5%E9%81%93%E8%B7%AF&hl=zh-CN&geocode=FQmf3AEd0p89ByHhXletWoHHAQ%3BFUTE3AEdtM89BykDVGuBVXCyNTG0urhhN19dkw%3BFZ3G3AEd1889BymBc0KG_3CyNTHNNl0vRlWPvw%3BFZXP3AEdNtc9BynjcIdBAHGyNTGJzKLURzYxlA%3BFZ7s3AEdINc9Byk7NeKlB3GyNTEFAhzLxCy1yg%3BFTJY3QEd6gI-Bw&mra=mrv&mrcr=0&via=1,2,3,4&dirflg=w&sll=31.238435,121.488984&sspn=0.009302,0.01929&brcurrent=3,0x0:0x0,1&ie=UTF8&ll=31.251259,121.49497&spn=0.025682,0.036478&z=14">查看大图</a></p>
<p>弯弯绕绕地走回来,7公里大约用了1小时57分,照了点照片~其实走到天宝路一直不拐弯觉得有点烦了= =回四平路正好就是浦发银行,顺路取点钱~
[gallery link=”file” columns=”3”]</p>
地铁志愿者
2010-10-23T16:59:35+00:00
http://greenmooon55.com/shanghai-metro-volunteer
<p>招募贴:<a href="http://club.metrofans.sh.cn/thread-137143-1-1.html">http://club.metrofans.sh.cn/thread-137143-1-1.html</a>
图片贴:<a href="http://club.metrofans.sh.cn/thread-138494-1-1.html">http://club.metrofans.sh.cn/thread-138494-1-1.html</a></p>
<p>第一次当志愿者,先去买伞。5点五十地铁,十五分钟到南京东路,疯狂走到南京路地下的那家麦当劳(人少,而且有豆瓣<a href="http://www.douban.com/minisite/imlovinshanghai/">麦当劳我就喜欢上海</a>的照片~)差不多五分钟吃完,跑到人广还是已经18:40了,说18:30点名,结果到七点才签到的,还看了下我的身份证。。</p>
<p>[caption id=”attachment_241” align=”alignnone” width=”600” caption=”等人中。。”]<a href="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3112.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3112-600x450.jpg" alt="" /></a>[/caption]</p>
<p>[caption id=”attachment_245” align=”alignnone” width=”450” caption=”地铁世博会志愿者?”]<a href="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3117.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3117-450x600.jpg" alt="" /></a>[/caption]</p>
<p>[caption id=”attachment_244” align=”alignnone” width=”600” caption=”太!傻!了!。。好久没人给我拍照了- -本图由周瑜的地铁拍摄”]<a href="http://greenmoon55.com/wp-content/uploads/2010/10/IMG_6197.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/IMG_6197-600x400.jpg" alt="" /></a>[/caption]</p>
<p>七点,穿上地铁志愿者的红衣服,把包和伞扔到某控制室里就开始“工作”了。。俺被安排在八号线上面,问的最多的是南京路、外滩咋走,左边19号口。好多人都是去外滩结果在人广就下了,应该到南京东路的。还有不少人问来福士广场怎么走,右边15号口。稍微复杂点的我都给别人处理了。。我吃了蛋糕,拿到了1瓶矿泉水+可乐+coco奶茶(终于明白为啥上海人都排队买奶茶了。。真好喝)+某小蛋糕(似乎是85度C的)。。他们几个人都在聊,都用上海话,我就像个外国人,一直在打酱油。。我原以为最大的问题是人们不知道单程票要回收,后来才知道是插卡有时插不进去。</p>
<p>某位是同济学长,04年的,学土木还建筑来着我忘记了,结果最后跑到地铁去了。。说交大最好(废话!)同济不如上财比武大“差多了”。。我觉得就是他自己没混好。。说CS一般般,这个倒是吧。。还是靠自己吧= =<del>明天</del>今天乖乖学习去。呃,还有个上大刚毕业的也第一次来,好像是做财务的。</p>
<p>后来还遇到特殊情况,某人在8号线南侧(是吧?)厕所附近倒在地上,神志不清,后来有员工来把他放轮椅上无障碍电梯送上去了。回来和那位学长一起走的,他到虹口足球场,他说8号线的车那时候都去世博了。。难怪往南的车那么多。</p>
A Happy Day~
2010-10-21T14:53:35+00:00
http://greenmooon55.com/a-happy-day
<p>每次打开后台都不想写东西了,sigh~今天还是写点吧
今天很爽,早上睡到9点半,宿舍宅一上午,就读了几分钟左右英语。。没干啥。下午思修不错,老师自言自语到三点。看天气不错就回来拿相机到处拍拍。
吃完面5点半到音乐广场,本来没餐券只想围观下,问了下发节目单的某位姐姐,居然就这么拿到餐券了^_^排了半小时就排到了,跑到大学生活动中心吃了某种饭+美年达!突然发现每天都放新闻联播的大屏幕居然在放电影!!!A Beautiful Mind,我听说过这个名字于是就看了会,实在是很冷啊。。回来发现居然豆瓣评分8.8,IMDB8.0。如此高的评分~看了一半,七点十五跑掉去王小慧工作室参加摄影协会活动,发现根本不是一个水平,似乎只有咱用卡片。。回来去图书馆借书学摄影- -。
恩,最像大学生活的一天~
好图:(<strong>这是校内不是世博会!!</strong>图片的title是介绍哦)
<a href="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3083.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3083-600x450.jpg" alt="" /></a></p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3082.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3082-600x450.jpg" alt="" /></a></p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3081.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3081-600x450.jpg" alt="" /></a></p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3080.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3080-600x450.jpg" alt="" /></a><a href="http://greenmoon55.com/a-happy-day/dscf3078/"></a></p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3078.jpg"><img src="http://greenmoon55.com/wp-content/uploads/2010/10/DSCF3078-600x450.jpg" alt="" /></a></p>
100924
2010-09-24T13:39:20+00:00
http://greenmooon55.com/100924
<p>本来想来图书馆写篇日志,到了又什么都不想写了。</p>
<p>对以前的中秋完全没印象,这次中秋三天最不爽就是没吃到五仁月饼。。。昨天在大润发买了鲜肉月饼,吃的时候才想起来这不就是火勺嘛。。杯具。发现上海也有桃李哇,原来是全国都有,和吉林、青岛一样。</p>
<p>上海天气变化真快,周二穿短袖浑身都是汗,周三冻得浑身发抖,昨天必须穿长袖,今天又能穿短袖了。。今天下午在图书馆看 The Story of Mankind,几个小时才读完前言,不认识的词写了好多页呢。。英语压力很大= = 明天起连上三天高数,不过自由时间很多,无压力~</p>
<p>似乎今天抢到了图书馆和西北食堂+西北四的mayor。。看来没多少人玩这个。twigee刷推不全,哪天换个软件弄弄。估计要自己修改了。。手机每月300M流量估计不够用啊。刷推和4sq很费流量的。。</p>
<p>没什么,对门宿舍昨天三国杀很久,似乎很复杂,以后慢慢学吧。看起来每天空闲时间很多,其实有很多事情可以做呢。</p>
<p>昨晚来下了17篇关于长吉城际和吉林市的论文,看了几篇,直接用公式算人数靠谱吗?而且某个硕士(or 博士)论文真是废话连篇,完全凑字数。PS:免费下载真爽!!哈哈</p>
<p>当当买了本英语阅读教程4的讲义,加运费比原价都贵。。估计外面不好买,今天下午发货,估计明天就能到了吧~</p>
<p>图书馆的电脑似乎可能有病毒啊,以后不敢这么登录blog了。。</p>
100918
2010-09-18T13:31:02+00:00
http://greenmooon55.com/100918
<p>第一周上课,课程内容还成吧。。高数得好好预习+复习,第二次高数我没预习于是就悲剧掉了。似乎我们学高数A,软院学B。。</p>
<p>原来同济离复旦这么近,今天147到大润发,然后走回到复旦这边,这里书店真多,一两公里内将近十个了。。买杂志、文史、英语、参考书都去那里好了。。晚饭吃了步行街上的鸡蛋灌饼,正常2块,比吉林小点。还吃了旁边的兰州拉面6块钱一大碗,肉还不少。和吉林二中4块的差不多~超值啊。</p>
<p>今天第一次连上CMCC-EDU。速度时快时慢,比图书馆无线慢点。。不过平时肯定是连不上的。青岛的舍友准备买本了,看来十月十一月有希望在宿舍上网了,其实学校电子阅览室也很爽的,屏幕大网速快还免费,主要是要排队= =</p>
<p>今晚刚班级聚会完,不会唱歌很悲剧- - 发现两位MM,一位咱东北沈阳的,另一位江苏的。这记性啊,问完名字不到1分钟就忘了。。旁边教室上自习的同学情何以堪!</p>
<p>iPad发售了?最近不看新闻不买杂志啥都不知道,陆家嘴的水果店还没去过呢,又一次都坐到2号线那站了,发现没带相机又回学校了。</p>
<p>英语老师(一个老师教4个,其中一个我们专业的还是师大附中的)布置:大学英语四级阅读+原版书 The Story of Mankind(借到图书馆最后一本双语版,还没看呢。网上查的位置,找了好久好久),电影 Front of the Class (估计没法下。。图书馆刚试过下不到,网吧10KB/S的速度不现实,呃难道明早去网吧下?)</p>
<p>现在,旁边某同学说中意班报的人少,选上了。反正咱没报,CS还是米国好吧。。</p>
<p>今天群里有人问有没有会NOIP的,聊了会,后来他给我个号。川大网站做题,某ACM预选赛。。第一题应该是DP,显然现在写不出来- - 争取以后去学ACM。</p>
<p>这里还是很习惯的,三月(or 4月?)来过上海,基本结构(!)很熟悉,现在气候也不错,还是和咱最热的时候差不多,整天短袖短裤还可以。</p>
<p>装上同济免费的 Office 2010 x86,还没激活也没提醒激活。。移动无线不行,哪天来图书馆无线试试~ MS Office 就是比 WPS 强,真是没的说。打击盗版,国产软件还要加油啊。</p>
<p>牛人很多哇。。团学联技术与宣传部(技宣部)会啥的都有啊。PS、画画、3ds Max、Dreamweaver、Flash、ASP.NET、OI(有人穿OIBH Monthly来),就我一个打酱油的。。随便在网上加了个 Google Camp,俺要去谷歌上海转转^_^。英语Top65班压力也很大,以后再加上ACM太忙的话,我就退掉团学联好了。。</p>
<p>最近好乱。。一部分发到推上,一部分写blog上好了~</p>
第一周碎碎念
2010-09-10T23:42:18+00:00
http://greenmooon55.com/first-week-in-shanghai
<p>还好还好了,温度还可以接受,宿舍有电扇。只是各种活动比较乱。。上网不方便,室友都不上。。只好去图书馆了= =无线很抽风。</p>
<p>Milestone装了百度输入法(谁叫它有双拼!)、Twigee、QQ for Android、点评(似乎只能看,不能评)、手机人人网。能收gmail还不错~66块300M现在好像用了72M。</p>
<p>为嘛我这么幸运呢。。。英语居然全部免修免试(考的是四级题,全校60个),昨晚随便说说就进团学联了(Q:会不会XXXX?A:不会,但我会努力很快学会。。。)</p>
<p>有没有ACM啥的玩玩?大一课表似乎很轻松,周二单周全天只有体育、周四上午没课。一三五忙、二四松。不过据说高数啥的很难。。而且老师特意提了保送生会很困难- - 我本来选了节嘉定的课玩玩,结果后来才说不行。。</p>
<p>十号线很棒,没人坐,空调足。图书馆很大,很凉快~</p>
<p>下周开始上课了,加油加油!</p>
<h1 id="唉本来我就写不好作文现在不会写140字以上的段落了">唉,本来我就写不好作文,现在不会写140字以上的段落了。。</h1>
<p>饿 对了 我还没打过开水呢。。很远。现在适应冷水澡了,因为花钱的热水浴室太远了,在热水房旁边。。似乎需要个自行车,可是我不会骑唉。今天起得太早,5点多就起了,现在很困 Q_Q
==
我要上网。。我要看F1,晚上在网吧看?哪里有电视?想看五星体育的~明天或许混去当志愿者免费看o(∩_∩)o 哈哈
==
我本来觉得我睡得算晚的,结果。。我都很困了别人都不睡,一般都到12点以后。估计开学11点断电就好了。。图书馆开到10点呢。
==
不知道周末都要去哪里,要是去世博我就去网吧好了。。中国馆我排30分钟都觉得不值,台北案例馆性价比很高的,城市实践区人很少,日本馆晚上不看表演很没意思。
==
要不以后转去软院?至少比我们强。。不过似乎很难很难。。(刚看到学长说要4.5+开源项目。。)第一目标就是顺利毕业。</p>
上海第一天
2010-09-01T14:46:47+00:00
http://greenmooon55.com/first-day-in-shanghai
<p>我妈开车走G12去的机场,本来想在车上睡一觉的。。她有一次超车把转向灯都打反了。。</p>
<p>提前一个多小时到的机场,不出所料晚点了。安检的时候把勺子(居然有勺子!)都翻出来了。。登机前又说人满了,行李最好托运,再包里翻了半天相机电池。。</p>
<p>晚到1点多起飞,看到长春了!看到南湖了!可能还看到四平或铁岭,杭州湾跨海大桥。(图片过几天再传。)起飞后晃了很久,不舒服,过了一小时才平稳的,从飞机上看海面很平静,不过上海天上都是乌云,降落后地面上都是水、飘白烟,很吓人。4点到PVG,机场真大,地面像地毯,很豪华。后来2号线换2号线换10号线回来的,基本上都有座(还好始发站啊,这可是上下班高峰哦)。7点多到旅馆,条件不错,网速相当快^_^不过同程网居然没定上明天的特价房。。</p>
<p>我对五角场沃尔玛很无语,“不仅东西都比吉林贵,买收音机都没人管、纯净水标价错,最后想买个雨伞,心里想着随便那一个吧,结果拿起来一看是坏的。” http://twitter.com/greenmoon55/status/22708514058</p>
<p>在犹豫明天是去买手机还是去SB会,两千的手机可不敢随便买啊。。</p>
再见吉林市
2010-08-31T14:24:41+00:00
http://greenmooon55.com/far-away-from-home
<p>很幸运去了同济。。明天就要走了,FM(MU)9180到浦东。</p>
<p>本来想做过很多事,比如学骑车、走遍吉林市(!!)、ACM(。。。)、背单词、甚至学琴(很想学可是从来没学过)、看电影。完成得都不怎么样。。吉林多好,冬天有暖气、夏天在家都不用开空调。Anyway,咱要走了。明天还台风,上海中小学都停课了,飞机可能<a href="http://finance.ifeng.com/roll/20100831/2573113.shtml">有影响</a>。。不过台风名字很好玩,叫“圆规”,数学老师起的?</p>
<p>感觉还没准备好就要走了,在家宅着也不错(最近很忙。。)。心态从高中转到大学还需要些时间,开始独立生活了~</p>
<p>哦对了,本来一志愿是SE,结果给分到CS了,好像很多人都是。以前想尽量转专业,某天群里大家报英语分,都130、140- - 我就么想法了。。做吉林卷(新课标)英语除听力、作文扣7.5,上海卷至少要扣22。。最强的科目只能和别人差不多,而且还被分到四级。。还好大学不用学化学、生物,好像也没语文^_^</p>
<p>计划:
9.1 晚上世博,昨天27万人,今天才20万。不过飞机晚点就够呛了,而且我还没查攻略。。
9.2 上午去<a href="http://bbs.tongji.net/viewthread.php?tid=301621">不夜城</a>买Milestone,下午继续世博
9.3 可以去宿舍了,有时间就买收音机等东西
9.4 报道
9.5 同省见面会(。。同校都不认识呢)+考试
…</p>
<p>现在已经有点困了,过会就洗洗睡了~
Update @ 2010/8/31 22:36 FM9180最近晚点情况,平均晚点85.07分。点<a href="https://spreadsheets.google.com/ccc?key=0AvoDx50Pnzz_dGlKZ1J2MjBPeWo2Y2xuZGNqV2RtdHc&hl=zh_CN">这里</a>看(墙外)</p>
Dell Inspiron 1420 Drivers for Windows 7 x64
2010-08-15T02:43:14+00:00
http://greenmooon55.com/dell-inspiron-1420-drivers-for-windows-7-x64
<p>俺的1420配置完全可以装win7,所以刚买不久时就装了~
分享下驱动:</p>
<p>好像不装声卡驱动就没声,SIGMATEL STAC 92XX C-Major HD Audio,下载:<a href="http://support.dell.com/support/downloads/download.aspx?c=us&l=en&s=gen&releaseid=R171789&SystemID=XPS_M1710&os=WW1&osl=en&deviceid=8907&devlib=0&typecnt=0&vercnt=3&catid=-1&impid=-1&formatcnt=1&libid=3&fileid=235761">R171789</a>
显卡驱动(我的是8400M GS)<a href="http://support.us.dell.com/support/downloads/download.aspx?c=us&l=en&s=gen&releaseid=R180917&formatcnt=0&libid=0&typeid=-1&dateid=-1&formatid=-1&source=-1&fileid=246679">R180917</a> 当然这个好像有点老,最新的可以去 <a href="http://www.nvidia.cn">http://www.nvidia.cn</a> 下载
如果觉得电脑没什么问题,但设备管理器里有个硬件没有驱动,可以考虑装一下这个试试。Ricoh R5C847 (<a href="http://support.dell.com/support/downloads/download.aspx?c=us&l=en&s=gen&releaseid=R230630&SystemID=LAT_E6400&servicetag=&os=W764%20&osl=en&deviceid=16426&devlib=0&typecnt=0&vercnt=1&catid=-1&impid=-1&formatcnt=0&libid=27&typeid=-1&dateid=-1&formatid=-1&source=-1&fileid=331575">R230630</a>)
注意到键盘上那些蓝色的功能键吗?是不是一直不能用?装这个吧!只要同时按下Fn就行。Dell QuickSet (<a href="http://support.dell.com/support/downloads/download.aspx?c=us&l=en&s=gen&releaseid=R233340&SystemID=STUDIOXPS1645&servicetag=&os=W764%20&osl=en&deviceid=2861&devlib=0&typecnt=0&vercnt=1&catid=-1&impid=-1&formatcnt=0&libid=25&typeid=-1&dateid=-1&formatid=-1&source=-1&fileid=335801">R233340</a>) 键盘调音量时也会有显示哦~</p>
<p>嗯,就这些了。具体配置可能不同,但应该没啥问题吧。</p>
<p>PS:前几天去电脑城陪同学看本,还是觉得咱的1420好看,还能调音量呢。当时老妈自己去买的,真有眼光。。</p>
<p><strong>Update @ 22:13 2010/8/21</strong> 推荐Win7 主题:<strong>Bing’s Best: Japan</strong> 日本好漂亮~。<a href="http://windows.microsoft.com/en-us/windows/downloads/personalize/themes">这里</a>找吧,好多呢。
<strong>Update @ 15:02 2010/8/24</strong> 再推荐点。。两个Win 7 Widget。一个叫<a href="http://gallery.live.com/liveItemDetail.aspx?li=b0c66300-f33d-4625-a05e-5bbf66f583d8&bt=1&pl=1"><strong>uuRadio</strong></a>,用来听<a href="http://www.911pop.com/">青檬</a>很爽,就是有时候有点卡。还有个天气小工具<strong><a href="http://gallery.live.com/liveItemDetail.aspx?li=77ad820a-2b64-408f-a92f-2c6c71b8ec37&bt=1">MSN Weather 2.0</a></strong>,界面很漂亮。</p>
Partition Wizard 硬盘分区管理软件
2010-08-08T14:33:27+00:00
http://greenmooon55.com/partition-wizard
<p>很多时候需要调整分区大小,比如:刚买的本分区不合理,东西下多了导致某个分区没空间了。而这方面的软件不多,支持Windows 7 <strong>x64</strong>的<strong>免费</strong>分区调整软件就更少了。</p>
<p>晚上试用了一下,删除了一个分区,后面的分区盘符不变,还调整了两个分区的大小。所有操作都<strong>不需重启</strong>,就是慢了点。。</p>
<p>Home Edition 是免费的,功能比较完整,与 Professional 相比只缺合并分区的功能,自己复制粘贴就行了~</p>
<p><strong>注意:调整分区大小前请看此<a href="http://www.partitionwizard.com/video-help/moveresizepartition/moveresizepartition.html">视频</a>,要注意减小分区时向前释放空间还是向后!</strong></p>
<p>官网:http://www.partitionwizard.com/ 有很多<a href="http://www.partitionwizard.com/support.html">帮助视频</a>,还提供email支持。</p>
<p><strong>最后友情提醒:虽然一般情况下很安全,重要数据请备份。</strong></p>
<p>PS:软件字体比较大,不方便截图,算了算了。其实<a href="http://www.appinn.com/">小众软件</a>很久以前就<a href="http://www.appinn.com/partition-wizard-home-edition/">介绍</a>过了。。</p>
吉林市洪水图片
2010-07-28T16:38:32+00:00
http://greenmooon55.com/flooding-in-jilin
<p>本作品采用<a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/">知识共享<strong>署名</strong>-非商业性使用-相同方式共享 2.5 中国大陆许可协议</a>进行许可。</p>
<p>懒得传到这里,还占流量(这里有人看吗=.=)。
Flickr原图均为1024*768(非Pro帐号不支持更大的T_T),不过拍得不怎么样。。中国大陆部分ISP(比如吉林联通)可能不能正常看部分图片。</p>
<p><strong>江水已至台阶</strong>
<a href="http://www.flickr.com/photos/greenmoon55/4838057832/"><img src="http://farm5.static.flickr.com/4091/4838057832_fe11f62be2_z.jpg" alt="江水已至台阶" /></a></p>
<p><strong>温德桥、一中前</strong>
温德桥已冲垮,水已经到这里了?!我面前是警戒线。
后来回家才知道,原来水都进鸿博锦绣了。。
后来从临江门桥墩可以看出水位稍有下降。
<a href="http://www.flickr.com/photos/greenmoon55/4838057870/"><img src="http://farm5.static.flickr.com/4107/4838057870_fb4374a43b_z.jpg" alt="温德桥、一中前" /></a></p>
<p><strong>回不去家的人</strong>
因为温德桥已冲垮,这些人估计都会不了家了,除非绕很远。
话说苏宁天润城的住户真悲剧。。
<a href="http://www.flickr.com/photos/greenmoon55/4838057882/"><img src="http://farm5.static.flickr.com/4125/4838057882_8a954a24c9_z.jpg" alt="回不去家的人" /></a></p>
<p><strong>健身器材也被淹了</strong>
临江门大桥西北角
<a href="http://www.flickr.com/photos/greenmoon55/4838057892/"><img src="http://farm5.static.flickr.com/4088/4838057892_894c522fe9_z.jpg" alt="健身器材也被淹了" /></a></p>
<p><strong>装化学品的蓝罐</strong>
<a href="http://www.flickr.com/photos/greenmoon55/4838057904/"><img src="http://farm5.static.flickr.com/4091/4838057904_f55b0d40a9_z.jpg" alt="装化学品的蓝罐" /></a></p>
<p><strong>第二头猪</strong>
活着呢~
第一头也照了,不过它藏着看不清。
<a href="http://www.flickr.com/photos/greenmoon55/4838057922/"><img src="http://farm5.static.flickr.com/4113/4838057922_2fe828d4dc_z.jpg" alt="第二头猪" /></a></p>
<p><strong>临江门大桥,江水稍有下降</strong>
看桥墩。人不少吧~
<a href="http://www.flickr.com/photos/greenmoon55/4837484259/"><img src="http://farm5.static.flickr.com/4129/4837484259_f6d87c13e3_z.jpg" alt="临江门大桥,江水稍有下降" /></a></p>
<p><strong>奇异的云彩</strong>
松江东路
乱拍的。。没拍好。
用了Picasa的“手气不错”
<a href="http://www.flickr.com/photos/greenmoon55/4837482391/"><img src="http://farm5.static.flickr.com/4126/4837482391_56756ed6b3_z.jpg" alt="奇异的云彩" /></a></p>
<p>http://news.qq.com/a/20100728/002312.htm
此新华网原稿曾经删除后来又出现了?配的视频很好玩,<strong>主持人错误:“黄浦江”</strong>。。吉林市没有黄浦江。<strong>省环保局副厅长错误:“下游的长春地区…”</strong>松花江不经过长春。。</p>
<p>我家附近的水都没了,后来在一中附近的锦绣超市买了几瓶两块、两块五的某水,没喝过~
谁知道现在的江水有没有问题,我觉得问题不大~先喝存的水吧。</p>
<p>呃对了,晚上吉林大桥已封闭,松江东路有人买娃哈哈矿泉水,24瓶40块。晚上回家网速很慢,甚至比拨号都慢,网页都打不开。传晚上泄洪,不过有图片看起来水已经退到健身器材以下了。
——
RT@xiaolai 南京工厂爆炸、吉林水源污染,成都火车故障。今天真乱。<a href="https://twitter.com/xiaolai/status/19732369065">https://twitter.com/xiaolai/status/19732369065</a>
推荐这个:<a href="https://docs.google.com/View?id=dgtbmwd6_1066csss7khm">哪个让你直播的——南京工厂爆炸事件媒体参考</a></p>
火场逃生记
2010-07-17T14:10:36+00:00
http://greenmooon55.com/escaped-from-a-fire
<p><strong>Update @ 22:21 2010/7/17 标题党了@_@其实没那么严重</strong></p>
<p>准备好了7点的FZOC联赛,正和Kidd_Allen聊天,突然楼下有声音,好像也有烟味,赶紧去窗户看,说着火了。(后来知道是一楼右门,我家在二楼左门)</p>
<blockquote>
</blockquote>
<blockquote>
<p>[ 2010-07-17 ]</p>
</blockquote>
<blockquote>
<p>Allen 18:40:28
有F练练么?</p>
<p>greenmoon55 18:41:23
- -
【提示:greenmoon55(254320526)正在使用WebQQ:http://web.qq.com/?w】</p>
<p>greenmoon55 18:41:33
13圈爆引擎。。。</p>
<p>Allen 18:41:53
。。。</p>
<p>greenmoon55 18:41:55
一停好像油不够
greenmoon55 18:42:03
Q跑两圈成绩
Allen 18:42:05
你开多少通风
greenmoon55 18:42:09
5
Allen 18:42:11
Q跑1圈够
greenmoon55 18:42:21
一直开5的 从来没爆过
greenmoon55 18:42:26
你几停?
Allen 18:42:36
1 停
greenmoon55 18:42:49
下午刷圈 带三圈油 跑到1:31.5了
Allen 18:43:00
哇,不错唉
Allen 18:43:09
我最多也就这样了。。。
greenmoon55 18:43:21
比赛速度大约1:34/35 等到油少了轮胎也不行了。。
Allen 18:43:57
不错,有竞争力
greenmoon55 18:44:18
没试这个调教 呢
greenmoon55 18:44:41
擦 楼下着火了 119来了
Allen 18:44:41
还是别用了
Allen 18:44:54
习惯你自己的TJ就可以了
greenmoon55 18:45:08
离我家20米。。
greenmoon55 18:45:15
全是烟
greenmoon55 18:45:17
88
Allen 18:45:38
。。
greenmoon55 19:14:24
我回来啦
【提示:greenmoon55(254320526)正在使用 WebQQ:http://web.qq.com/?w】
Allen 19:14:38
快
greenmoon55 19:14:52
吓死了。。
Allen 19:16:36
没事吧
greenmoon55 19:17:24
再说吧 我妈去问能不能用电了。。
Allen 19:17:38
晕
greenmoon55 19:55:50
没事了。。</p>
</blockquote>
<p>后来说要撤,于是赶紧行动,断电源,关笔记本。想过要不要带笔记本,决定不拿。赶快去穿短裤和T恤,想了下这个T恤是校服,不好看。。。没穿袜子直接开门穿鞋,发现楼道里有烟了,听到关门声,知道有人也往下跑。跑了几步,吸了几口天然气,感觉有点晕了,赶紧捏着鼻子狂奔出门,还好在2楼。。这要是三楼四楼很可能跑不出去了。。我妈慢了,没跑出去。</p>
<p>外面围了有一百人吧,刚出去消防车就到了,有消防员戴上面具进去了,水管真长啊!!可能是为了尽快使天然气扩散,有消防员打碎了屋内的玻璃。据说最开始有人帮忙用灭火器喷了,所以消防员很快结束战斗。围观群众中有个老头还那个DV摄像..看起来像六十多的。后来消防员用数码相机照了那个破碎的玻璃,难道要赔钱?消防员告诉该住户今晚不要在家住,他屋内还有很多烟雾,楼道也有点。</p>
<p>回到屋里,老妈说有消防员进屋告诉他不要开北侧的窗户,要开南侧的通风,不要贸然下楼。后来老妈下楼去问了,据说起火原因是做饭油在锅里,人出去了,结果就这样了。。。万幸的是当时爷爷奶奶出去散步了,否则他们得急死。。</p>
<p>警示:着火时不能着急出去,特别是楼层高的时候,当时二楼烟不浓,一楼却很浓。我和对门孩子都跑出去了,家长都在家里呢。</p>
<p>PS:今天RP真低。。早上八点被人喊出去搬家,下午着火,玩F1好不容易排位第二(!!!要知道我是用默认调教的,随便改了改变速箱而已),正赛也超到第二了,结果正好没油的时候出SC,进站被罚Drive Through,然后又掉线。。。本来可以第二的!!!</p>
<p>我见过身边的火灾,比如初中时住的地方对面楼,自己单元的火灾可是第一次见。多掌握紧急情况的处理办法吧。。</p>
三花
2010-07-10T17:01:34+00:00
http://greenmooon55.com/%e4%b8%89%e8%8a%b1
<p>吃狗吃猫本来没有什么问题,把别人家养的宠物偷来卖给餐馆就不对了。我吃过几次狗肉,很好吃的。说双汇里放猫肉,谁知道真假。。吃吧吃吧,最近超市特价还买个好几个呢,三鹿蒙牛都放<a href="http://news.163.com/10/0708/21/6B3OLIGL000146BC.html">三聚氰胺</a>呢= = (from <a href="https://twitter.com/greenmoon55/status/17948118088">my tweet</a>)</p>
<p>几乎每个行业都有黑幕,榨取利润时,人们既是迫害者也是受害者。维权被捕,官员复出,食品安全从何谈起?
片中这样的派出所所长在这个国家是可以当下去的,还有什么可说的。
做人尽量做到“不作恶”吧,从自己做起。不能说真话就要尽量不说假话。</p>
<p>ed2k链接:
<a href="ed2k://|file|%E4%B8%89%E8%8A%B1.m4v|474984898|0AA32E4BC33C7CC6B9EFE12A1BCA9F59|h=NRDQM5UEKRIQ63MRRHLPPLB63ZCCO6UK|/">ed2k://|file|%E4%B8%89%E8%8A%B1.m4v|474984898|0AA32E4BC33C7CC6B9EFE12A1BCA9F59|h=NRDQM5UEKRIQ63MRRHLPPLB63ZCCO6UK|/</a></p>
<p>其他下载地址(Google Buzz):<a href="https://www.google.com/buzz/106372800511710859472/JQJrPnKWaJ9/">https://www.google.com/buzz/106372800511710859472/JQJrPnKWaJ9/</a></p>
OFRL2010加拿大
2010-06-12T15:40:04+00:00
http://greenmooon55.com/ofrl-2010-gp-canada
<p><a href="http://greenmoon55.com/ofrl-2010-gp-canada/grab_001/"><img src="http://greenmoon55.com/wp-content/uploads/2010/06/GRAB_001-600x336.jpg" alt="" /></a></p>
<p>今晚玩了加拿大站,第三名冲过终点线,很神奇。</p>
<p>排位好像是五六名,发车在外线,没有遇到什么事故,几个事故车超过后又被追回来了。后来前是25,5s后是Allen的时候撞了,还好没什么事,Allen迅速接近,本来想让他过的,结果他spin了。。</p>
<p>虽然显示最多12圈,但实际上能跑14圈,最后剩5L左右,因此选择一停。进站时感觉刹车不行了,当时觉得很诧异,break duct size我选的是6啊,难道和撞车有关?</p>
<p>出站刹车失灵,压到黄线,当时都想退赛了。后来慢慢坚持,还在最后一弯没刹住撞墙,又回去修了14S,N多人都退赛了,最后一弯我被第4的追到,还好没超过去。当时非常兴奋!!</p>
<p>Taomi表示:
1 对于压黄线,因为没有影响最终结果所以不罚,但是<a href="http://www.ourfmst.cn/thread-458-1-1.html">规则</a>明明写着</p>
<blockquote>
<p>3.3.对于“跨越维修站出口分道线的定义”:以赛车靠近比赛路面一侧轮胎为基准,此侧前轮已经越过维修站出口分道线,使部分车体占用到了主比赛路面,车手甚至将赛车直接行驶到主比赛路面。
处罚:当场比赛时间加罚10-30秒</p>
</blockquote>
<p>2 由于最后过终点线后直接ESC退出,我成了第4,在规则中没找到这条,更不用说详细的处罚规定了。</p>
<p>规则中甚至规定了安全车,但是比赛中从来没看到过安全车出动,服务器甚至不会弄。
“<a href="http://www.ourfmst.cn/thread-895-1-1.html">Coca-Cola投诉SWT车手schumi_1-sa</a>”,1sa被罚30秒,有处罚依据,但没有具体标准。</p>
<p><strong>对于既然规则不能认真执行,那还制定什么?</strong></p>
USACO Health Holsteins
2010-05-28T06:19:21+00:00
http://greenmooon55.com/usaco-health-holsteins
<p>简单题。。。DFS</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
PROB: holstein
LANG: C
*/</span>
<span class="cp">#include
#include
</span><span class="kt">int</span> <span class="n">temp</span><span class="p">[</span><span class="mi">26</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="n">bool</span> <span class="n">used</span><span class="p">[</span><span class="mi">16</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="kt">int</span> <span class="n">num</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">max</span><span class="o">=</span><span class="mi">999</span><span class="p">,</span><span class="n">v</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">min</span><span class="p">[</span><span class="mi">26</span><span class="p">],</span><span class="n">feed</span><span class="p">[</span><span class="mi">16</span><span class="p">][</span><span class="mi">26</span><span class="p">],</span><span class="n">ans</span><span class="p">[</span><span class="mi">16</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">;</span>
<span class="n">bool</span> <span class="n">ok</span><span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="o">></span><span class="n">g</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">v</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">temp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+=</span><span class="n">feed</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">i</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o"><</span><span class="n">min</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="n">ok</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">used</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="n">num</span><span class="o">++</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ok</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="o"><</span><span class="n">max</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">max</span><span class="o">=</span><span class="n">num</span><span class="p">;</span>
<span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="n">used</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">j</span><span class="o">++</span><span class="p">;</span>
<span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">used</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span>
<span class="n">num</span><span class="o">--</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">v</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">temp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-=</span><span class="n">feed</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">i</span><span class="p">];</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">work</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
<span class="n">used</span><span class="p">[</span><span class="n">n</span><span class="p">]</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span>
<span class="n">num</span><span class="o">--</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">v</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">temp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-=</span><span class="n">feed</span><span class="p">[</span><span class="n">n</span><span class="p">][</span><span class="n">i</span><span class="p">];</span>
<span class="n">work</span><span class="p">(</span><span class="n">n</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"holstein.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">,</span><span class="n">stdin</span><span class="p">);</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"holstein.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">,</span><span class="n">stdout</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">v</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">v</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">min</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">g</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">g</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">v</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">feed</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="n">work</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d "</span><span class="p">,</span><span class="n">max</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">max</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">printf</span><span class="p">(</span><span class="s">"%d "</span><span class="p">,</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">ans</span><span class="p">[</span><span class="n">max</span><span class="p">]);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
USACO Sorting a Three-Valued Sequence
2010-05-27T15:09:02+00:00
http://greenmooon55.com/usaco-sorting-a-three-valued-sequence
<p>自己的想法错了。。第六组过不去,后来参照<a href="http://oibh.org/bbs/viewthread.php?tid=10411&page=5#pid290439">OIBH</a>了。
可以这样理解,先把3放好,对于1、2位置,如果{1在2上,2在1上}互相交换即可,否则要和新换上的数字交换。。
比如:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>3
1
2
```
要交换两次。
```c
/*
ID: djgreen1
PROB: sort
LANG: C
*/
#include <stdio.h>
int max(int a, int b)
{
if (a>b) return a;
else return b;
}
int main()
{
freopen("sort3.in","r",stdin);
freopen("sort3.out","w",stdout);
int i,n,num[1002]={0},count[4]={0},ans[4]={0},end;
scanf("%d",&n;);
for (i=1;i<=n;i++)
{
scanf("%d",&num;[i]);
count[num[i]]++;
}
for (i=1;i<=count[1];i++)
{
if (num[i]==3)
{
ans[3]++;
continue;
}
if (num[i]==2) ans[2]++;
}
end=count[1]+count[2];
for (i=count[1]+1;i<=end;i++)
{
if (num[i]==3)
{
ans[3]++;
continue;
}
if (num[i]==1) ans[1]++;
}
printf("%d\n",ans[3]+max(ans[1],ans[2]));
fclose(stdin);
fclose(stdout);
return 0;
}
```
</code></pre></div></div>
USACO Ordered Fractions
2010-05-27T10:11:20+00:00
http://greenmooon55.com/usaco-ordered-fractions
<p>求值排序</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="cm">/*
ID:djgreen1
PROG:frac1
LANG:C
*/</span>
<span class="cp">#include
#include
</span><span class="k">struct</span> <span class="n">num</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">;</span>
<span class="kt">double</span> <span class="n">value</span><span class="p">;</span>
<span class="p">};</span>
<span class="n">bool</span> <span class="n">prime</span><span class="p">[</span><span class="mi">200</span><span class="p">];</span>
<span class="n">bool</span> <span class="nf">work</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">a</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="o">%</span><span class="n">i</span><span class="o">==</span><span class="mi">0</span><span class="o">&&</span><span class="n">b</span><span class="o">%</span><span class="n">i</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"frac1.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">,</span><span class="n">stdin</span><span class="p">);</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"frac1.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">,</span><span class="n">stdout</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">count</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">num</span> <span class="n">frac</span><span class="p">[</span><span class="mi">25600</span><span class="p">],</span><span class="n">temp</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">prime</span><span class="p">,</span><span class="nb">true</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">prime</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">160</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="mi">160</span><span class="o">/</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="o">*</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"0/1</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="o">==</span><span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"1/2</span><span class="se">\n</span><span class="s">1/1</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">count</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="c1">//generate all fractions
</span> <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">work</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">))</span> <span class="k">continue</span><span class="p">;</span> <span class="c1">//gcd
</span> <span class="n">count</span><span class="o">++</span><span class="p">;</span>
<span class="n">frac</span><span class="p">[</span><span class="n">count</span><span class="p">].</span><span class="n">a</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="n">frac</span><span class="p">[</span><span class="n">count</span><span class="p">].</span><span class="n">b</span><span class="o">=</span><span class="n">j</span><span class="p">;</span>
<span class="n">frac</span><span class="p">[</span><span class="n">count</span><span class="p">].</span><span class="n">value</span><span class="o">=</span><span class="p">(</span><span class="kt">double</span><span class="p">)</span><span class="n">i</span><span class="o">/</span><span class="p">(</span><span class="kt">double</span><span class="p">)</span><span class="n">j</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//sort
</span> <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">ifrac</span><span class="p">[</span><span class="n">j</span><span class="p">].</span><span class="n">value</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">temp</span><span class="o">=</span><span class="n">frac</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">frac</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">frac</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">frac</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">count</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d/%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">frac</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="p">,</span><span class="n">frac</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">b</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"1/1</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">stdin</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">stdout</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>有种方法很简单,根据</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>a/b<c/d==>a/b<(a+c)/(b+d)<c/d
```
(通分可证,更深奥的就不懂了- -!)USACO给的答案:
```c
/* print the fractions of denominator <= n between n1/d1 and n2/d2 */
void
genfrac(int n1, int d1, int n2, int d2)
{
if(d1+d2 > n) /* cut off recursion */
return;
genfrac(n1,d1, n1+n2,d1+d2);
fprintf(fout, "%d/%d\n", n1+n2, d1+d2);
genfrac(n1+n2,d1+d2, n2,d2);
}
}
```
</code></pre></div></div>
期待卡通赛车的再次开放
2010-05-21T14:13:38+00:00
http://greenmooon55.com/waiting-for-kart-online
<p>我曾写过<a href="http://greenmoon55.com/%E7%94%A8sandboxie%E6%AD%A3%E5%B8%B8%E7%8E%A9%E5%8D%A1%E9%80%9A%E8%B5%9B%E8%BD%A6/">用Sandboxie正常玩卡通赛车</a>,其实后来新浪更新了UT,支持Win7了。</p>
<p>2010年5月18日,新浪再一次更新,推出“视频游戏”,在<strong>没有提前告知</strong>的情况下(<a href="http://games.sina.com.cn/o/z/zngg/2010-05-12/1440372514.shtml"><strong>5月14日</strong>关闭金币充值</a>),原来的卡通赛车、野菜部落、飞行棋等等都停运了。</p>
<p>在<a href="http://greenmoon55.com/%E7%94%A8sandboxie%E6%AD%A3%E5%B8%B8%E7%8E%A9%E5%8D%A1%E9%80%9A%E8%B5%9B%E8%BD%A6/">用Sandboxie正常玩卡通赛车</a>我写了:</p>
<blockquote>
<p>igame里的飞行棋很好玩,igame连连看的背景音乐很好听,卡通赛车我从2005年玩到现在,野菜部落我做完了绝大部分任务。igame中用来买东西的金币可以通过挂银币得到,所以不用花RMB就能买很多东西。</p>
</blockquote>
<p>不过,现在网易新闻不错,新浪不愿管不赚钱的igame了。
野菜部落最后维护时间是2007年11月12日。
卡通赛车上次更新是<strong>2007年7月13日</strong>,曾经的服务器200人频道爆满好久不见了,曾经的组队跑圣诞1刷分也没有了。积分设置不合理,玩得钱越来越少。。虽然这样,还有很多忠诚的老玩家,甚至有<strong>日本人、韩国人</strong>。</p>
<p>卡通赛车可能是我玩的第一个网游。(2005-2010.5.18)
05年初买了新电脑,不再拨号,用上ADSL。下了igame发现的卡通赛车。5年半了。
游戏刚开始玩得比较多,后来一般只在假期玩。也没什么朋友,只对几个ID比较熟悉。<a href="http://bbs.games.sina.com.cn/thread-3285366-1-1.html">#</a></p>
<p>大批玩家在论坛里抱怨、与QQ客服沟通,可怜的客服只能公式化地回答。
<a href="http://greenmoon55.com/waiting-for-kart-online/attachment/20100521213830058/"><img src="http://greenmoon55.com/wp-content/uploads/2010/05/20100521213830058.png" alt="" /></a></p>
<p>有人向315电子消费投诉网<a href="http://www.315ts.net/archive/tousu/2010/0520/721354.shtml">投诉新浪</a>,提到了充值问题,这个方向不错嘛。新浪只是游戏关闭4天前停止金币充值,游戏关闭没有提前通知玩家。</p>
<p>资深玩家“小猫发飙”<a href="http://bbs.games.sina.com.cn/viewthread.php?tid=3285316&page=1#pid5818590">这样说</a>(在群里),我很赞同。他还提到,“玩家<飓风传说>要用5万元购买版本”。</飓风传说></p>
<p>今晚,我看到了新浪的补充说明。</p>
<blockquote>
<p>发表于 3 天前 22:20
[公告] 关于野菜部落、燃烧战车、升级等游戏的补充说明
本帖最后由 gm17777.cn 于 2010-5-21 12:57 编辑</p>
</blockquote>
<p>尊敬的各位玩家:</p>
<p>为了提供更好的用户体验,IGAME转型为视频棋牌平台,主要有:疯狂斗地主、火爆斗地主、疯狂双扣、牛牛、扎金花、德州扑克、五子棋、四国军旗、美式八球等20多款视频休闲游戏。另外我们深表遗憾的是IGAME平台原来的部分游戏目前将无法继续提供服务,我们会尽量和韩方及其它相关部门进行沟通,得到技术升级及开放允许,会尽最大努力进行沟通的,敬请大家谅解!</p>
<p>目前新平台还在调试中,稍后将陆续开放金币类游戏及FLASH游戏,同时新平台会有很多活动,相信会更加精彩,敬请期待!</p>
<p>新平台、新玩法、新朋友、新气象,希望大家继续支持IGAME游戏!
igame官方网站:http://www.17777.com</p>
<p>稍稍感觉好了点,毕竟还是有希望的。</p>
<p>我的建议:
1新浪不再开放银币换金币,让大家<strong>用RMB买道具</strong>,否则像以前那样赚不到钱啊。
2在首页、新闻频道<strong>红字推荐igame</strong>,现在顶部导航栏都没有链接,谁知道新浪还运营游戏啊?!</p>
<p>发点图吧
足球模式:
<a href="http://greenmoon55.com/waiting-for-kart-online/cracer_client-2009-01-16-22-39-51-45/"><img src="http://greenmoon55.com/wp-content/uploads/2010/05/CRacer_Client-2009-01-16-22-39-51-45.png" alt="足球模式" /></a></p>
<p>藏獒9进球了,高手:
<a href="http://greenmoon55.com/waiting-for-kart-online/cracer_client-2009-01-16-22-40-28-95/"><img src="http://greenmoon55.com/wp-content/uploads/2010/05/CRacer_Client-2009-01-16-22-40-28-95.png" alt="藏獒9进球了,高手" /></a></p>
<p>比赛开始,准备抢球╰( ̄▽ ̄)╭:
<a href="http://greenmoon55.com/waiting-for-kart-online/cracer_client-2009-01-16-22-46-55-21/"><img src="http://greenmoon55.com/wp-content/uploads/2010/05/CRacer_Client-2009-01-16-22-46-55-21.png" alt="比赛开始,准备抢球╰( ̄▽ ̄)╭" /></a></p>
<p>战斗模式:
<a href="http://greenmoon55.com/waiting-for-kart-online/cracer_client-2009-01-19-10-03-19-96/"><img src="http://greenmoon55.com/wp-content/uploads/2010/05/CRacer_Client-2009-01-19-10-03-19-96.png" alt="战斗模式" /></a></p>
<p>道具战,与其他游戏不同的是,只能赛前买好4个道具:
<a href="http://greenmoon55.com/waiting-for-kart-online/cracer_client-2009-01-19-10-45-05-62/"><img src="http://greenmoon55.com/wp-content/uploads/2010/05/CRacer_Client-2009-01-19-10-45-05-62.png" alt="道具战,与其他游戏不同的是,只能赛前买好4个道具" /></a></p>
<p>战斗模式游戏中:
<a href="http://greenmoon55.com/waiting-for-kart-online/cracer_client-2009-06-21-10-34-43-04/"><img src="http://greenmoon55.com/wp-content/uploads/2010/05/CRacer_Client-2009-06-21-10-34-43-04.png" alt="战斗模式游戏中" /></a></p>
<p>PS:新版igame虽然界面很漂亮,连个连连看都下不了。。速度极慢还不停从头下,网站的连连看链接还无效。怒!</p>
中国站前瞻——Williams, McLaren, Mercedes GP等等
2010-04-12T14:38:27+00:00
http://greenmooon55.com/2010-china-preview-quotes
<p>原文链接:<a href="http://www.formula1.com/news/headlines/2010/4/10648.html">http://www.formula1.com/news/headlines/2010/4/10648.html</a></p>
<p>上海国际赛车场有令人惊叹的建筑、高速直道和蜿蜒的弯道,这意味着车队非常高兴地忍受着上海拥挤的交通,享受在中国比赛的机会。接下来车队的高级员工和车手考虑中国大奖赛周末的期望,并解释为什么他们把此赛道看作他们最喜欢的赛道之一。</p>
<p>Rubens Barrichello, Williams
2009 排位赛 - 第4, 2009 正赛 - 第4</p>
<p>”上海赛道是个十分有趣的赛道。弯道和赛道末尾很适合超车的长直道结合得不错。要得到快的圈速,赛车需要更多的空气动力学,而不是机械性能,但两者的精确结合往往很难达到。再加上每圈也很长,影响因素很多,完美的调教赛车是艰难的工作。我赢得了上海的第一场比赛,这对我很特别。我会常常想起那场胜利,这使我想到我随时可以再赢一次。”
Nico Hulkenberg, Williams
2009 排位赛 - 无, 2009 正赛 - 无</p>
<p>”与马来西亚一样,我以前在中国比赛过,那是A1大奖赛两个赛季前。去参加一场对赛道有经验的大奖赛感觉不错。你可以在模拟器里做无数训练,但这比不过真实的赛道经验。这个赛道不是我喜欢的,它缺乏人情味,但它确实有个很长的直道,这是超车的好地方。这里在比赛时要提防被超过,赛道的这个部分会有一些精彩动作。我将在周一飞往中国,虽然没有必要为了适应早点到,我真的想看看风景名胜,这座城市相当酷。我一定会去一趟外滩和附近浦东的东方明珠电视塔。“</p>
<p>Sam Michael, Williams 技术总监</p>
<p>“在马来西亚遇到的问题后,我们带着提升我们表现的明确目标前往中国。有几个我们明显要注意的关键区域。第一,我们要保证两位车手再次在排位赛中进入前十,以便给他们最好的机会在正赛中得到需要的积分。我们也要改进我们的发车。我们解决了 Rubens 在发车时的问题,在周五练习赛我们将要进行一系列发车训练。对于赛车研发,我们正在努力为上海站对前后翼进行一些空气动力学改进。”</p>
<p>Jenson Button, McLaren
2009 排位赛 - 第5, 2009 正赛 - 第3</p>
<p>“去年,他们把比赛从赛季末移到赛季初,周末比以前更冷更湿。天气预报现在不表明今年的赛事会有任何不同——但我乐观地认为周末会干燥,比赛会比去年更加简单。尽管如此,这是一个我喜欢的赛道:这是个典型的现代化赛道——有真正的弯角组合,但它使一些相当精确的、要求技术的区段与一些高速弯和长直道结合。这是个好车手的赛道,这里对平衡良好的赛车有优势。尽管我认为在那个区域我已经有了真正的进步,我对马来西亚的赛车平衡并不完全满意,所以我在 McLaren 科技中心呆了一天,看看我们为什么在雪邦做得不够好,也展望了上海。我认为,和我的机械师们一起,我们已经对MP4-25更加了解。我们知道如何微调赛车的平衡到最好、如何在一个比赛周末搞定它。当然,这是一个连续的过程,但是总体感觉是我们正在进步——这总是积极的。”</p>
<p>Lewis Hamilton, McLaren
2009 排位赛 - 第9, 2009 正赛 - 第6</p>
<p>“很难相信我们正在临近今年的第四场比赛——比赛过得非常快。马来西亚后,我有一点点时间来反思这个赛季(到目前为止),我对 Jenson 和我在一些有挑战性的环境中得到的成绩很高兴。我真想在中国有一个不被打断的周末,这样我们就可以集中注意力到比赛上并与其他在锦标赛中领先的队伍竞争。在这里驾驶真的很享受——2008年我在这里开了我最好的比赛之一,从杆位获胜。在三场比赛后,我们对我们的比赛节奏很满意,我们将要在前排,我们感觉很舒服。在这个赛道上,超车是可能的,尤其是长直道的末端,所以我很自信这又是一个我们有竞争力的周末。最后,我认为在世界上我们去过的所有地方里中国车迷是最激情、热诚的。他们真正地支持我这么多年,我盼望在到达上海后再次见到他们。”</p>
<p>Martin Whitmarsh, McLaren 车队领队</p>
<p>“根据我们自己很高的标准,在前三场比赛中我们没有完全达到我们很高的预期,尽管有我们感觉在前排竞争必要的比赛速度,尽管我们赢了澳大利亚大奖赛。考虑到我们是车队积分榜的第二名,考虑到 Jenson 和 Lewis 都与车手积分榜第一位接近,这听起来或许过于自我批评了。但那仅仅是一个事实的反映—— Vodafone McLaren Mercedes 想在任何时候都出色。所以我把这目标当作积极的信号:我们的愿望是改进并剔除错误,使我们变成更强的锦标赛竞争者。没有否认我们的成功—— Jenson 与车队的融合,他在墨尔本的胜利,以及 Lewis 职业生涯中一些最好的驾驶——给了我们赛季初期的鼓励。现在我们希望长期保持在前列的竞争者,并定期夺得有可能的最多积分。这支车队的最佳特质之一就是可观的发展潜力,当前往中国以及后面的欧洲赛季开始时,我们相信我们将成为更难对付的竞争者。”</p>
<p>Nico Rosberg, Mercedes GP
2009 排位赛 - 第7, 2009 正赛 - 第15</p>
<p>“上海赛道是个好赛道,对于车手是个有趣的挑战。两个长直道提供相当好的超车机会,弯角的组合相当棒,尤其是高速段。上海的天气要比前三站冷,而且还很难预测,所以这将是个有趣的周末。中国车迷十分热情,上海是个很棒的城市,我总是享受我们一年一度的到来。与车队上一站在马来西亚实现我第一个杆位真是难以置信,我希望能持续我们一贯的努力,下周在中国取得好成绩。”</p>
<p>Michael Schumacher, Mercedes GP
2009 排位赛 - 无, 2009 正赛 - 无</p>
<p>“对梅塞德斯-奔驰的热情和车迷的支持在中国很强大,所以我们下周在上海面临一场有吸引力的比赛。我自信车迷是不会失望地离开比赛的。我们在马来西亚看起来合情合理,在上海或许事情将再一次在我们的掌控之中。我很期待比赛,也期待再一次完全享受竞争。不可否认地说上两场比赛对我不太幸运,但我充分意识到了原因。我知道F1中事情怎样发展,如果你仔细看两场比赛的详细过程,我觉得一切仍然按计划进行。你只能一步一步改进,我相信我们正在这样做。”</p>
<p>Ross Brawn, Mercedes GP 车队领队</p>
<p>“在马来西亚与 Nico 夺得本赛季的我们的第一个杆位让人很满意,这对车队是个及时的激励,马来西亚还是是我们冠名赞助商 Petronas 的主场。Michael 也有个强大的周末,每场比赛 Michael 越来越快,尽管在墨尔本和雪邦他不能控制的情况限制了他的比赛发挥。在中国,我们希望继续进步,这将尤其对 Michael 有利,他能开一场没有意外的比赛并展示从赛季开始以来的进步。在实际表现层面,车队在最近三站表现很好,在 Nico 马来西亚的比赛做得很棒,创下了赛季中最短的进站之一的记录。除了马来西亚的车轮螺栓问题外,我们的赛车是可靠的,我对车手们的表现很满意。我们得到了一系列与当前赛车速度相符的合理的结果,但我们需要实事求是并承认我们不够快,现在还不足以在前列竞争。显然这不是个让我们高兴的状况,我们正努力工作以缩小差距。”</p>
<p>Norbert Haug, 副董事长, 梅赛德斯·奔驰汽车运动公司</p>
<p>“中国大奖赛从2004年起举办,是F1赛历中最受认可的赛事之一。处于上海城区外的赛道带给赛车、车手和车队很多挑战。有高速弯也有低速弯,还有两个发夹弯,其中的一个接近起止线。对于上海,长期天气预报不能预测下雨的可能性,就像上一站马来西亚一样。无论怎么样,我们会努力得到好成绩并为接下来的比赛一步一步提高我们的技术套件。”</p>
<p>Pedro de la Rosa
2009 排位赛 - 无, 2009 正赛 - 无</p>
<p>“我真的喜欢并享受上海赛道。我最后一次在这里比赛是2006年,我第五名完赛。这个赛道有很长的直道和很好的超车机会。整体来说这个赛道有各种各样的弯角,包括需要大力刹车的发夹弯和通过顺畅的其他弯角。我们正在努力工作提高赛车的表现。还剩下16场比赛,所以不管怎么说赛季还没有结束。对于可靠性我很放松,在马来西亚发生的不幸极了,这不会再次发生。”</p>
<p>Kamui Kobayashi
2009 排位赛 - 无, 2009 正赛 - 无</p>
<p>“在F1中第一次到上海比赛,我感到很兴奋。2008年10月,在GP2亚洲系列赛我度过了一个不错的周末。我从第二位起跑,创造了最快圈速,却在安全车时期差了一点点丢掉了冠军。赛道很棒,大看台让人印象深刻。事实上我喜欢在大直道后的发夹弯前大脚刹车。我感觉在上海我们会很艰难,但我期待着挑战。一般来说,我喜欢在亚洲比赛,日本也不远了,我常常在这里看到比欧洲多的日本同胞。上海也是个令人兴奋的城市,但不幸的是我们不能看太多,因为赛道离市中心太远了。”</p>
<p>James Key, BMW Sauber 技术总监</p>
<p>“我期盼着和车队的第一场比赛。在复活节周末后我来到了 Hinwil 见了好多人。我对正在发生的事情有了个好印象。显然有要做的工作,但车队团队精神和积极性非常高。现在开始显露的是我们需要前进的方向。每个人都努力工作,我们现在正在做未来方向的计划以继续进步。今年我还没去过赛道,看看到底是怎么样、学学轮胎、与车手谈话会是有趣的事。这将是我第一次看到 C29,与 Willy Rampf 近看它并查看细节会很好。就赛道而言,下压力级别与我们经历的前三站相当相似。这是另一个特制的赛道,有一些有趣的特色。有个很长的直道,因此下压力需要妥协。这是一个高抓地力赛道,这意味着或许要把定风翼角度调大一点点。刹车稳定性和牵引力很重要,还有两个蜗牛一样的弯角,车手对此很棘手。我们要看看赛车和轮胎怎么样。我们希望得到最好的结果,我们会努力得到一些积分。”</p>
<p>Hirohide Hamashima, 普利司通赛车轮胎发展总监</p>
<p>“上海国际赛车场对轮胎要求很高。这里侧向力很大,我们预测左前胎会粒化,尤其是由半径增加的二号弯和倾斜度增大的13号弯造成的。这里后台也会出现粒化。今年的轮胎配置比2009年更硬了一些,因为赛车更沉、赛道耗胎。赛道布局意味着中低下压力的调教将会被使用,尽管有两条长直道,但赛道的很大一部分都很弯曲、技术要求高。对于车队和车手,找到正确的调教以充分利用轮胎是个大挑战。去年挑战是天气,雨胎在比赛的大部分时间里被使用。这不是第一次在中国湿地比赛,所以天空将会是这周末的关注焦点。”</p>
<p>终于弄完了,一下午+一晚上,有些地方自己都不太理解,翻译玩一看全是套话。。然后官网又更新了。。不一定加了。
没有校对,自己都没读。。
以后再写出难懂的地方学习学习~</p>
USACO Superprime Rib
2010-04-04T07:16:35+00:00
http://greenmooon55.com/usaco-superprime-rib
<p>这题和昨天那个差不多,DFS找质数即可。
最开始把prime数组开到10000,出现了很怪异的问题:运行完init()会把n归零。。
还学会了<a href="http://www.slyar.com/blog/c-freopen-stdin-stdout.html">用freopen</a>,否则没法再其他地方输出。还是要写fclose的。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
PROB: sprime
*/</span>
<span class="cp">#include
#include
#include
</span>
<span class="n">bool</span> <span class="n">prime</span><span class="p">[</span><span class="mi">10001</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">num</span><span class="p">[</span><span class="mi">10000</span><span class="p">],</span><span class="n">sum</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
<span class="kt">void</span> <span class="nf">init</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">prime</span><span class="p">,</span><span class="nb">true</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">prime</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">100</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="mi">10000</span><span class="o">/</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="o">*</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">10000</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">prime</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">j</span><span class="o">++</span><span class="p">;</span>
<span class="n">num</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">sum</span><span class="o">=</span><span class="n">j</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">bool</span> <span class="nf">isprime</span><span class="p">(</span><span class="kt">long</span> <span class="n">a</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">sum</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">></span><span class="n">sqrt</span><span class="p">(</span><span class="n">a</span><span class="p">))</span> <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="o">%</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">void</span> <span class="nf">search</span><span class="p">(</span><span class="kt">long</span> <span class="n">a</span><span class="p">,</span><span class="kt">int</span> <span class="n">depth</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="n">temp</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">depth</span><span class="o">==</span><span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%ld</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">a</span><span class="p">);</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">10</span><span class="p">;</span><span class="n">i</span><span class="o">+=</span><span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">temp</span><span class="o">=</span><span class="n">a</span><span class="o">*</span><span class="mi">10</span><span class="o">+</span><span class="n">i</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">isprime</span><span class="p">(</span><span class="n">temp</span><span class="p">))</span> <span class="n">search</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span><span class="n">depth</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"sprime.in"</span><span class="p">,</span> <span class="s">"r"</span><span class="p">,</span> <span class="n">stdin</span><span class="p">);</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"sprime.out"</span><span class="p">,</span> <span class="s">"w"</span><span class="p">,</span> <span class="n">stdout</span><span class="p">);</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="n">init</span><span class="p">();</span>
<span class="n">search</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
<span class="n">search</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
<span class="n">search</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
<span class="n">search</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">stdin</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">stdout</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
我的饭否消息
2010-04-03T16:29:44+00:00
http://greenmooon55.com/my-fanfou
<p>再见饭否,这是<a href="http://www.fanfoublog.com/">导出</a>的消息,我的中文微博开始于饭否。吃惊地发现原来从07年就开始了。
<a href="http://www.cnnic.net.cn/html/Dir/2003/12/12/2000.htm">“Across the Great Wall we can reach every corner in the world.”</a></p>
<ol>
<li>
<p>@JasonNg 有一个<a href="http://www.hellof1.com/">http://www.hellof1.com/</a>, 上面有“F1最新动态,视频、图片、新闻、直播”。有个用WP的英文站<a href="http://www.f1fanatic.co.uk/">http://www.f1fanatic.co.uk/</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-10-04 18:14</a> 通过网页</p>
</li>
<li>
<p>这里先不管了,先只用twitter <a href="http://twitter.com/greenmoon55">http://twitter.com/greenmoon55</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-30 22:01</a> 通过网页</p>
</li>
<li>
<p>有人度蜜月把相机丢了,捡到的人在Help Forum 和Scotland group发贴,后来在大家的帮助下找到了。Flickr Blog里有介绍。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-30 20:13</a> 通过网页</p>
</li>
<li>
<p>今天坐公交车比校车还快:) <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-30 15:21</a> 通过网页</p>
</li>
<li>
<p>对了,今天第二段看到两车一圈时间相同了。好久没看到(第一次?)。只 记得06年某站排位KIMI比舒米快0.002秒。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-23 21:08</a> 通过网页</p>
</li>
<li>
<p>不错,很惊险啊,法拉利在前面一直感觉有点慢。载油量怎么样?这赛道我 还没好好玩过。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-23 21:06</a> 通过网页</p>
</li>
<li>
<p>雨会变大吗? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-23 20:30</a> 通过网页</p>
</li>
<li>
<p>看F1新赛道很爽 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-23 20:26</a> 通过网页</p>
</li>
<li>
<p>深度、雨林的系统版已经隐藏?呵呵 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-20 20:09</a> 通过网页</p>
</li>
<li>
<p>CB又上不去。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-20 19:58</a> 通过网页</p>
</li>
<li>
<p>松花江中学着火了,开始好像很严重,各处的消防车都去了。刚去看,不过连烟都没了,学生似乎在正常上课,正好下晚 课?。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-20 18:39</a> 通过网页</p>
</li>
<li>
<p>今天累了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-15 22:11</a> 通过网页</p>
</li>
<li>
<p>射箭赢了,很爽^_^ lol <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-14 18:01</a> 通过网页</p>
</li>
<li>
<p>下载BBC开幕式ing,500多M。高清的太大了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-11 11:50</a> 通过网页</p>
</li>
<li>
<p>刚开始文艺表演还可以,不过实在是太古典了。主题歌很难听,或许听多了 就好了。。焰火也没什么特别的。总体感觉一般,或许是期望太大了,过几个小时再问问国外几个人的感受。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-09 00:43</a> 通过网页</p>
</li>
<li>
<p>今天摄像太没水平了,切换很有问题,而且给领导的镜头太多了。 小孩画画之前还有个SB老师。运动员入场时当拉拉队的MM好可怜。。 点火炬太没意思,不过李宁的速度为什么先满后快? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-09 00:35</a> 通过网页</p>
</li>
<li>
<p>#080808 怎么都用这个 tag? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-09 00:30</a> 通过网页</p>
</li>
<li>
<p>Hungary race analysis - what goes around, comes around <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-06 17:35</a> 通过网页</p>
</li>
<li>
<p>刚发现网易有个域名<a href="http://orz.163.com/">http://orz.163.com/</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-03 12:26</a> 通过网页</p>
</li>
<li>
<p>wp2.6 中文tag标题不显示,更换文件也无法解决。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-03 11:43</a> 通过网页</p>
</li>
<li>
<p>在speed众多广告中,我居然发现有godaddy的域名注册广告, 时间还不短。。。 .com域名 1.99USD/yr <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-02 21:30</a> 通过网页</p>
</li>
<li>
<p>看的是speed的F1,MC1-2,Massa P3 Kimi P6。马萨有最快圈,但是感觉不是很轻松。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-02 21:28</a> 通过网页</p>
</li>
<li>
<p>今天看看itv直播的F1 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-02 19:59</a> 通过网页</p>
</li>
<li>
<p>鼠标右键坏了。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-02 17:43</a> 通过网页</p>
</li>
<li>
<p>FireGestures突然不好使了? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-02 17:20</a> 通过网页</p>
</li>
<li>
<p>找出将近10年前的win98盘,安装。用软盘传U盘驱动,用U盘传网 卡驱动,能上网了。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-02 16:37</a> 通过网页</p>
</li>
<li>
<p>看了一部分日全食,发现自己什么都不懂。学过的忘了,没学的不知道。 BS一下国内某些直播台。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-01 20:04</a> 通过网页</p>
</li>
<li>
<p>新版delicious怎么越看越难受。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-01 08:44</a> 通过网页</p>
</li>
<li>
<p>听BBC中文广播中 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-01 07:05</a> 通过网页</p>
</li>
<li>
<p>deliciuos终于升级了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-08-01 06:36</a> 通过网页</p>
</li>
<li>
<p>Kovalainen to stay at McLaren for 2009 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-31 20:07</a> 通过网页</p>
</li>
<li>
<p>Firefox 无法建立到 127.0.0.1:895 服务器的连接。现在好了,刚才以为VPN也被封了。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-31 19:33</a> 通过网页</p>
</li>
<li>
<p>youtube有简体中文版了?是早就有了我没发现还是刚有?logo右侧有个语言选择。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-31 11:00</a> 通过网页</p>
</li>
<li>
<p>YOUTUBE are starting CENSORSHIP ?! <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-30 20:58</a> 通过网页</p>
</li>
<li>
<p>回到17寸液晶,舒服 汗 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-27 21:40</a> 通过网页</p>
</li>
<li>
<p>自带FF1.5,从外部打开链接有点问题,PETget一打开就崩溃。。要是电脑强的话早装Ubuntu了。 800*600+15寸球面够受的。不过这个E-PUP-Linux-217作者改的和Windows操作差不多了,安装也比较简单,硬盘也不怎么响。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-27 21:15</a> 通过网页</p>
</li>
<li>
<p>puppy linux装好了,体验中。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-27 18:51</a> 通过网页</p>
</li>
<li>
<p>推荐Neekey API Services <a href="http://photozero.net/neekey_api_services/">http://photozero.net/neekey_api_services/</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-27 16:14</a> 通过网页</p>
</li>
<li>
<p>从旺旺NG群上看到的,这下买不了了。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-27 11:17</a> 通过网页</p>
</li>
<li>
<p>关于“港澳台”相关书籍涉及政治,色情,邪教等书籍的会员,属违规行为或违法行为,淘宝网将继续加大查处力度,给于严 厉冻结账户处罚。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-27 11:15</a> 通过网页</p>
</li>
<li>
<p>亲爱的卖家: 淘宝网于2008年7月19日针对一级类目下“书籍/杂志/报纸”的二级类目“国外原版书/台版、港版书”做整改措施,只保留“生活类原版书”,其余都做 不计数下架删除。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-27 11:15</a> 通过网页</p>
</li>
<li>
<p>Blog上的垃圾评论越来越多了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-26 12:25</a> 通过网页</p>
</li>
<li>
<p>something interesting: 到Google News上搜“香港 记者 北京 警察”who is right? youtube上虽然有video,不过有人说是被剪辑的。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-26 12:24</a> 通过网页</p>
</li>
<li>
<p>昨天学校final debate:censorship in china, right or wrong(我们组早被淘汰了)之后去解释了一下G/F/W,几十学生只有一人和hk回来的大学生+外教明白。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-26 12:20</a> 通过网页</p>
</li>
<li>
<p>真正的假期来临了,不过也没几天了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-26 12:16</a> 通过网页</p>
</li>
<li>
<p>现在G/F/W好松好狡猾啊,<a href="http://en.wikipedia.org/wiki/Golden_Shield_Project">http://en.wikipedia.org/wiki/Golden_Shield_Project</a>都 能访问,刷新就不行了。译言文章有wikipedia的链接都会被墙。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-25 17:15</a> 通过网页</p>
</li>
<li>
<p>天热啊,早上还没风,现在还好些,有点风了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-25 13:56</a> 通过网页</p>
</li>
<li>
<p>Youtube上有好多good videos. <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-24 21:02</a> 通过网页</p>
</li>
<li>
<p>令人不解的是盗号的没改密码,只用我15悬赏分提问。难道学校微机室那时有人而我碰巧没有退出? 希望是这样,我还是很相信自己电脑的安全的。开学去查查。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-23 16:20</a> 通过网页</p>
</li>
<li>
<p>百度登陆上了,原来是ff禁用了百度的cookie。密码或许是在学校丢的,学校应该什么病毒都有,还装着网络版x 星,连改设置都不行。开学去学校查查有没有keylogger,以后再学校也要注意安全啊。在学校登录过百度、gmail、校内、网易邮箱、雅虎邮箱、 oibh。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-23 16:17</a> 通过网页</p>
</li>
<li>
<p>FF3不能登陆百度? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-23 07:33</a> 通过网页</p>
</li>
<li>
<p>MS我百度的帐号被盗了。邮箱里发现问题到期提醒,但是我从来没有问过啊,如果是盗号也应该改密码啊,他连我密码都没 改,难道只为了给那15分悬赏?提问时间2008-7-9 09:37,一定不是我,我在考试啊。。。难道密码真的被盗了?!!!!!!很多别的服务都在用这个啊。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-23 01:19</a> 通过网页</p>
</li>
<li>
<p>poj很强啊,可以把交过的程序做成archive一起下来。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-22 22:27</a> 通过网页</p>
</li>
<li>
<p>江边很漂亮啊,天空阴云密布,江边的楼房还在阳光的侧面照射下。这么多年都没看到过。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-22 17:19</a> 通过网页</p>
</li>
<li>
<p>上google好慢啊,用VPN试试 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-22 07:28</a> 通过网页</p>
</li>
<li>
<p>疯了!zju1136还是不对。调了一下午了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-21 17:22</a> 通过网页</p>
</li>
<li>
<p>Great race but sad results for Ferrari. <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-20 22:19</a> 通过网页</p>
</li>
<li>
<p>noi linux至少需要384M内存才能引导live cd <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-20 19:13</a> 通过网页</p>
</li>
<li>
<p>Sunday weather update - showers still threaten for race <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-20 12:37</a> 通过网页</p>
</li>
<li>
<p>今天吉林很热啊 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-20 12:35</a> 通过网页</p>
</li>
<li>
<p>Kimi P6 Massa P2 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-19 21:31</a> 通过网页</p>
</li>
<li>
<p>谁开发一个饭否的ff插件,像twitterfox就行。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-19 19:43</a> 通过网页</p>
</li>
<li>
<p>今天明天Hockenheim还要下雨吗?今年雨站真多。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-19 19:43</a> 通过网页</p>
</li>
<li>
<p>似乎是我的blog不太稳定,关闭feedlr的bot了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-19 15:13</a> 通过网页</p>
</li>
<li>
<p>zju 1149…………….. <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-17 21:19</a> 通过网页</p>
</li>
<li>
<p>怎么又出现这么多blog post?再来我就取消这个了。555555 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-17 21:19</a> 通过网页</p>
</li>
<li>
<p>zju 1076 一直WA 55555 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-16 22:10</a> 通过 GTalk</p>
</li>
<li>
<p>Blog Post: Zju1107 <a href="http://tinyurl.com/5nqp6t">http://tinyurl.com/5nqp6t</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-15 16:29</a> 通过 API</p>
</li>
<li>
<p>twitter上垃圾Followers真多。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-15 15:30</a> 通过 GTalk</p>
</li>
<li>
<p>Blog Post: Zju1027 <a href="http://tinyurl.com/5rhu7s">http://tinyurl.com/5rhu7s</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-15 15:27</a> 通过 API</p>
</li>
<li>
<p>全走江边。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-14 14:41</a> 通过 GTalk</p>
</li>
<li>
<p>吉林市火炬传递路线:市政府门前广场,经松江中路—江城广场—松江东路—江湾大桥—滨江东路—滨江中路—风帆广场。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-14 14:40</a> 通过 GTalk</p>
</li>
<li>
<p>土豆和56开始删除F1的视频了,优酷还可以看。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-13 06:37</a> 通过 GTalk</p>
</li>
<li>
<p>20行小程序能编出N多错误。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-12 09:14</a> 通过 GTalk</p>
</li>
<li>
<p>做点题找找感觉。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-12 08:54</a> 通过 GTalk</p>
</li>
<li>
<p>额,正在折腾blog。对不起follower。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 22:05</a> 通过网页</p>
</li>
<li>
<p>Blog Post: CookieMan Context <a href="http://tinyurl.com/695mb7">http://tinyurl.com/695mb7</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 22:03</a> 通过 API</p>
</li>
<li>
<p>没意思。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 18:17</a> 通过 GTalk</p>
</li>
<li>
<p>刚刚发现有qzone的feed居然只输出一小部分,还得去qqmail里看。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 16:24</a> 通过 GTalk</p>
</li>
<li>
<p>@拉奇 忙什么呢? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 13:51</a> 通过 GTalk</p>
</li>
<li>
<p>@JasonNg 。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 13:50</a> 通过 GTalk</p>
</li>
<li>
<p>静态化弄了半天也没弄好,其实也没必要静态化。 使用cos-html-cache时page出现404 <a href="http://tinyurl.com/59lkz9">http://tinyurl.com/59lkz9</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 12:43</a> 通过 GTalk</p>
</li>
<li>
<p>天天下雨 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 11:00</a> 通过 GTalk</p>
</li>
<li>
<p>Blog Post: Read it Later <a href="http://tinyurl.com/55z7lq">http://tinyurl.com/55z7lq</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 09:38</a> 通过 API</p>
</li>
<li>
<p>终于翻译完了!Testing…不过有些地方可能检查不到。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-11 06:24</a> 通过 GTalk</p>
</li>
<li>
<p>在babelzilla翻译FF的Read it Later插件,相当不错的插件啊! <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-10 20:17</a> 通过 GTalk</p>
</li>
<li>
<p>不是几天,只是今天上午,打错了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-08 17:29</a> 通过网页</p>
</li>
<li>
<p>怎么回事,一考试就有问题。昨天磕脑袋了,几天感冒+脖子疼。。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-08 14:51</a> 通过 GTalk</p>
</li>
<li>
<p>很爽啊,有点像去年欧洲了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-06 21:49</a> 通过 GTalk</p>
</li>
<li>
<p>银石又下雨了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-06 20:41</a> 通过 GTalk</p>
</li>
<li>
<p>起来了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-06 14:30</a> 通过 GTalk</p>
</li>
<li>
<p>又下雨了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-06 08:21</a> 通过 GTalk</p>
</li>
<li>
<p>官方直播说Rain is expected!或许这样还能对法拉利好点。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-05 21:24</a> 通过 GTalk</p>
</li>
<li>
<p>前几名差距很大 KOV21.049 WEB21.554 RAI21.706 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-05 21:22</a> 通过 GTalk</p>
</li>
<li>
<p>Ferrari好慢啊 MAS居然1:23第9 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-07-05 21:20</a> 通过 GTalk</p>
</li>
<li>
<p>Blog Post: 贵州Weng/an <a href="http://tinyurl.com/3zvz9d">http://tinyurl.com/3zvz9d</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-30 23:59</a> 通过 API</p>
</li>
<li>
<p>Blog Post: 吉林2008省选题扫描版 <a href="http://tinyurl.com/5vzhps">http://tinyurl.com/5vzhps</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-30 23:28</a> 通过 API</p>
</li>
<li>
<p>Blog Post: The Castle <a href="http://tinyurl.com/5hdmnc">http://tinyurl.com/5hdmnc</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-30 23:28</a> 通过 API</p>
</li>
<li>
<p>Blog Post: 空白垃圾邮件 <a href="http://tinyurl.com/5ab8m4">http://tinyurl.com/5ab8m4</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-30 23:28</a> 通过 API</p>
</li>
<li>
<p>Blog Post: CookieMan Context <a href="http://tinyurl.com/695mb7">http://tinyurl.com/695mb7</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-30 23:28</a> 通过 API</p>
</li>
<li>
<p>Blog Post: 贵州Weng/an <a href="http://tinyurl.com/3zvz9d">http://tinyurl.com/3zvz9d</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-29 23:31</a> 通过 API</p>
</li>
<li>
<p>删掉Gtalk labs edition,换回老版了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-29 17:16</a> 通过 GTalk</p>
</li>
<li>
<p>又打雷了,今年夏天雷雨真多。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-29 15:50</a> 通过 GTalk</p>
</li>
<li>
<p>Feedsky又出问Feedsky又出问题了?FEED链接打不开,看来Feedsky又出问题了?FEED链接打 不开,看来用feedsky做统计风险太大。用feedsky做统计风险太大。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-28 19:57</a> 通过 GTalk</p>
</li>
<li>
<p>弄了retaggr,很有趣。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-28 18:19</a> 通过 GTalk</p>
</li>
<li>
<p>在Babelzilla更新了FF插件disable menu的中文翻译。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-28 17:41</a> 通过 GTalk</p>
</li>
<li>
<p>kimi的问题到底是怎么回事? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-22 22:07</a> 通过 GTalk</p>
</li>
<li>
<p>我们高中在豆瓣上居然有小组,真不容易,不过没几个人。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-22 19:21</a> 通过 GTalk</p>
</li>
<li>
<p>tor网站被封了,刚想更新一下 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-21 21:22</a> 通过 GTalk</p>
</li>
<li>
<p>本站宝马怎么了?不知道明天HAM会三停吗? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-21 21:18</a> 通过 GTalk</p>
</li>
<li>
<p>@JasonNg 吉林网通ADSL能 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-21 18:24</a> 通过 GTalk</p>
</li>
<li>
<p>Facebook发布中文版了,但是还没有完全中文化,学校名还是英文,我都没找到我的学校。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-21 16:42</a> 通过 GTalk</p>
</li>
<li>
<p>以后在twitter也发中文 <a href="http://twitter.com/greenmoon55">http://twitter.com/greenmoon55</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-21 16:33</a> 通过 GTalk</p>
</li>
<li>
<p>唉,第一题都错了,刚才重打的50分,改完80,再改才100,这种错误。。。。 :( <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-18 23:14</a> 通过 GTalk</p>
</li>
<li>
<p>话说OI吉林省队女生只要140分,师大附中 的。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-18 22:36</a> 通过 GTalk</p>
</li>
<li>
<p>QQ音乐的分组列表居然要手动上传,以前的都没了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-15 12:55</a> 通过 GTalk</p>
</li>
<li>
<p>终于会用CENA了。^_^ <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-13 21:07</a> 通过 GTalk</p>
</li>
<li>
<p>电脑又快了?! <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-12 23:22</a> 通过 GTalk</p>
</li>
<li>
<p>装上twitterfox了,好久没更新twitter <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-08 21:30</a> 通过 GTalk</p>
</li>
<li>
<p>twitter导航栏上的help怎么指向首页了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-08 21:05</a> 通过 GTalk</p>
</li>
<li>
<p>注册了friendfeed,弄了半天才把flickr帐号加进去。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-08 20:59</a> 通过 GTalk</p>
</li>
<li>
<p>用PE重装了系统,深度5.10。还是有点慢, 看来硬盘确实有问题,不知道还能撑多久。 :( <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-07 16:58</a> 通过 GTalk</p>
</li>
<li>
<p>今天收到了NG08年第5期,还不错。以后慢慢看 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-05 21:39</a> 通过 GTalk</p>
</li>
<li>
<p>FF3.0 RC2 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-05 19:31</a> 通过 GTalk</p>
</li>
<li>
<p>FT~~支付宝从Feedsky收款还要实名认证。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-02 18:43</a> 通过 GTalk</p>
</li>
<li>
<p>海内的验证email终于发来了,落款是5月25日。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-01 13:13</a> 通过 GTalk</p>
</li>
<li>
<p>Piero说下周重赛一半 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-01 07:07</a> 通过 GTalk</p>
</li>
<li>
<p>Long Beach 排位1:15秒多一点,领先Clodi半秒多。比赛第二圈超过他夺回第一,以后一直保持10s领先。可惜10圈左右服务器关了,被踢出了,不过应该算第 一。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-06-01 06:44</a> 通过 GTalk</p>
</li>
<li>
<p>把EQ从3.41升到4.0b3+竹节规则,感觉这个规则自己还得调不少东西。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-31 22:00</a> 通过 GTalk</p>
</li>
<li>
<p>今天下午信息课。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-30 19:05</a> 通过 GTalk</p>
</li>
<li>
<p>百度“facebook 中文”为关键词的搜索结果第一页有我的blog,30多ip <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-29 19:53</a> 通过 GTalk</p>
</li>
<li>
<p>twitter的IM服务还没好呢 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-29 19:52</a> 通过 GTalk</p>
</li>
<li>
<p>网速快真好!Castle快完事了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-29 19:52</a> 通过 GTalk</p>
</li>
<li>
<p>MAS发车时好像挡KIMI了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-25 22:25</a> 通过 GTalk</p>
</li>
<li>
<p>MAS开始还是很快的,后来不知道出了什么问题。KIMI至少最近这3年在这里都很惨啊。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-25 22:22</a> 通过 GTalk</p>
</li>
<li>
<p>天气预报比德国差多了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-25 22:16</a> 通过 GTalk</p>
</li>
<li>
<p>还看到了多年不得一见的HAM和KUB圈速相 同,以黑色显示+0.000 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-25 22:09</a> 通过 GTalk</p>
</li>
<li>
<p>CCTV的翻译该下岗了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-25 22:08</a> 通过 GTalk</p>
</li>
<li>
<p>有戏剧性,果然下雨了,但没预想的有意思。MAS P3, RAI P10 4 stops <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-25 22:08</a> 通过 GTalk</p>
</li>
<li>
<p>Twitter的IM服务暂停了,好像是系统负 担过重 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-24 21:10</a> 通过 GTalk</p>
</li>
<li>
<p>Ferrari 1-2 真不容易,这么多年了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-24 21:02</a> 通过 GTalk</p>
</li>
<li>
<p>qsort错了还能过六组(milk2) ,囧 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-18 06:33</a> 通过 GTalk</p>
</li>
<li>
<p>晕死。。。。犯了N个小错(N-1个都是输入输出的。。)。submission #7 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-13 19:45</a> 通过 GTalk</p>
</li>
<li>
<p>以前用windows经典 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-10 22:42</a> 通过 GTalk</p>
</li>
<li>
<p>换到XP默认主题,居然感到变快了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-10 22:42</a> 通过 GTalk</p>
</li>
<li>
<p>超级亚久里退出F1了。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-09 18:53</a> 通过 GTalk</p>
</li>
<li>
<p>del.icio.us Temporarily Down for Maintenance We are performing scheduled maintenance. We should be back online shortly. 暂停服务 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-03 15:21</a> 通过 GTalk</p>
</li>
<li>
<p>安装mania2008 mod中 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-03 13:13</a> 通过 GTalk</p>
</li>
<li>
<p>FF地址栏按回车后没反应。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-03 11:46</a> 通过 GTalk</p>
</li>
<li>
<p><a href="http://tinyurl.com/4rh5ed">http://tinyurl.com/4rh5ed</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-03 11:43</a> 通过 GTalk</p>
</li>
<li>
<p>正在用VPN下载f-1mania38.exe。很快啊,都能到60K,稳定在40~50K之间 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-03 11:38</a> 通过 GTalk</p>
</li>
<li>
<p>Watch Tibet Past & Present on CCTV 9 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-03 06:58</a> 通过 GTalk</p>
</li>
<li>
<p>打雷、下雨,天气变化快啊,昨天还是大晴天呢 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-05-02 10:08</a> 通过 GTalk</p>
</li>
<li>
<p>五一快乐,庆祝下三天多的假期 :) <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-30 23:40</a> 通过 GTalk</p>
</li>
<li>
<p>April 28, 2008 (2008-04-28) (Monday): Two passenger trains collide in Zibo in Shandong province in eastern China resulting in the deaths of at least 71 people. <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-30 23:39</a> 通过 GTalk</p>
</li>
<li>
<p>看F1都看累了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-27 21:55</a> 通过 GTalk</p>
</li>
<li>
<p>已解决 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-21 10:33</a> 通过 GTalk</p>
</li>
<li>
<p>真神奇,IE7、8不显示我blog的404 page,而FF下正常。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-21 10:33</a> 通过 GTalk</p>
</li>
<li>
<p>看了A1 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-13 19:12</a> 通过 GTalk</p>
</li>
<li>
<p>又起来晚了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-13 07:24</a> 通过网页</p>
</li>
<li>
<p>还是用以前的吧,这个不习惯 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-05 17:49</a> 通过 GTalk</p>
</li>
<li>
<p><a href="http://www.google.com/talk/labsedition">http://www.google.com/talk/labsedition</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-05 17:48</a> 通过 GTalk</p>
</li>
<li>
<p><a href="http://www.facebook.com/translations/">http://www.facebook.com/translations/</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-05 12:03</a> 通过 GTalk</p>
</li>
<li>
<p>欢迎来翻译 Facebook <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-05 12:03</a> 通过 GTalk</p>
</li>
<li>
<p>维基百科解封了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-04-04 20:50</a> 通过 GTalk</p>
</li>
<li>
<p>Wordpress 2.5 Released! <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-30 00:31</a> 通过 GTalk</p>
</li>
<li>
<p>youtube刚解封?^_^ 下午试还是被封的 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-22 22:22</a> 通过 GTalk</p>
</li>
<li>
<p>:D <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-22 18:12</a> 通过 GTalk</p>
</li>
<li>
<p>Ferrari包揽头排^_^ 不过不知道载油量? <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-22 18:12</a> 通过 GTalk</p>
</li>
<li>
<p>澳大利亚站真 乱啊,赶上去年加拿大了。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-16 15:04</a> 通过 GTalk</p>
</li>
<li>
<p><a href="http://del.icio.us/greenmoon55">http://del.icio.us/greenmoon55</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-16 00:21</a> 通过 GTalk</p>
</li>
<li>
<p>开始使用del.icio.us,感觉很不错 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-16 00:21</a> 通过 GTalk</p>
</li>
<li>
<p>终于解决完了 Google Reader中将近1000个未读项目 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-16 00:13</a> 通过 GTalk</p>
</li>
<li>
<p>写了个qsort,居然发现现在写这个都不熟练了。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-09 18:30</a> 通过 GTalk</p>
</li>
<li>
<p>音乐之声真不错 :D <a href="http://www.cnr.cn/">www.cnr.cn</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-09 16:12</a> 通过 GTalk</p>
</li>
<li>
<p>开始工作。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-02 14:31</a> 通过 GTalk</p>
</li>
<li>
<p>看了一圈同学的qzone,加了一些友链 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-03-02 14:23</a> 通过 GTalk</p>
</li>
<li>
<p>假期终于又结 束了。。没过够,目标由没实现,一周不能上网了。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-24 21:12</a> 通过 GTalk</p>
</li>
<li>
<p>。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-19 22:08</a> 通过 GTalk</p>
</li>
<li>
<p>晕死,好像又好了,明天再说 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-19 22:08</a> 通过 GTalk</p>
</li>
<li>
<p>受不了wp的 tags了,slug不能改,重命名也不行,晕死。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-19 21:46</a> 通过 GTalk</p>
</li>
<li>
<p>还不太明白这个 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-18 18:30</a> 通过 GTalk</p>
</li>
<li>
<p>估计没人想让 我写。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-18 18:30</a> 通过 GTalk</p>
</li>
<li>
<p>Feedsky说我blog定价为40元!晕死 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-18 18:27</a> 通过 GTalk</p>
</li>
<li>
<p>加了<a href="http://fairyfish.net/2008/01/19/bookmark-share-plugin/">http://fairyfish.net/2008/01/19/bookmark-share-plugin/</a> 不过有留言上的框 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-17 18:44</a> 通过 GTalk</p>
</li>
<li>
<p>用了XPertMailer <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-16 15:41</a> 通过 GTalk</p>
</li>
<li>
<p>blog注册 邮件发送问题已解决 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-02-16 15:40</a> 通过 GTalk</p>
</li>
<li>
<p>睡觉去了,看完zju1755没做 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-01-26 00:45</a> 通过 GTalk</p>
</li>
<li>
<p>刚才看到了 《杨光的快乐生活三》,还不错,以前大概看过1和2。天津卫视19:30 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-01-25 21:44</a> 通过 GTalk</p>
</li>
<li>
<p>测试K-Meleon <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-01-17 09:18</a> 通过 GTalk</p>
</li>
<li>
<p>编程中 <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-01-16 14:37</a> 通过 GTalk</p>
</li>
<li>
<p>刚才看了维也纳新年音乐会(UUSEE上的cctv音乐频道) <a href="file:///E:/Downloads/fanfou/status_1.html#">2008-01-01 21:17</a> 通过网页</p>
</li>
<li>
<p>准备买一体机,正在查资料 <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-31 19:23</a> 通过 GTalk</p>
</li>
<li>
<p>开始用 FileZilla代替FlashFxp。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-30 19:42</a> 通过 GTalk</p>
</li>
<li>
<p>twitter好像被GFW屏蔽了。。。 <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-30 19:03</a> 通过 GTalk</p>
</li>
<li>
<p>Happy new year:) <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-30 16:54</a> 通过 MSN 签名</p>
</li>
<li>
<table>
<tbody>
<tr>
<td>ed2k://</td>
<td>file</td>
<td>Celine%20Dion%20-%20Christmas%20Songs%20-%20Silent%20Night.mp3</td>
<td>5242880</td>
<td>315443087BA8C6E946C33DEC7D1FC6F7</td>
<td>/ <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-23 15:25</a> 通过 GTalk</td>
</tr>
</tbody>
</table>
</li>
<li>
<table>
<tbody>
<tr>
<td>ed2k://</td>
<td>file</td>
<td>christmas%20songs%20-%20Mariah%20Carey%20~%20Joy%20To%20The%20World.mp3</td>
<td>4163672</td>
<td>374F7F641E1B10C08E8578F180D91E90</td>
<td>/ <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-23 15:25</a> 通过 GTalk</td>
</tr>
</tbody>
</table>
</li>
<li>
<p>下载圣诞歌曲 Joy To The world and Silent Night <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-23 15:24</a> 通过 GTalk</p>
</li>
<li>
<p>困&累 <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-17 21:35</a> 通过 GTalk</p>
</li>
<li>
<p>下午睡了一 觉,不知道睡了多久,总之醒来天就黑了 <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-15 17:24</a> 通过 GTalk</p>
</li>
<li>
<p>音乐之声上放一首不错的歌:孙燕姿《遇见》 <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-15 14:36</a> 通过 GTalk</p>
</li>
<li>
<p>听《中华民 谣》<a href="http://mp3.baidu.com/m?f=ms&tn=baidump3lyric&ct=150994944&lf=2&rn=10&word=%BC%C5%C4%AF%B5%C4%C8%CB%D4%DA%B7%E7%D3%EA%D6%AE%BA%F3&lm=-1">http://mp3.baidu.com/m?f=ms&tn=baidump3lyric&ct=150994944&lf=2&rn=10&word=%BC%C5%C4%AF%B5%C4%C8%CB%D4%DA%B7%E7%D3%EA%D6%AE%BA%F3&lm=-1</a> <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-15 14:35</a> 通过 GTalk</p>
</li>
<li>因高二会考,下午和周六周日放假,终于可以歇会了,不过作业不少:( <a href="file:///E:/Downloads/fanfou/status_1.html#">2007-12-14 12:51</a> 通过 GTalk</li>
</ol>
USACO Prime Palindromes
2010-04-03T04:50:41+00:00
http://greenmooon55.com/usaco-prime-palindromes
<p>第一个TLE了,枚举所有数,先判断回文,后判断质数。优化了点还是不行。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
PROB: pprime
*/</span>
<span class="c1">//This is version 1 TLE
</span><span class="cp">#include
#include
#include
</span><span class="kt">int</span> <span class="n">num</span><span class="p">[</span><span class="mi">11</span><span class="p">];</span>
<span class="kt">int</span> <span class="nf">convert</span><span class="p">(</span><span class="kt">long</span> <span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">n</span><span class="o">></span><span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">n</span><span class="o">%</span><span class="mi">10</span><span class="p">;</span>
<span class="n">n</span><span class="o">=</span><span class="n">n</span><span class="o">/</span><span class="mi">10</span><span class="p">;</span>
<span class="n">i</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">i</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">bool</span> <span class="nf">isprime</span><span class="p">(</span><span class="kt">long</span> <span class="n">l</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">temp</span><span class="p">;</span>
<span class="n">temp</span><span class="o">=</span><span class="n">sqrt</span><span class="p">(</span><span class="n">l</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">temp</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">l</span><span class="o">%</span><span class="n">i</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"pprime.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"pprime.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">long</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">i</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">length</span><span class="p">,</span><span class="n">j</span><span class="p">;</span>
<span class="n">bool</span> <span class="n">find</span><span class="p">;</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%ld%ld"</span><span class="p">,</span><span class="o">&</span><span class="n">a</span><span class="p">;,</span><span class="o">&</span><span class="n">b</span><span class="p">;);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">a</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">b</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">></span><span class="mi">11</span> <span class="o">&&</span> <span class="n">i</span><span class="o"><</span><span class="mi">100</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">></span><span class="mi">1000</span> <span class="o">&&</span> <span class="n">i</span><span class="o"><</span><span class="mi">10000</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">></span><span class="mi">100000</span> <span class="o">&&</span> <span class="n">i</span><span class="o"><</span><span class="mi">1000000</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o">%</span><span class="mi">2</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="n">length</span><span class="o">=</span><span class="n">convert</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="n">find</span><span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">length</span><span class="o">/</span><span class="mi">2</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">!=</span><span class="n">num</span><span class="p">[</span><span class="n">length</span><span class="o">-</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">find</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">find</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">isprime</span><span class="p">(</span><span class="n">i</span><span class="p">))</span> <span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%ld</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">i</span><span class="p">);</span>
<span class="p">}</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
<p>后来参考USACO的hint,直接生成递增的回文数,循环很巧妙,提前生成10000以内的质数,应该提高了不少效率。
所有偶数位的回文数都能<a href="http://zhidao.baidu.com/question/86299975.html">被11整除</a>,此时奇数位与偶数位的差为0。
时间很短:不过为啥时间最长的不是Test 9?</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> Test 1: TEST OK [0.022 secs, 1956 KB]
Test 2: TEST OK [0.000 secs, 1956 KB]
Test 3: TEST OK [0.022 secs, 1956 KB]
Test 4: TEST OK [0.000 secs, 1956 KB]
Test 5: TEST OK [0.011 secs, 1956 KB]
Test 6: TEST OK [0.000 secs, 1956 KB]
Test 7: TEST OK [0.011 secs, 1956 KB]
Test 8: TEST OK [0.011 secs, 1956 KB]
Test 9: TEST OK [0.011 secs, 1956 KB]
```
```C
/*
ID: djgreen1
LANG: C
PROB: pprime
*/
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
int prime[10000];
bool isp[10000];
int num[11],pnum;
bool isprime(long l)
{
int i;
for (i=0;i<pnum;i++)
{
if (prime[i]>sqrt(l)) break;
if (l%prime[i]==0) return false;
}
return true;
}
void init()
{
int i,j;
memset(isp,true,sizeof(isp));
for (i=2;i<100;i++)
if (isp[i])
for (j=2;j<=10000/i;j++) isp[i*j]=false;
j=0;
for (i=2;i<10000;i++)
if (isp[i])
{
prime[j]=i;
j++;
}
pnum=j;
}
int main()
{
FILE *in=fopen("pprime.in","r"),*out=fopen("pprime.out","w");
long a,b,temp;
int i,j,k,l;
fscanf(in,"%ld%ld",&a;,&b;);
fclose(in);
init();
//single-digit number
for (i=5;i<10;i++)
{
if (i<a) continue;
if (i>b)
{
fclose(out);
return 0;
}
if (isprime(i)) fprintf(out,"%d\n",i);
}
//11
if (11>=a && 11<=b) fprintf(out,"11\n");
//3-digit number
for (i=1;i<=9;i+=2)
for (j=0;j<=9;j++)
{
temp=i*101+j*10;
if (temp<a) continue;
if (temp>b)
{
fclose(out);
return 0;
}
if (isprime(temp)) fprintf(out,"%ld\n",temp);
}
//5-digit number
for (i=1;i<=9;i+=2)
for (j=0;j<=9;j++)
for (k=0;k<=9;k++)
{
temp=i*10001+j*1010+k*100;
if (temp<a) continue;
if (temp>b)
{
fclose(out);
return 0;
}
if (isprime(temp)) fprintf(out,"%ld\n",temp);
}
//7-digit number
for (i=1;i<=9;i+=2)
for (j=0;j<=9;j++)
for (k=0;k<=9;k++)
for (l=0;l<=9;l++)
{
temp=i*1000001+j*100010+k*10100+l*1000;
if (temp<a) continue;
if (temp>b)
{
fclose(out);
return 0;
}
if (isprime(temp)) fprintf(out,"%ld\n",temp);
}
fclose(out);
return 0;
}
```
</code></pre></div></div>
电子信息科学类
2010-04-01T10:30:41+00:00
http://greenmooon55.com/%e7%94%b5%e5%ad%90%e4%bf%a1%e6%81%af%e7%a7%91%e5%ad%a6%e7%b1%bb
<p>其实呢,这个包括cs和信息安全。。似乎不太好~~当时考试理化很悲剧的。
<a href="http://greenmoon55.com/%e7%94%b5%e5%ad%90%e4%bf%a1%e6%81%af%e7%a7%91%e5%ad%a6%e7%b1%bb/attachment/20100401170500120/"><img src="http://greenmoon55.com/wp-content/uploads/2010/04/20100401170500120.png" alt="" /></a>
看到“<a href="http://cs.tongji.edu.cn">同济大学计算机科学与技术系”</a>和“<a href="http://see.tongji.edu.cn/">同济大学电子与信息工程学院</a>”的网页,再与<a href="http://sse.tongji.edu.cn/">软院</a>比较一下,我表示很无语。。人家甚至都有RSS了。</p>
<p>扯扯淡,我一直喜欢苏浙沪,为什么呢?从什么时候开始的呢?
其实不太清楚。。
最主要的原因是轨道交通(<a href="http://www.exploreshanghai.com/ditie/">图</a>)吧,就像我喜欢公交车一样。。喜欢听地铁、国铁车轮与轨道的摩擦声。。(上海地铁似乎比北京还要挤)在MSTS上已经跑了几十次沪宁线。
还有就是喜欢F1咯,喜欢F1的声音(汗!),喜欢赛车游戏。。(嘉定校区离上赛场十公里)。
喜欢江南小镇,喜欢那种静谧。</p>
<p>应该还有一些原因的,怎么就是想不起来了呢!或许一个重要原因是:我还没去过那里。。人们貌似会对没去过的地方有很多美好的想象。。</p>
<p>对海边无爱,不会游泳~</p>
USACO Number Triangles
2010-03-31T11:24:11+00:00
http://greenmooon55.com/usaco-number-triangles
<p>很简单的DP,边读入边算都行。。
经测试,定义大数组要放到int main外面,原因不懂~</p>
<p>今天下午可折腾坏了。。试用N个IDE,最后用了北航的Guide。。。gdb还不行,似乎是版本过高了,后来又重新下载的。。
这个似乎是给NOI用的,目前唯一问题是不知道怎么调字体字号。
Code::Blocks现在不能新建工程、Codelite调试窗口是黑的、NetBeans无法编译(唔,现在好像可以啦)。。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
PROB: numtri
*/</span>
<span class="cp">#include
</span><span class="kt">long</span> <span class="n">num</span><span class="p">[</span><span class="mi">1001</span><span class="p">][</span><span class="mi">1001</span><span class="p">];</span>
<span class="kt">long</span> <span class="nf">max</span><span class="p">(</span><span class="kt">long</span> <span class="n">a</span><span class="p">,</span><span class="kt">long</span> <span class="n">b</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="o">></span><span class="n">b</span><span class="p">)</span> <span class="k">return</span> <span class="n">a</span><span class="p">;</span>
<span class="k">else</span> <span class="k">return</span> <span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"numtri.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"numtri.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">r</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">;</span>
<span class="kt">long</span> <span class="n">m</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">memset</span><span class="p">(</span><span class="n">num</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">num</span><span class="p">));</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">r</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">r</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">num</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">+=</span><span class="n">max</span><span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]);</span>
<span class="p">}</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">r</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">r</span><span class="p">][</span><span class="n">i</span><span class="p">]</span><span class="o">></span><span class="n">m</span><span class="p">)</span> <span class="n">m</span><span class="o">=</span><span class="n">num</span><span class="p">[</span><span class="n">r</span><span class="p">][</span><span class="n">i</span><span class="p">];</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">m</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
USACO Arithmetic Progressions
2010-03-30T05:15:50+00:00
http://greenmooon55.com/usaco-arithmetic-progressions
<p>时间限制为5秒。。
Test 1: TEST OK [0.000 secs, 1952 KB]
Test 2: TEST OK [0.000 secs, 1952 KB]
Test 3: TEST OK [0.011 secs, 1956 KB]
Test 4: TEST OK [0.011 secs, 1956 KB]
Test 5: TEST OK [0.011 secs, 1956 KB]
Test 6: TEST OK [0.162 secs, 1956 KB]
Test 7: TEST OK [2.106 secs, 1960 KB]
Test 8: TEST OK [4.752 secs, 1952 KB]
Test 9: TEST OK [4.352 secs, 1952 KB]</p>
<p>先搜公差再搜首项就不用排序了。。显然速度很慢。4.752s…</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/*
ID: djgreen1
LANG: C
PROB: ariprog
*/
#include <stdio.h>
#include <stdbool.h>
int main()
{
long n,m,i,j,mm,nn,a,b;
FILE *in=fopen("ariprog.in","r"),*out=fopen("ariprog.out","w");
bool bisquare[125001],find,none=true;
memset(bisquare,false,sizeof(bisquare));
fscanf(in,"%d%d",&n;,&m;);
for (i=0;i<=m;i++)
for (j=i;j<=m;j++) bisquare[i*i+j*j]=true;
mm=m*m;
for (b=1;b<=mm;b++)
{
nn=m*m*2-b*(n-1);
for (a=0;a<=nn;a++)
{
if (bisquare[a])
{
find=true;
for (i=n-1;i>0;i--)
if (!bisquare[a+b*i])
{
find=false;
break;
}
if (find)
{
fprintf(out,"%d %d\n",a,b);
none=false;
}
}
}
}
if (none) fprintf(out,"NONE\n");
fclose(in);
fclose(out);
}
```
</code></pre></div></div>
USACO Packing Rectangles
2010-03-27T02:13:37+00:00
http://greenmooon55.com/usaco-packing-rectangles
<p>这题真BT…….
题解:<a href="http://starforever.blog.hexun.com/2097115_d.html">http://starforever.blog.hexun.com/2097115_d.html</a>
自己最开始毫无头绪,上网搜了题解。。
最后一种情况要仔细考虑,每个矩形还要翻转。。
还要注意输出。</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/*
ID: djgreen1
LANG: C
PROB: packrec
*/
#include <stdio.h>
#include <stdbool.h>
struct box
{
int h,w;
};
struct box rectangle[6],rect[6],ans[6];
bool used[6],ro[6];
int p,s=10000,w,h;
int max(int a,int b)
{
if (a>b) return a;
else return b;
}
void judge()
{
int i,j,temp;
if (w>h)
{
temp=w;
w=h;
h=temp;
}
if (w*h<=s)
{
if (w*h==s)
{
for (i=1;i<=p;i++)
if (w==ans[i].w) return;
for (i=1;i<=p;i++)
if (w<ans[i].w)
{
for (j=p+1;j>i;j--)ans[j]=ans[j-1];
ans[i].w=w;
ans[i].h=h;
p++;
return;
}
p++;
ans[p].h=h;
ans[p].w=w;
}
else
{
s=w*h;
p=1;
ans[p].h=h;
ans[p].w=w;
}
}
}
void work()
{
//Case 1
w=rect[1].w+rect[2].w+rect[3].w+rect[4].w;
h=max(rect[1].h,rect[2].h);
h=max(h,rect[3].h);
h=max(h,rect[4].h);
judge();
//Case 2
w=max(rect[1].w+rect[2].w+rect[3].w,rect[4].w);
h=max(rect[1].h,rect[2].h);
h=max(h,rect[3].h);
h+=rect[4].h;
judge();
//Case 3
w=max(rect[1].w+rect[2].w,rect[3].w)+rect[4].w;
h=max(max(rect[1].h,rect[2].h)+rect[3].h,rect[4].h);
judge();
//Case 4
w=rect[1].w+max(rect[2].w,rect[3].w)+rect[4].w;
h=max(rect[1].h,rect[4].h);
h=max(h,rect[2].h+rect[3].h);
judge();
//Case 6
if (rect[3].h>=rect[2].h+rect[4].h)
{
w=max(rect[3].w+rect[2].w,rect[3].w+rect[4].w);
w=max(w,rect[1].w);
h=rect[1].h+rect[3].h;
judge();
return;
}
if (rect[3].h>rect[4].h)
{
w=max(rect[1].w+rect[2].w,rect[2].w+rect[3].w);
w=max(w,rect[4].w+rect[3].w);
h=max(rect[1].h+rect[3].h,rect[2].h+rect[4].h);
judge();
return;
}
if (rect[3].h==rect[4].h)
{
w=max(rect[1].w+rect[2].w,rect[3].w+rect[4].w);
h=max(rect[1].h,rect[2].h)+rect[3].h;
judge();
return;
}
if (rect[3].h<rect[4].h && rect[4].h<rect[3].h+rect[1].h)
{
w=max(rect[1].w+rect[2].w,rect[1].w+rect[4].w);
w=max(w,rect[3].w+rect[4].w);
h=max(rect[1].h+rect[3].h,rect[2].h+rect[4].h);
judge();
return;
}
w=max(rect[2].w,rect[1].w+rect[4].w);
w=max(w,rect[3].w+rect[4].w);
h=rect[4].h+rect[2].h;
judge();
}
void exchange(int i)
{
int temp;
temp=rect[i].h;
rect[i].h=rect[i].w;
rect[i].w=temp;
}
void rotate(int depth)
{
if (depth==5)
{
work();
return;
}
if (!ro[depth])
{
ro[depth]=true;
exchange(depth);
rotate(depth+1);
ro[depth]=false;
exchange(depth);
rotate(depth+1);
}
}
void search(int depth)
{
int i;
if (depth==5)
{
rotate(1);
return;
}
for (i=1;i<5;i++)
{
if (!used[i])
{
rect[depth]=rectangle[i];
used[i]=true;
search(depth+1);
used[i]=false;
}
}
}
int main()
{
int i;
FILE *in=fopen("packrec.in","r"),*out=fopen("packrec.out","w");
memset(ans,0,sizeof(ans));
for (i=1;i<5;i++) fscanf(in,"%d%d",&rectangle;[i].h,&rectangle;[i].w);
fclose(in);
search(1);
fprintf(out,"%d\n",s);
for (i=1;i<=p;i++)
{
fprintf(out,"%d %d\n",ans[i].w,ans[i].h);
}
fclose(out);
}
```
</code></pre></div></div>
USACO Prime Cryptarithm
2010-03-25T11:12:51+00:00
http://greenmooon55.com/usaco-prime-cryptarithm
<p>额 字母很乱。。。</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code> i j k
x a b
_______________
e d c
h g f
_______________
n m l
```
```c
/*
ID: djgreen1
LANG: C
PROB: crypt1
*/
#include <stdio.h>
#include <stdbool.h>
int main()
{
int i,j,k,a,b,c,d,e,f,g,h,l,m,n,ans=0,num;
bool digit[10];
FILE *in=fopen("crypt1.in","r"),*out=fopen("crypt1.out","w");
fscanf(in,"%d",&num;);
memset(digit,0,sizeof(digit));
for (i=0;i<num;i++)
{
fscanf(in,"%d",&j;);
digit[j]=true;
}
for (i=1;i<10;i++)
{
if (!digit[i]) continue;
for (j=0;j<10;j++)
{
if (!digit[j]) continue;
for (k=0;k<10;k++)
{
if (!digit[k]) continue;
for (a=1;a<10;a++)
{
if (!digit[a]) continue;
for (b=0;b<10;b++)
{
if (!digit[b]) continue;
c=k*b;
d=c/10;
c=c%10;
if (!digit[c]) continue;
d+=b*j;
e=d/10;
d=d%10;
if (!digit[d]) continue;
e+=b*i;
if (e>9 || e==0 || !digit[e]) continue;
f=a*k;
g=f/10;
f=f%10;
if (!digit[f]) continue;
g+=a*j;
h=g/10;
g=g%10;
if (!digit[g]) continue;
h+=a*i;
if (h>9 || h==0 || !digit[h]) continue;
l=d+f;
m=l/10;
l=l%10;
if (!digit[l]) continue;
m+=e+g;
n=m/10;
m=m%10;
if (!digit[m]) continue;
n+=h;
if (n>9 || n==0 || !digit[n]) continue;
ans++;
}
}
}
}
}
fprintf(out,"%d\n",ans);
fclose(in);
fclose(out);
}
```
</code></pre></div></div>
USACO Calf Flac
2010-03-24T13:45:48+00:00
http://greenmooon55.com/usaco-calf-flac
<p>从前面一个一个搜就行,枚举回文串的中点,注意奇偶两种情况。
Test 1: TEST OK [0.000 secs, 1956 KB]
Test 2: TEST OK [0.000 secs, 1952 KB]
Test 3: TEST OK [0.011 secs, 1948 KB]
Test 4: TEST OK [0.000 secs, 1948 KB]
Test 5: TEST OK [0.011 secs, 1952 KB]
Test 6: TEST OK [0.011 secs, 1952 KB]
Test 7: TEST OK [0.011 secs, 1952 KB]
Test 8: TEST OK [0.076 secs, 1952 KB]
今天折腾了好久,好几个IDE都弄不好。。
</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/*
ID: djgreen1
LANG: C
PROB: calfflac
*/
#include <stdio.h>
#include <stdbool.h>
bool compare(char ch1,char ch2)
{
if (ch1==ch2 || (int)ch1+32==ch2 || (int)ch2+32==ch1) return true;
else return false;
}
int main()
{
char code[20001],temp,real[20001];
int i,j,sum,a,length,ans,tempbegin,tempend,p[20001];
FILE *in=fopen("calfflac.in","r"),*out=fopen("calfflac.out","w");
i=0;
j=0;
while (fscanf(in,"%c",&code;[i])!=EOF)
{
if (((int)code[i]>64 && (int)code[i]<91) || ((int)code[i]>96 && (int)code[i]<123))
{
real[j]=code[i];
p[j]=i;
j++;
}
i++;
}
ans=0;
for (a=0;a<j;a++)
{
length=1;
while (a-length>=0 && a+length<j)
{
if (compare(real[a-length],real[a+length])) length++;
else break;
}
if (length*2-1>ans)
{
ans=length*2-1;
tempbegin=a-length+1;
tempend=a+length-1;
}
length=0;
while (a-length>=0 && a+length+1<j)
{
if (compare(real[a-length],real[a+length+1])) length++;
else break;
}
if (length*2>ans)
{
ans=length*2;
tempbegin=a-length+1;
tempend=a+length;
}
}
fprintf(out,"%d\n",ans);
for(a=p[tempbegin];a<=p[tempend];a++) fprintf(out,"%c",code[a]);
fprintf(out,"\n");
fclose(in);
fclose(out);
}
```
</code></pre></div></div>
谷歌再见
2010-03-23T07:33:33+00:00
http://greenmooon55.com/goodbye-googlecn
<p>谷歌为什么要退出:</p>
<ol>
<li>
<p><strong>极光行动</strong>(<a href="http://zh.wikipedia.org/wiki/%E8%8B%B1%E8%AF%AD">英语</a>:Operation Aurora) 或<strong>欧若拉行动</strong>是2009年12月中旬可能源自<a href="http://zh.wikipedia.org/wiki/%E4%B8%AD%E5%9B%BD">中国</a>的 一场<a href="http://zh.wikipedia.org/w/index.php?title=%E7%BD%91%E7%BB%9C%E6%94%BB%E5%87%BB&action=edit&redlink=1">网络攻击</a>(英语:<a href="http://en.wikipedia.org/wiki/cyber_attack">cyber attack</a>)<a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-0">[1]</a>, 其名称“Aurora”(意为<a href="http://zh.wikipedia.org/wiki/%E6%9E%81%E5%85%89">极光</a>、<a href="http://zh.wikipedia.org/wiki/%E6%AC%A7%E8%8B%A5%E6%8B%89">欧若拉</a>)来自攻击者电脑上恶意文件所在路径的一部分<a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-mcafee-1">[2]</a>。 遭受攻击的除了<a href="http://zh.wikipedia.org/wiki/Google">Google</a><a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-googleblog-2">[3]</a>外, 还有20多家公司:其中包括<a href="http://zh.wikipedia.org/wiki/Adobe_Systems">Adobe Systems</a><a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-3">[4]</a>、<a href="http://zh.wikipedia.org/wiki/Juniper_Networks">Juniper Networks</a><a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-4">[5]</a>、<a href="http://zh.wikipedia.org/w/index.php?title=Rackspace&action=edit&redlink=1">Rackspace</a><a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-5">[6]</a>、<a href="http://zh.wikipedia.org/wiki/%E9%9B%85%E8%99%8E">雅虎</a>、<a href="http://zh.wikipedia.org/wiki/%E8%B5%9B%E9%97%A8%E9%93%81%E5%85%8B">赛门铁克</a>、<a href="http://zh.wikipedia.org/wiki/%E8%AF%BA%E6%96%AF%E6%B4%9B%E6%99%AE%C2%B7%E6%A0%BC%E9%B2%81%E9%97%A8">诺斯洛普·格鲁门</a>和<a href="http://zh.wikipedia.org/wiki/%E9%99%B6%E6%B0%8F%E5%8C%96%E5%B7%A5">陶氏化工</a><a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-wapo-6">[7]</a>。 这场攻击过后,Google提出了它的新计划:它将“在必要的法律范围内”<a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-withinthelaw-7">[8]</a>, 于中国运营一个完全不受过滤的搜索引擎;同时Google也承认,如果该计划不可实现,它将可能离开中国并关闭它在中国的办事处<a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8#_note-googleblog-2">[3]</a>。 via <a href="http://zh.wikipedia.org/zh-cn/%E6%9E%81%E5%85%89%E8%A1%8C%E5%8A%A8">维基百科</a></p>
</li>
<li>
<p>有证据表明数十位与中国有关的人权活动人士的Gmail帐户经常被第三方侵入</p>
</li>
<li>
<p>过去一年中试图进一步限制在华网络言论自由的企图,包括持续不断的屏蔽Facebook、Twitter、YouTube、Google Docs和Blogger等网站</p>
</li>
<li>
<p>中国政府已经非常明确地表示,自我审查是一项没有商量余地的法律要求。</p>
</li>
</ol>
<p>2, 3, 4 来自谷歌声明<a href="http://googleblog.blogspot.com/2010/03/new-approach-to-china-update.html">原文</a>华尔街日报<a href="http://cn.wsj.com/gb/20100323/tec090754.asp">译稿</a>。<strong>更新:<a href="http://www.google.com/press/new-approach-to-china/update.html">Google官方中文版声明</a></strong></p>
<p>“据当地法律法规和政策,部分搜索结果未予显示”** ——谁知道是哪部法律哪条规定了哪些结果不能显示<strong>?
在哪个国家,访问某些网站会出现</strong>连接超时<strong>和</strong>连接被重置**?
在哪个国家,建立个人网站需要备案,<a href="http://tech.sina.com.cn/i/2010-02-23/09363872278.shtml">需至IDC处当面拍照核验身份等备案资料才可能予以通过</a>?
在哪个国家,<a href="http://epaper.nddaily.com/A/html/2009-12/24/content_975754.htm">没有100万就不要在网上开论坛</a>?(海子铁路网、铁路在线论坛等等)
在哪个国家,查处一个网站,会<a href="http://www.ruanyifeng.com/blog/2009/12/should_isp_bear_joint_liabilities.html">株连整个机房</a>?
在哪个国家,域名可以被随意<a href="http://www.google.com.hk/search?hl=zh-CN&q=%D3%F2%C3%FB%CD%A3%D6%B9%BD%E2%CE%F6">停止解析</a>?
在哪个国家,工信部会花<a href="http://www.caijing.com.cn/2009-06-09/110179990.html">四千万</a>采购<a href="http://zh.wikipedia.org/zh-cn/%E7%B6%A0%E5%A3%A9%C2%B7%E8%8A%B1%E5%AD%A3%E8%AD%B7%E8%88%AA">绿坝</a>?</p>
<p>译言、<a href="http://blogbus.blogbus.com/logs/56241385.html">BlogBus</a>活了过来,Yo2已死。其实还有很多网站。。</p>
<p><a href="http://greenmoon55.com/goodbye-googlecn/dscf1330/"><img src="http://greenmoon55.com/wp-content/uploads/2010/03/DSCF1330-600x450.jpg" alt="" /></a></p>
<p><a href="http://greenmoon55.com/goodbye-googlecn/dscf1330/"></a><a href="http://greenmoon55.com/goodbye-googlecn/dscf1331/"><img src="http://greenmoon55.com/wp-content/uploads/2010/03/DSCF1331-600x450.jpg" alt="" /></a></p>
<p>图片拍摄于2010年1月15日 清华科技园谷歌中国办事处</p>
<p>www.google.com.hk 其实和 www.google.com的简体中文搜索没什么区别吧,中国大陆访问Google香港仍存在关键词重置,显然Google香港在墙外。
“www.google.com.hk”会成为敏感词吗?谁知道呢?“你是互联网,我是防火墙”,防火墙会存在多久呢?
“我们计划继续在中国的研发工作” 希望谷歌拼音和谷歌音乐搜索能留住^_^</p>
<p>译言被封时看到:<strong>“当初我们学英语是为了了解世界,如今我们学英语是为了了解中国。”</strong></p>
<p>PS:Tweet: 您的QQ帐号受到临时登录限制!RT: <a href="http://twitter.fishnote.net/user.php?id=rtmeme">@rtmeme</a>: RT <a href="http://twitter.fishnote.net/user.php?id=Gackiliang">@Gackiliang</a> RT <a href="http://twitter.fishnote.net/user.php?id=4zai">@4zai</a>: 大家把QQ签名改成 “欢迎您来到谷歌搜索在中国的新家”,改完后下线,再上线,看看有啥效果?</p>
<p>//在网上发言要注意人身安全,包括但不限于QQ、MSN、<a href="http://government.zdnet.com/?p=4063">Tom-Skype</a>、各大论坛、校内等SNS。。</p>
<p>PS:<a href="http://cn.wsj.com/gb/20100323/bch123454.asp">香港政府:不会审查网络内容,尊重资讯自由</a>??
PS:<a href="http://www.google.com/prc/report.html">中国大陆对Google各项服务封锁</a>
PS:2006年的<a href="http://googlechinablog.com/gugeflash.swf">谷歌宣传动画</a>。</p>
<p>Google在2006年推出Google.cn时<a href="http://googleblog.blogspot.com/2006/01/google-in-china.html">就说</a>“Filtering our search results clearly compromises our mission”。为了用户的安全,<strong>Google在中国没有存放用户数据</strong>,因此谷歌音乐甚至不能用Gmail账户<a href="http://www.google.cn/music/selector">登录</a>。
遗憾的是,谷歌的离开没能让所有中国网民了解事情的经过,国内媒体不得不报道谷歌的负面新闻。</p>
<p>今天是2010年3月23日。</p>
<p>**Update @ 10:32 2010/3/24 **疑似google.com.hk/search成为敏感词。</p>
<p>**Update @ 10:42 2010/3/24 **现已恢复正常</p>
<p>**Update @ 23:41 2010/3/24 **<a href="http://twaud.io/5cy">#323candlelight 音频</a></p>
USACO Barn Repair
2010-03-22T15:21:04+00:00
http://greenmooon55.com/usaco-barn-repair
<p>这题做得真纠结,第五次才AC。
刚想起来其实排序可以优化一点点。。
输入数据不是有序的,要先排序!我的算法就是先铺上木板再去掉最大的那几个空隙。
前后改来改去,写得很乱。还要注意m很大的情况。</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/*
ID: djgreen1
LANG: C
PROB: barn1
*/
#include <stdio.h>
int main()
{
int m,s,c,num[200],data[200],first,i,j,p=1,pnum=0,a,sum,gap,t;
FILE *in=fopen("barn1.in","r"),*out=fopen("barn1.out","w");
fscanf(in,"%d%d%d",&m;,&s;,&c;);
for(i=1;i<=c;i++) fscanf(in,"%d",&data;[i]);
//sort
for(i=1;i<c;i++)
for(j=1;j<c;j++) if (data[j]>data[j+1])
{
t=data[j+1];
data[j+1]=data[j];
data[j]=t;
}
first=data[1];
a=first;
for(i=2;i<=c;i++)
{
if (data[i]>i-p+first)
{
gap=data[i]-(i-p+first);
num[pnum]=gap;
pnum++;
first=data[i];
p=i;
}
}
//sort
for(i=pnum-1;i>0;i--)
for(j=pnum-1;j>0;j--) if (num[j]>num[j-1])
{
t=num[j-1];
num[j-1]=num[j];
num[j]=t;
}
sum=data[c]-a+1;
if (m>pnum+1) m=pnum+1;
for(i=0;i<m-1;i++) sum=sum-num[i];
fprintf(out,"%d\n",sum);
fclose(in);
fclose(out);
}
```
</code></pre></div></div>
USACO Mixing Milk
2010-03-20T08:25:41+00:00
http://greenmooon55.com/usaco-mixing-milk
<p>快排+贪心,还要注意0 0的情况。。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
PROB: milk
*/</span>
<span class="cp">#include
</span><span class="kt">long</span> <span class="n">a</span><span class="p">[</span><span class="mi">5000</span><span class="p">],</span><span class="n">p</span><span class="p">[</span><span class="mi">5000</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">qsort</span><span class="p">(</span><span class="kt">int</span> <span class="n">l</span><span class="p">,</span><span class="kt">int</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">pivot</span><span class="p">;</span>
<span class="kt">long</span> <span class="n">temp</span><span class="p">;</span>
<span class="n">i</span><span class="o">=</span><span class="n">l</span><span class="p">;</span>
<span class="n">j</span><span class="o">=</span><span class="n">r</span><span class="p">;</span>
<span class="n">pivot</span><span class="o">=</span><span class="n">p</span><span class="p">[</span><span class="n">rand</span><span class="p">()</span><span class="o">%</span><span class="p">(</span><span class="n">r</span><span class="o">-</span><span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="n">l</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">i</span><span class="o"><</span><span class="n">j</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o"><</span><span class="n">pivot</span><span class="p">)</span> <span class="n">i</span><span class="o">++</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">></span><span class="n">pivot</span><span class="p">)</span> <span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o"><=</span><span class="n">j</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">temp</span><span class="o">=</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">p</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="n">temp</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="n">i</span><span class="o">++</span><span class="p">;</span>
<span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span><span class="o">></span><span class="n">l</span><span class="p">)</span> <span class="n">qsort</span><span class="p">(</span><span class="n">l</span><span class="p">,</span><span class="n">j</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o"><</span><span class="n">r</span><span class="p">)</span> <span class="n">qsort</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">r</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"milk.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"milk.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">long</span> <span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">milk</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">price</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;,</span><span class="o">&</span><span class="n">m</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"0</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">m</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">p</span><span class="p">;[</span><span class="n">i</span><span class="p">],</span><span class="o">&</span><span class="n">a</span><span class="p">;[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="n">srand</span><span class="p">(</span><span class="n">time</span><span class="p">(</span><span class="nb">NULL</span><span class="p">));</span>
<span class="n">qsort</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">m</span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">m</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">milk</span><span class="o">+</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o"><</span><span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">milk</span><span class="o">+=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">price</span><span class="o">+=</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">*</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="n">price</span><span class="o">+=</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="n">milk</span><span class="p">)</span><span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">price</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
USACO Dual Palindromes
2010-03-19T11:50:12+00:00
http://greenmooon55.com/usaco-dual-palindromes
<p>昨天做的,本来以为很快就能打完。原来是“if (ispal()) sum++;”忘记打ispal的括号了。。调了很久,ispal返回值一直是一个固定的大数。调好后USACO就挂了。。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
PROB: dualpal
*/</span>
<span class="cp">#include
#include
</span>
<span class="kt">int</span> <span class="n">p</span><span class="p">,</span><span class="n">new</span><span class="p">[</span><span class="mi">20</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">convert</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="kt">int</span> <span class="n">base</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">p</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="nb">true</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">new</span><span class="p">[</span><span class="n">p</span><span class="p">]</span><span class="o">=</span><span class="n">num</span><span class="o">%</span><span class="n">base</span><span class="p">;</span>
<span class="n">num</span><span class="o">=</span><span class="n">num</span><span class="o">/</span><span class="n">base</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
<span class="n">p</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">bool</span> <span class="nf">ispal</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">j</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">p</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">new</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">!=</span><span class="n">new</span><span class="p">[</span><span class="n">p</span><span class="o">-</span><span class="n">j</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">return</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"dualpal.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"dualpal.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">sum</span><span class="p">,</span><span class="n">find</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">i</span><span class="p">;</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;,</span><span class="o">&</span><span class="n">s</span><span class="p">;);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">find</span><span class="o"><</span><span class="n">n</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">s</span><span class="o">++</span><span class="p">;</span>
<span class="n">sum</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">2</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="mi">10</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">convert</span><span class="p">(</span><span class="n">s</span><span class="p">,</span><span class="n">i</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ispal</span><span class="p">())</span> <span class="n">sum</span><span class="o">++</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sum</span><span class="o">==</span><span class="mi">2</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">s</span><span class="p">);</span>
<span class="n">find</span><span class="o">++</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
USACO Palindromic Squares
2010-03-17T05:30:23+00:00
http://greenmooon55.com/usaco-palindromic-squares
<p>“We generate all the squares from 1 to 300 and check to see which are palindromes. “
慢慢算就是了~不过不太熟悉C的函数、过程什么的,没用到。</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/*
ID: djgreen
LANG: C
PROB: palsquare
*/
#include <stdio.h>
#include <stdbool.h>
const char s[20]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
int main()
{
FILE *in=fopen("palsquare.in","r"),*out=fopen("palsquare.out","w");
int base,n,new[17],old[17],p,p2,i,temp;
long num;
bool find;
fscanf(in,"%d",&base;);
fclose(in);
for (n=1;n<=300;n++)
{
num=n*n;
//convert(num)
p=0;
while (true)
{
new[p]=num%base;
num=num/base;
if (num==0) break;
p++;
}
//palindromic?
p2=0;
find=true;
for (i=0;i<=p;i++)
{
if (new[i]!=new[p-i])
{
find=false;
break;
}
}
if (find)
{
temp=n;
while (true)
{
old[p2]=temp%base;
temp=temp/base;
if (temp==0) break;
p2++;
}
for (i=p2;i>=0;i--) fprintf(out,"%c",s[old[i]]);
fprintf(out," ");
for (i=0;i<=p;i++) fprintf(out,"%c",s[new[i]]);
fprintf(out,"\n");
}
}
fclose(out);
}
```
</code></pre></div></div>
USACO Name That Number
2010-03-15T16:46:28+00:00
http://greenmooon55.com/usaco-name-that-number
<p>逆向思维,读入词典中与数字长度相同的名字,再把名字转化为数字一位一位比较。
学到了:switch, case, strlen()。
<strong>UPDATE @ 2010/3/16 0:55</strong>
<strong>看USACO给的答案,其实是可以读一个处理一个不开数组的。。。懒得改了</strong></p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
TASK: namenum
LANG: C
ID: djgreen1
*/</span>
<span class="cp">#include
#include
#include
</span><span class="kt">char</span> <span class="nf">work</span><span class="p">(</span><span class="kt">char</span> <span class="n">ch</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">switch</span> <span class="p">(</span><span class="n">ch</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">case</span> <span class="sc">'A'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'B'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'C'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'2'</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'D'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'E'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'F'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'3'</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'G'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'H'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'I'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'4'</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'J'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'K'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'L'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'5'</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'M'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'N'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'O'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'6'</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'P'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'R'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'S'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'7'</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'T'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'U'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'V'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'8'</span><span class="p">;</span>
<span class="k">case</span> <span class="sc">'W'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'X'</span><span class="p">:</span><span class="k">case</span> <span class="sc">'Y'</span><span class="p">:</span> <span class="k">return</span> <span class="sc">'9'</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">char</span> <span class="n">num</span><span class="p">[</span><span class="mi">13</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">},</span><span class="n">dict</span><span class="p">[</span><span class="mi">5000</span><span class="p">][</span><span class="mi">13</span><span class="p">],</span><span class="n">temp</span><span class="p">[</span><span class="mi">13</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"namenum.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">txt</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"dict.txt"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"namenum.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">length</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">;</span>
<span class="n">bool</span> <span class="n">find</span><span class="p">,</span><span class="n">none</span><span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%s"</span><span class="p">,</span><span class="n">num</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="n">length</span><span class="o">=</span><span class="n">strlen</span><span class="p">(</span><span class="n">num</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">fscanf</span><span class="p">(</span><span class="n">txt</span><span class="p">,</span><span class="s">"%s"</span><span class="p">,</span><span class="n">temp</span><span class="p">)</span><span class="o">!=</span><span class="n">EOF</span><span class="p">;)</span><span class="c1">//find name with the same length
</span> <span class="k">if</span> <span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">temp</span><span class="p">)</span><span class="o">==</span><span class="n">length</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o"><</span><span class="n">length</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span><span class="n">dict</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">i</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">txt</span><span class="p">);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o"><</span><span class="n">i</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span><span class="c1">//start comparation
</span> <span class="p">{</span>
<span class="n">find</span><span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o"><</span><span class="n">length</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">work</span><span class="p">(</span><span class="n">dict</span><span class="p">[</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">])</span><span class="o">!=</span><span class="n">num</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">find</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span>
<span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">find</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">none</span><span class="o">=</span><span class="nb">false</span><span class="p">;</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">dict</span><span class="p">[</span><span class="n">j</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">none</span><span class="p">)</span> <span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"NONE</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
USACO Transformations
2010-03-14T11:31:28+00:00
http://greenmooon55.com/usaco-transformations
<p>这题当时(08年!)没做,有点麻烦,数据才10*10,慢慢算就行。
PS:从Dev-C++换到了Code:Blocks,前者调试时很费劲,容易崩溃。适应中…
看F1去鸟^_^</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/*
ID: djgreen1
LANG: C
PROB: transform
*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
int main()
{
int n,i,j;
char s1[11][11]={0},s2[11][11]={0};
bool skip;
FILE *in=fopen("transform.in","r"),*out=fopen("transform.out","w");
skip=false;
fscanf(in,"%d\n",&n;);
for (i=0;i<n;i++) fscanf(in,"%s\n",s1[i]);
for (i=0;i<n;i++) fscanf(in,"%s\n",s2[i]);
//Case 1
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s1[i][j]!=s2[j][n-i-1])
{
skip=true;
break;
}
if (skip) break;
}
if (!skip)
{
fprintf(out,"1\n");
return 0;
}
//Case 2
skip=false;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s1[i][j]!=s2[n-i-1][n-j-1])
{
skip=true;
break;
}
if (skip) break;
}
if (!skip)
{
fprintf(out,"2\n");
return 0;
}
//Case 3
skip=false;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s2[i][j]!=s1[j][n-i-1])
{
skip=true;
break;
}
if (skip) break;
}
if (!skip)
{
fprintf(out,"3\n");
return 0;
}
//Case 4
skip=false;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s1[i][j]!=s2[i][n-j-1])
{
skip=true;
break;
}
if (skip) break;
}
if (!skip)
{
fprintf(out,"4\n");
return 0;
}
//Case 5
skip=false;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s1[i][n-j-1]!=s2[j][n-i-1])
{
skip=true;
break;
}
if (skip) break;
}
if (skip)
{
skip=false;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s1[i][n-j-1]!=s2[n-i-1][n-j-1])
{
skip=true;
break;
}
if (skip) break;
}
}
if (skip)
{
skip=false;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s2[i][j]!=s1[n-j-1][n-i-1])
{
skip=true;
break;
}
if (skip) break;
}
}
if (!skip)
{
fprintf(out,"5\n");
return 0;
}
//Case 6
skip=false;
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
if (s1[i][j]!=s2[i][j])
{
skip=true;
break;
}
if (skip) break;
}
if (!skip) fprintf(out,"6\n");
else fprintf(out,"7\n");
return 0;
}
```
</code></pre></div></div>
Greedy Gift Givers
2010-03-08T12:56:23+00:00
http://greenmooon55.com/greedy-gift-givers
<p>身体不太舒服,这题弄了好久。。
学到了:={0}好像可以初始化,strcmp是比较字符串的函数,相等时值为0。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
TASK: gift1
*/</span>
<span class="cp">#include
</span><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">money</span><span class="p">[</span><span class="mi">11</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">},</span><span class="n">give</span><span class="p">,</span><span class="n">num</span><span class="p">,</span><span class="n">income</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">name</span><span class="p">[</span><span class="mi">11</span><span class="p">][</span><span class="mi">15</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">},</span><span class="n">people</span><span class="p">[</span><span class="mi">15</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"gift1.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"gift1.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%s"</span><span class="p">,</span><span class="n">name</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%s"</span><span class="p">,</span><span class="n">people</span><span class="p">);</span>
<span class="k">for</span><span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">j</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">people</span><span class="p">,</span><span class="n">name</span><span class="p">[</span><span class="n">j</span><span class="p">]))</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">income</span><span class="p">;,</span><span class="o">&</span><span class="n">num</span><span class="p">;);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">num</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">give</span><span class="o">=</span><span class="n">income</span><span class="o">/</span><span class="n">num</span><span class="p">;</span>
<span class="n">money</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">money</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">-</span><span class="n">give</span><span class="o">*</span><span class="n">num</span><span class="p">;</span>
<span class="k">for</span><span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">num</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%s"</span><span class="p">,</span><span class="n">people</span><span class="p">);</span>
<span class="k">for</span><span class="p">(</span><span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">strcmp</span><span class="p">(</span><span class="n">people</span><span class="p">,</span><span class="n">name</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span> <span class="k">break</span><span class="p">;</span>
<span class="n">money</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">=</span><span class="n">money</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">+</span><span class="n">give</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%s %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">name</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">money</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
Hello World
2010-03-01T13:47:28+00:00
http://greenmooon55.com/hello-world
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cp">#include
</span><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"Hello World!"</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
<p>参照M67牛的<a href="http://www.matrix67.com/blog/archives/216">文章</a>P转C中,至少要达到NOIP2008时的水平..
OIBH上不去了。。
3月了,开始了。</p>
<p>Feedsky验证:f05de917
豆瓣验证:doubanclaim41f15eeec11d235d
QQ验证:QQREADERB9DD86B9C9B08813</p>
Wordbook20100224
2010-02-24T12:41:59+00:00
http://greenmooon55.com/wordbook20100224
<p><a href="http://techcrunch.com/2010/02/23/eu-antitrust-google-microsoft/">TechCrunch: EU Opens Antitrust Investigation Into Google. Microsoft’s Fingerprints Are Everywhere.</a></p>
<p>antitrust
adj. 反托拉斯的,反垄断的
open an antitrust investigation</p>
<p>be dominated by</p>
<p>come of
由 … 引起,来自 …
nothing may come of it</p>
<p>file a complaint
提出控告,进行投诉
file [Tn] send (sth) so that it may be recorded 送交(某物)以便备案; 提交</p>
<p>notably
显著地,值得注意地,特别地
and notably, one of them is owned by Microsoft.</p>
<p>ballot [ˈbælət]
[U, C] the system of voting in writing and usually in secret; an occasion on which a vote is held
n.投票;投票总数;选票 v.投票表决
1 [I, Ipr] ~ (for sb/sth) vote by ballot (for sb/sth) 以无记名投票方式(对某人[某事物])进行表决.
2 [Tn, Tn.pr] ~ sb (about/on sth) cause sb to vote (on sth) secretly 使某人以无记名方式投票表决(某事物): The union balloted its members on the proposed changes. 工会让会员们以无记名方式就所建议的改革进行表决.
IE ballot screen</p>
<p>ongoing
adj [esp attrib 尤作定语] continuing to exist or progress 继续存在的; 进行中的: an ongoing debate</p>
<p><a href="http://techcrunch.com/2010/02/23/twitter-ads-look-like-love/">TechCrunch: What Should Twitter Ads Look Like? And Will You Really Love Them?</a></p>
<p>fascinating
extremely interesting
a.迷人的,有极大吸引力的</p>
<p>revenue
1 money that a business or organization receives over a period of time, especially from selling goods or services
→income
advertising revenue
Strikes have cost £20 million in lost revenues .
2 money that the government receives from tax
an increase in tax revenues of 8.4%
advertising revenue models</p>
<p>grill
v.烧烤;拷问 n.烤架;烧烤餐馆;烤肉;格板
The police grilled him (with non-stop questions) for over an hour.
SocialMedia, was on the same panel and is the one who grilled Banerji about Twitter’s ad plans.</p>
<p>disclose
vt.揭露,泄露,透露</p>
<p>authentic<br />
1 known to be true or genuine 真实的; 真正的
2 trustworthy; reliable 可信的; 可靠的: an authentic statement 可靠的陈述.</p>
<p>Contextual ads
contextual: relating to a particular context</p>
神奇的百度
2010-02-22T06:52:58+00:00
http://greenmooon55.com/interesting-baidu
<p>某天不经意间在百度搜了“拆迁”,第一页惊现三个本地结果,用SSH再搜索就没有了。</p>
<p>这是第四条以后的对比图:
<a href="http://greenmoon55.com/interesting-baidu/attachment/20100222142910607/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100222142910607.png" alt="" /></a><a href="http://greenmoon55.com/interesting-baidu/attachment/20100222142921345/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100222142921345.png" alt="" /></a></p>
<p>既然百度有这个功能,为什么不高调宣传呢?能不能提供地理位置的选项呢?还有就是昨晚想写这个,结果发现没有本地结果了。。今天又有了。(记得某天在Twitter上看到说百度的广告也是分地域投放的)</p>
<p>某天,百度通知我知道上的回答被采纳了,可我已经有很久没去知道回答问题了啊,打开<a href="http://zhidao.baidu.com/question/19012891.html">问题</a>一看,原来是我在2007-1-25 21:00回答的。。这个提问者在大约三年后才采纳。</p>
<p><a href="http://greenmoon55.com/interesting-baidu/attachment/20100222145028502/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100222145028502.png" alt="" /></a></p>
1000 tweets
2010-02-21T10:17:00+00:00
http://greenmooon55.com/1000-tweets
<p><a href="http://greenmoon55.com/1000-tweets/attachment/20100221151944930/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100221151944930.png" alt="" /></a></p>
<p><a href="http://greenmoon55.com/1000-tweets/attachment/20100221152043007/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100221152043007.png" alt="" /></a></p>
<p>从10:45 PM Oct 1st, 2007在Twitter上发出的第一条tweet “<a href="https://twitter.com/greenmoon55/status/305070872">Testing twitter</a>” 到前几天年三十晚上(8:41 PM Feb 13th)正好发了<a href="https://twitter.com/greenmoon55/status/9053971852">一千条推</a>。最开始我在Twitter上发英文,在饭否上发中文。<a href="https://twitter.com/greenmoon55/status/840149181">后来</a>才在Twitter上发中文。</p>
<p>Twitter从“What are you doing”变成了”What’s Happening?”。我也在Twitter上围观了一些事,比如正虎、谷歌退出、春晚、伊朗。我也发过本地火车出轨的消息,不过我从来没有被RT过。刚才翻我过去的推,感觉有点像日记。Twitter对于我来说,主要是个获取信息的地方,当然我好像有点窥私欲^^
(Update @2010/2/22 15:10 Twitter上的信息很多,有些消息可能是不真实的,别轻易相信,RT前要谨慎。)</p>
<p>Twitter十分开放,你可以不上twitter.com就能注册、发消息、搜索消息等等,中文推特圈这样的网站其实和twitter.com没什么区别了,twitter有很多第三方程序,各大浏览器也都有插件,我就一直在用火狐上的Echofon,在状态栏里用起来很方便。
<a href="http://greenmoon55.com/1000-tweets/attachment/20100221174916808/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100221174916808.png" alt="" /></a></p>
<p>现在各大门户都推出了微博,目前的格局似乎和博客很相似,新浪吸引了一些名人,不过,或许腾讯还能赢,别忘了,TX可以把QQ做成微博的客户端,只要把输入状态的地方稍加改进即可。当然啦,现在的一小撮中文推友一定会坚守在twitter上的。</p>
<p>对于现在的官方RT之争,我的做法是如果不需要评论,则使用官方RT,减少他人负担(如 <strong><a href="https://twitter.com/bbcchinese">bbcchinese</a></strong> 简讯:中朝俄边境发生6.7级地震 <a href="https://twitter.com/bbcchinese/status/9263701893">via</a>)。如果需要评论,不妨使用普通RT,如果完全不需要别人知道,就直接@someone得了,免得打扰别人,比如(@someone 你是哪里人?)。</p>
<p>对了,互相fo的时候不用太认真,我一般要看完一屏tweets再决定是否follow并可能随时unfo。也不必苛求别人和自己所有观点都相同,但如果观点都不同还是取消关注吧。。</p>
<p>欢迎fo我,@<a href="https://twitter.com/greenmoon55">greenmoon55</a>。</p>
Dreamhost Live Chat
2010-02-12T12:34:37+00:00
http://greenmooon55.com/dreamhost-live-chat
<p>The following is a record of your online chat.</p>
<p>General Info</p>
<p><strong>Chat start time</strong></p>
<p>Feb 11, 2010 6:45:03 AM EST</p>
<p><strong>Chat end time</strong></p>
<p>Feb 11, 2010 7:09:39 AM EST</p>
<p><strong>Duration (actual chatting time)</strong></p>
<p>00:24:36</p>
<p><strong>Operator</strong></p>
<p>ChrisL</p>
<p>Chat Transcript</p>
<p>info: Please wait for a site operator to respond.
info: All operators are currently assisting others. Thanks for your patience. An operator will be with you shortly.
info: You are now chatting with ‘ChrisL’
ChrisL: hi, how can I help you?
you: Hello, why can’t I login using putty?
ChrisL: with which user?
you: dongjin
you: Is it my problem?
ChrisL: did you make any changes to the user on the panel recently?
you: It was working well but today it says “access denied”, so I retyped the password on the panel.
you: ?
ChrisL: that change is still reconfiguring
ChrisL: trying to push that through now…
you: not working…
ChrisL: I’m not done yet
ChrisL: okay, try now
you: I just tried, it’s all right now. thanks
ChrisL: good deal
ChrisL: looks like ssh was hung up
info: Your chat transcript will be sent to *** at the end of your chat.
ChrisL: had to restart that and push through the pending user config, so you should be good
you: ok bye</p>
<p>昨晚MyEnTunnel出问题,显示“Connection is stable”10秒后就会中断重连,PuTTY输完密码后显示access denied,看来是DH服务器的问题。这是我第一次Live Chat。</p>
用Sandboxie正常玩卡通赛车
2010-02-09T16:40:43+00:00
http://greenmooon55.com/%e7%94%a8sandboxie%e6%ad%a3%e5%b8%b8%e7%8e%a9%e5%8d%a1%e9%80%9a%e8%b5%9b%e8%bd%a6
<p>尝试安装UT Game及卡通赛车,在UT里下载安装后只有第一次可以用,重启之后虽然能显示服务器列表,但是双击后就要求下载。我用的win7 x64,兼容模式等等也都尝试无效,没人反映此问题。可能性1:玩的人太少了….可能性2:是个例,是我的问题。</p>
<p>我在新浪论坛发了帖,不过没有得到解决办法:
http://bbs.games.sina.com.cn/thread-3230591-1-1.html
http://bbs.games.sina.com.cn/viewthread.php?tid=3230814</p>
<p>试过N次后想到新装的Sandboxie,于是在第一次安装后将整个目录加入沙盘并“自动删除沙盘中保存的内容”。问题解决,测试飞行棋也正常。
<a href="http://greenmoon55.com/%e7%94%a8sandboxie%e6%ad%a3%e5%b8%b8%e7%8e%a9%e5%8d%a1%e9%80%9a%e8%b5%9b%e8%bd%a6/attachment/20100209230722659/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100209230722659.png" alt="" /></a></p>
<p>在这里顺便说说新浪吧,新浪曾是我心中的第一门户,我的第一个邮箱([email protected]?)好像就是新浪的,新浪邮箱@sina.com也被我当过一段时间主力邮箱,刚才进去看了看,界面很像QQ邮箱,不过里面全是垃圾邮件。
<a href="http://greenmoon55.com/%e7%94%a8sandboxie%e6%ad%a3%e5%b8%b8%e7%8e%a9%e5%8d%a1%e9%80%9a%e8%b5%9b%e8%bd%a6/attachment/20100209231638690/"><img src="http://greenmoon55.com/wp-content/uploads/2010/02/20100209231638690.png" alt="" /></a>
新浪新闻是我初中时看新闻的网站,总是苦盼科技新闻的更新。新浪让Blog在国内火了起来,新浪也是国内较早推出微博的网站,爱问知识人比百度知道早了很多,igame里的飞行棋很好玩,igame连连看的背景音乐很好听,卡通赛车我从2005年玩到现在,野菜部落我做完了绝大部分任务。igame中用来买东西的金币可以通过挂银币得到,所以不用花RMB就能买很多东西。</p>
<p>不过,现在网易新闻不错,新浪不愿管不赚钱的igame了。
野菜部落最后维护时间是<a href="http://igame.sina.com.cn/_common/NM_Notice.asp?BBSNO=3343">2007年11月12日</a>。
卡通赛车上次更新是<a href="http://igame.sina.com.cn/_common/NM_Notice.asp?BBSNO=3009">2007年7月13日</a>,曾经的服务器200人频道爆满好久不见了,曾经的组队跑圣诞1刷分也没有了。积分设置不合理,玩得钱越来越少。。虽然这样,还有很多忠诚的老玩家,甚至有日本人、韩国人。
…
igame休闲游戏更新都在2008年前,请看这个<a href="http://igame.sina.com.cn/_common/bbslist.asp?where=2">游戏公告</a>列表。希望新浪能在让我们玩几年卡通赛车~
BTW,最近新浪还有这件事:<a href="http://blog.kenengba.com/2010/02/01/688/">新浪微博的气量</a>。</p>
<p>当然了,如果这样用Sandboxie实在是大材小用啊,<del>这个东西还是要用来管QQ的,把用着的TM加入了沙盘,为了“安全”</del>。哦,对了,好像emule下载时ip地址是可见的,记不太清了。</p>
<p>Sandboxie Version 3.44 reintroduces support for 64-bit Windows. (3 February 2010)
http://www.sandboxie.com/
Price for customers in China: 85 Yuan.
貌似这软件不注册也能正常用,和 Total Commander 一样。
注册最大特色是 Enables the Forced Programs and Forced Folders features 强制在沙盘中运行特定文件、文件夹。</p>
A new approach to China
2010-01-13T03:36:26+00:00
http://greenmooon55.com/a-new-approach-to-china
<p>http://googleblog.blogspot.com/2010/01/new-approach-to-china.html
http://chinese.wsj.com/gb/20100113/tec081605.asp</p>
<p>相关:06年Google的声明:http://googleblog.blogspot.com/2006/01/google-in-china.html</p>
<p>第一天不上学,刚起床就看到这事。
Don’t be evil.
XXX居然窃取“某些人”的Gmail账户! 试想国内新闻:“Google不愿过滤色情淫秽内容而退出中国市场。“</p>
<p>静观事态发展</p>
Read it Later 2
2010-01-01T10:05:40+00:00
http://greenmooon55.com/read-it-later-2
<p>刚刚翻译完成,没怎么测试直接release了,可能会出现一些错误。有些英文无法翻译。</p>
<p>What’s new?
1 不再使用Firefox书签管理,用了数据库。
2 保存上次浏览页面的位置,可以用Currently Reading查看页面读完了多少,不过没什么大用。上次浏览位置还能在web version, iPhone app, and Firefox extension中同步。
<a href="http://greenmoon55.com/read-it-later-2/attachment/20100101174348814/"><img src="http://greenmoon55.com/wp-content/uploads/2010/01/20100101174348814.png" alt="" /></a>
3 支持标签
4 纯文本浏览模式,仅显示文本,像快照一样。
5 把share功能移到状态栏右下角,支持delicious, twitter, GR等等。
6 新图标
作者介绍新功能:<a href="http://readitlaterlist.com/blog/2009/12/welcome-to-20/">http://readitlaterlist.com/blog/2009/12/welcome-to-20/</a></p>
<p>突然想到,其实现在的Read it Later如果加入收藏分享不就是delicious了吗!我用Read it Later只是为了省去添加书签选文件夹和删除书签的繁琐,同步很少用到,Click to save更是一次也没用过。有些人已经用回0.9版了。
BTW,与GReader整合的功能很好。
<a href="http://greenmoon55.com/read-it-later-2/attachment/20100101180615660/"><img src="http://greenmoon55.com/wp-content/uploads/2010/01/20100101180615660.png" alt="" /></a></p>
<p><a href="https://addons.mozilla.org/zh-CN/firefox/addon/7661">https://addons.mozilla.org/zh-CN/firefox/addon/7661</a></p>
<p>豆瓣验证:doubanclaim85cd2653ef1ff45c</p>
喜欢纪录片
2009-12-14T11:51:21+00:00
http://greenmooon55.com/%e5%96%9c%e6%ac%a2%e7%ba%aa%e5%bd%95%e7%89%87
<p>难得的放假,看了几个纪录片。</p>
<p><a href="http://v.youku.com/v_show/id_XMTIxNDI0MzYw.html"> [探索频道]【建筑奇观:北京地铁系统】 </a>
视频里说的四号线已经建成,还没体验过。个人认为地铁是解决交通拥堵问题的唯一办法,对这方面还是很感兴趣的。现在才知道修地铁也不容易,又是地质问题又是噪音共振问题。移动闭塞这个东西很好玩,我觉得还应该加长编组。</p>
<p><a href="http://v.youku.com/v_show/id_XMTM4MDg3NDY4.html"> The Canton Tower - 国家地理频道-伟大工程巡礼:广州电视观光塔(完整版) </a>
好高好高哇!现在的新建筑越来越怪异了。抗风实验又是同济弄的,城市规划专业我也喜欢,不过估计去不了。</p>
<p><a href="http://v.youku.com/v_show/id_XMTM0MzgyOTgw.html">[日本NHK纪录片]2009年春节广州站纪实</a>
NHK的,回家难啊,还好这是09年的,08年人比这还多,都滞留了。武广客专年内开通,3h+ 490,很贵啊,两人1000。大约长春到北京的距离,还是卧铺比较合适,两人才500,如现在的Z62。要是长吉城际能按现行D车票价35该多好。</p>
<p><a href="http://www.verycd.com/topics/2786024/">[NHK纪录片]IT世代-改变未来的年轻一代(VeryCD)</a>
那个CEO比我还小一点,真帅。不过,如果他不会英语,要完成这些也不容易。片中的TakingITGlobal在中国大陆无法访问,中文内容不多,大陆用户也没看到几个。</p>
<p>赞下<a href="http://www.daolan.net/viewthread.php?tid=450">无私奉献</a>的字幕组,愿道兰长存。
道兰纪录片同好会<a href="http://www.daolan.net">http://www.daolan.net</a>
顺便推荐下<a href="http://v.youku.com/v_playlist/f3190990o1p0.html">中国铁道大纪行</a>,还没看到一半,很喜欢。</p>
<p>考试考得很垃圾,但愿这是我高中阶段的最后一次考试,xmu以上的我都去>.<。准备换个.com域名,很久以前就想了。</p>
就想出去玩——北京
2009-09-20T09:59:41+00:00
http://greenmooon55.com/beijing-travel-for-fun
<p>7月去的,为什么去?恐怕是今年上半年看了好多别人的旅行(主要在<a href="http://bbs.hasea.com">海子</a>),就是想出去,随便逛逛而已。以图代字。</p>
<p>为了不浪费第二天上午,选择了K7504+Z62,体验直特。
视频:K7504吉林站——孤店子站</p>
<p>宽平桥,经典位置。国铁、轻轨、有轨电车三合一,不过没法同时拍三种车。
<a href="http://www.flickr.com/photos/greenmoon55/3936066275/"><img src="http://farm3.static.flickr.com/2617/3936066275_fb0cd70022.jpg" alt="长春有轨电车" /></a></p>
<p>第一次亲眼看见动车,CRH5。</p>
<p>好地方,出去就是北航西门,清北离这里也不远,不过连个站房都没有,西侧就是高架的13号线。
<img src="http://greenmoon55.com/wp-content/uploads/2009/09/DSCF0276-600x450.jpg" alt="清华园站站牌" /></p>
<p>水立方
<a href="http://www.flickr.com/photos/greenmoon55/3717161902/"><img src="http://farm3.static.flickr.com/2659/3717161902_f584f71d21.jpg" alt="水立方" /></a>
<img src="http://greenmoon55.com/wp-content/uploads/2009/09/DSCF0303EDIT-600x450.jpg" alt="水立方" /></p>
<p>王府井新华书店:北京教材版本
<img src="http://greenmoon55.com/wp-content/uploads/2009/09/DSCF0309-600x450.jpg" alt="北京教材版本" />
还在这书店看到了“金盾出版社”的广告…</p>
<p>Z62很爽很快,不过下铺那对一直聊到很晚,我迷迷糊糊地看到了1秒沈阳北的站台,随后皇姑屯、大成通过,上了高架,第一次体验秦沈,还是想白天坐T157什么的看看。</p>
<p>第二天4点多就醒了,路上记录了通过每站的时间和速度,不过那张纸被弄没了。6点整正点到站,坐地铁到三元桥,走了很远换乘403,到铁博时还没开门。里面都是一些旧车,兴趣不大,还有一个地铁车,那时只有一号线、二号线。打车到团结湖地铁站,穿过某医院(在谷歌地图上没找到?),普通的居民小区与”三里屯”仅相距几百米,小区里有人正在路旁吃着盒饭。去Apple Store玩了会,还有老外在上Facebook。匆匆看了光合作用书店,就去北京北站坐了S2。从清华园去百万城看了车模,吃饭,睡觉。</p>
<p>第X天,去了奥运区,鸟巢没觉得多大,直饮水取水处连水龙头都没了,过了奥运这些设施就不能留下来点吗?</p>
<p>第X天,北京南——天津——沈阳北,体验动车,盒饭很贵。我体验过的最高速到了330,秦沈新建车站附近实在太荒凉。</p>
<p>第X天,T5319沈阳北——吉林。终。</p>
中病毒
2009-08-23T14:41:31+00:00
http://greenmooon55.com/fight-with-viruses
<p>上周日,Replay Media Catcher突然无法抓取formula1.com的视频,我找到了自称能录制一切视频的Replay Video Capture,从国外某网站下的破解。下完在安装的时候小红伞提示有病毒,我怀疑是误报,往virustotal上传,可是上传速度太慢了,我等不及了就解压了安装,点了一次Ignore,然后就中毒了。</p>
<p>中毒后Antivir一会弹出一个exe被感染的提示,虽然是间断性的,不是连续的,但也很烦人,我就去设置里调成了自动。这里病毒已经不止一种了,但种类也不多。此时看到了virustotal的结果,一片红啊。此时病毒已驻留内存,红伞杀不掉,网上下了个专杀,结果到处都是OK,去下了大蜘蛛的cureit,结果还是杀不掉内存的病毒。用冰刃查看发现有两个伪装进程,一个是notepad.exe,另一个忘了。
<img src="http://greenmoon55.com/wp-content/uploads/2009/08/20090816200622903.png" alt="中毒情况" />
实在没办法,备份了C盘(其实也就是桌面)几个文件,找到买电脑时的镜像恢复了。Ghost完,装好小红伞,全盘杀毒,发现很多exe文件无法修复,都被移到隔离区了,不过有些还是幸免于难,比如盛名时刻。</p>
<p>忘了备份FF了,后来又花时间找插件。。Read it later的reading list也没了,重新注册了一个帐户,不敢把密码存在FF里,刚刚改成了最简单的密码。</p>
<p>中毒时有一段时间电脑很卡,使我想起了当年中欢乐时光病毒的样子,那时我在用金山毒霸,一直傻傻的删C盘文件。从那时起,我电脑几乎没种过病毒。现在我没有防火墙,eqsecure也多年不用了。上周中毒时我还想过去找EQ,现在好像都收费了。</p>
<p>今天从国内某网站下了Replay Video Capture,明白它的用法了,就是捕捉屏幕上指定的一部分,但formula1.com的视频全部播放完再回头看还要缓冲。Replay Media Catcher依然无法抓取,只好就这样了。要是formula1.com提供下载就好了,标明供个人使用就行了呗。</p>
ITV F1 - 12 Years of F1 Montage - We'll Carry On
2009-06-08T04:56:41+00:00
http://greenmooon55.com/itv-f1-12-years-of-f1-montage-well-carry-on
<p>从半年多前到现在,这个视频我已经看了无数遍了。我觉得这是最棒的F1视频,配的歌是My Chemical Romance的Welcome to the Black Parade。
F1年年大变样,希望F1不要衰落就好。</p>
<p>歌词及翻译:
来源:<a href="http://zhidao.baidu.com/question/16415674.html">http://zhidao.baidu.com/question/16415674.html</a></p>
<blockquote>
<p>When I was a young boy,
My Father took me into the city,
To see a marching band.
当我还是个小男孩的时候,我父亲曾带我进城去看乐队游行。</p>
</blockquote>
<p>He said “Son when you grow up, would you be the savior of the broken, the beaten and the damned.”
他说:“孩子,当你长大的时候,你能否成为那些绝望的,失败的,和倒霉的人的救星?”</p>
<p>He said “will you defeat them, your demons and all the non-believers, the plans they have made.”
他说:“你能打倒你心中的恶魔,建立你的信仰,让那些魔鬼的计划全部破产么??”</p>
<p>“Because one day I leave you,
A phantom to lead you in the summer,
To join the black parade.”
“因为,我有一天会离开你,夏天,幻象会把你引入卡怕的游行”</p>
<p>When I was a young boy, (同上)
My father took me into the city
To see a marching band.</p>
<p>He said, “Son when you grow up, will you be the savior of the broken, the beaten and the damned?”</p>
<p>Sometimes I get the feeling
She’s watching over me.
And other times I feel like I should go.
And through it all, the rise and fall, the bodies in the streets.
When you’re gone we want you all to know
有时我会有这种感觉,
我感觉她在监视我。
有的时候我认为
我应该经历世间所有的沉浮
当你离开是时候,我要让你们所有人都明白</p>
<p>We’ll carry on, 我们会坚持
We’ll carry on 我们会坚持
And though you’re dead and gone believe me 尽管你死了你也要相信我
Your memory will carry on 你的记忆会继续
Carry on 继续
We’ll carry on 我们会坚持
And in my heart I can’t contain it 我的心没有办法容忍
The anthem wont explain it. 即使赞美诗也没办法解释</p>
<p>And we will send you reeling from decimated dreams 我们将让你从杀戮的梦中解脱出来
Your misery and hate will kill us all 你的苦和恨将杀了我们所有人
So paint it black and take it back 所以,把它涂黑,把它收回
Let’s shout it loud and clear 让我们大声清晰的喊出来。
Do you fight it to the end 你会和它战斗到底
We hear the call to我们听见高喊声
Carry on 坚持
We’ll carry on 我们会坚持
Though you’re dead and gone believe me尽管你死了你也要相信我
Your memory will carry on 你的记忆会继续
We’ll carry on 我们会坚持
And though you’re broken and defeated尽管你曾被征服,被打败
You’re weary widow marches 但你已厌倦再哀伤孤独下去
On
And on we carry through the fears 一次次,我们穿越痛苦
Ooh oh ohhhh 哦
The disappointed faces of your peers 你们这些贵族们失望的脸
Ooh oh ohhhh 哦
Take a look at me cos I could not care at all 看我的吧因为
Do or die 是我不会顾虑,就算决一死战
You’ll never make me 你没办法控制我
Cos the world, will never take my heart 就算是全世界也不能占据我的心
You can try, you’ll never break me 你可以试,但是你们没办法削弱我
Want it all, I’m gonna play this part我要所有 我要扮演这个角色
Wont explain or say I’m sorry 我不会解释任何 不会说对不起
I’m not ashamed, I’m gonna show my scar我要给你们看我的伤疤,我不会惭愧
You’re the chair, for all the broken你安抚所有失意的人
Listen here, because it’s only..听着,因为……
I’m just a man, I’m not a hero 我只是个凡人 我不是英雄
Just a boy, who’s meant to sing this song 只是个男孩 唱这首歌的男孩
Just a man, I’m not a hero 我是个凡人 我不是英雄
I DON’T CARE!! 我不介意</p>
<p>Carry on 坚持
We’ll carry on我们会坚持
Though you’re dead and gone believe me 尽管你死了你也要相信我
Your memory will carry on 你的记忆会继续
We’ll carry on 我们会坚持
And though you’re broken and defeated 尽管你曾被征服,被打败
Your weary widow marches on 但你已厌倦再哀伤孤独下去
Do or die决一死战
You’ll never make me 你们无法安排我
Cos the world, will never take my heart 就算是全世界也不能占据我的心
You can try, you’ll never break me 你可以试,但是你们没办法削弱我
We’ll carry on 我们会坚持
We’ll carry on
We’ll carry on
We’ll carry
We’ll carry on</p>
端午节体验长春轨道交通
2009-06-08T03:50:10+00:00
http://greenmooon55.com/090528-changchun
<p>端午节就是想出门,本来想去沈阳,体验T5312的客流或体验4272的卧代座+T158,回程4235走沈吉全线,但是只有两天,时间不够,沈阳市内也不知道去哪玩,沈抚城际还没修好,于是放弃去沈阳。
<a href="http://www.ditiezu.com/thread-37443-1-1.html">http://www.ditiezu.com/thread-37443-1-1.html</a>
<a href="http://www.ditiezu.com/thread-37437-1-1.html">http://www.ditiezu.com/thread-37437-1-1.html</a>
看了这两个帖子,决定去长春体验轻轨二期和54路了。
没带相机(没有),虽然有点遗憾,但也少了个包袱,旅行不是为了去拍照留下纪念,而是享受这个过程。</p>
<p>目标:长吉城际工地、轻轨二期、动车、宽平大桥、54路、百脑汇(看相机)、《中国国家地理》长春读者服务站</p>
<p><strong>去长春</strong>
早上3点出发,沿江边步行3公里一直走到火炬大厦,这是我从小到大第一次端午节去江边。。
上网查了一会,5点半出发,3路车居然满员,去火车站的人很多,甚至有人上不去,这可是5点啊!要是平时能有这客流完全可以修地铁。吉林大桥南侧都成了早市,卖艾蒿的地坛前围了很多人,刚才在江边走的时候可没人要。吉林大桥有点堵车,北侧松江中路的人和春节前超市的人有一拼。
6点到火车站,先去出站口看看晚点情况,不像<a href="http://greenmoon55.com/090321-jilinxi-jilin/">上次</a>全部正点,T271晚点1小时。买票时有个人点名要“7:12的”,等着去吧!买票人很多,排队15分,大部分是去长春的,很多人都买K7324,屏幕显示有两百多张硬座。买完票时间还早,从新兴街往北走沿铁路线进站,看到K7324是K215/6套的。。此时是橘子的天下。
车上客流一般,基本1个人一排座,桌子不干净,毕竟刚跑完三千公里。上次坐这个车我还在上小学,当时还没升K,还是<a href="http://bbs.hasea.com/thread-129453-1-1.html">1365/6/7/8</a>。(据说最开始是绿皮?)其实长吉现在这样也不错,20块不算贵,座位还多。
学校C楼时间7:01,在K7333晚点1小时进站之后K7322才开,看了城际施工情况,城际就是部分高架+截弯取直,不知道等级到底怎么样,速度能到多少,要是真的最高时速200km/h的话也太慢了。座位后面是个和我年龄相仿的人,在看杂志,我挑了个三人座,左前方是有个MM,貌似是大学生。
在七家子清楚地看到两年前军训的楼,果然离铁路线很近,客技站里还停着两个破绿皮,不知道是什么车。
途中会4337和T5311,还看到某工程车。九台晚10分,长春晚12分到。出站后在KFC看到T5316晚40分。感觉长吉间这次时间过得最快。</p>
<p><strong>轻轨</strong>
花4块买票,是很旧的磁卡票,去净月潭和长影世纪城的人最多,好像现在没有只到临河街的车了。轻轨是靠右侧通行,长春站这里车进北侧站台,南侧下车,司机走到另一方向驾驶室再开北侧车门。
上车后听广播好像是三十多公里,全程63分,可真远啊!
与铁路并行这段站比较多,感觉几乎一出站就进站了,遇下行重载货车,最前面两个机车,中间也有两个,好像是SS4。有个小问题,为什么不把中间的SS4放到最后呢?
还看到宽平桥上54路的接触网了,然后很清楚地看到长春南站,南站附近的棚户区和几年前一样差。卫星广场站已经改成地下站了,有地铁的感觉,还是地铁好。轻轨一期有很多平交路口,二期基本都是高架了,二期还是沿着卫星路和净月大街走,弯比较多,很不爽,常常能看到路旁限速40、54的牌子。旁边能看到以前曾经从火车站站到会展中心的160路,轻轨南侧还有东北师范大学等等等等N多学校,长春的大学很多很多。在净月看到某豆腐渣工程,上面有一大堆条幅。。。
终点长影世纪城,本来想出站来着,到站之后决定不出站了,轻轨各站中间都有栅栏,栅栏上的门也锁着,不能直接走过去。上楼的楼梯好像有无障碍轮椅,这里轻轨车两个股道都进。
由于提前做的准备不充分,还是分不清轻轨的车,最开始坐的车铭牌上写着最高速度70km/h,好像是05年产的。车很晃,我都有点晕车了,回来的车就不晃了。
到净月潭下车,在站台上呆了一会,不知道下一班轻轨的时间是怎么显示的,显示0分了还没车来,一会又变成xx分了。。还有站台上那个记秒的液晶是干嘛用的,一会红一会绿的。
回到宽平大桥出站时居然要补票,说时间超过1小时就得补票,那从火车站到长影世纪城不得“63分”吗?长春轻轨价格还是很合理的,不贵。30公里4块钱和火车一个价了。
总体感觉一般,二期的高架弯太多了,半径也比较小。还是地铁好,想怎么修就怎么修。不过MS地铁对地面建筑物有损害。
很多人拍轻轨,来的时候在九台附近也有人拍K7322。还有长春情侣真多啊,到处都是穿情侣装的。</p>
<p><strong>54路</strong>
刚出站就看见上行某SS9G+25K,桥很陡,铁路线对应的桥上位置都有防护网,估计是怕自杀的跳到铁路线上。。这是很经典的位置,桥上有54路,桥下有京哈线和长春轻轨3号线,全国没准都没有第二个。不过,要想把三个都照上很难,不仅仅是时间上的问题,北侧下面轻轨的站内桥也影响视线。
在桥上看到一个爸爸带着孩子看车,孩子戴着那种带小电扇的帽子,我小时候也这样。呵呵~ 后来这父子俩和我们一起坐54路了。
在桥上很快来了个上行绿皮,速度还可以,不过显然没有上100。不知道160是什么感觉。
我还想从宽平大桥坐到西安大路呢,当时饿了,时间也比较紧。就直接去红旗街了。
长春有轨电车和大连的不一样,大连的是在马路中央,和机动车一起。长春的是单独有线路。
54路人工报站,自动售票,好像电压不是很高,驾驶手柄急解位、缓解位什么的。线路不隔离,车每到路口都要减速通过,还要等红灯,54路甚至没有旁边的公交车快,现在价值不大。54路车隔还是很短的,一会就一辆。
最大的收获是红旗街折返的地方道岔只有一侧可以换,另一侧是死的,不明白车是怎么转过来的,难道轮子和铁路不一样,还是我看错了?</p>
<p><strong>市区</strong>
去看了一圈数码相机,百脑汇门前电信在宣传3G,还有这个马路可是真难过啊。。坐K362到重庆路,按地图绕了半天才找到《中国国家地理》长春读者服务站,超级小的地方,门前还贴着告示,说端午节放假一天。。
从重庆路坐Z306路到高速客运站,这长春还出来个Z车,K车T车Z车都全了,哪里有D车。。这个和306貌似只是部分路线不同,不知道为什么叫Z。</p>
<p><strong>回程</strong>
坐17:45的末班车大客,大客末班太早了,不过也没多少人,一共才10人左右,于是坐到第一排。
限速30跑80,以100km/h左右超大货的感觉可真是刺激,极品飞车的感觉。。由于窗外景物比较单调,感觉不到速度。
一小时到吉林,80km/h左右进沙河子广场与佳宝抢行,佳宝撞到大客的中部,保险杠撞坏了。眼睁睁地看着25路末班开走,走了很远到中东新生活和人拼车走刚重铺路面的临江门大桥回家,在深圳街超快速走右侧车道超车,吓人啊。以后还是多坐火车吧。</p>
F12009Spain
2009-05-10T14:22:32+00:00
http://greenmooon55.com/f12009spain
<p>服了,彻底服了!法拉利现在弱智到这种地步。。</p>
<p>KimiQ1淘汰、马萨省油到第6,以前从来没看过直播中的故意省油,今天算开了眼界了。。我一直有个问题,就是赛后称重MAS能过去吗?法拉利的稳定性和策略啊!现在我每次看法拉利进站都胆战心惊的。。</p>
<p>今天MAS和VET有点像06年Imola,不过我一点也没有当年的紧张感觉。怀念06年,舒米和蓝色的雷诺。</p>
<p>最后一次练习赛法拉利包揽一二,原来是用了B版赛车,极高幅度很大,在西班牙应该算第三快的车(排位后我根据载油量的预测基本正确),明显比MC快。进步很快,赞一下!</p>
<p>今天刚开始用PPLIVE看后来用UUSEE看的台湾星空卫视体育台,两个网络电视都把台标给抹掉了。好像有一年没看这个台了。解说不错,这个台车手名、车队名什么的都不翻译,广告和<del>赛后采访</del>也不翻译。</p>
<hr />
<p>Blog的更新频率已经<1篇/月了 :(</p>
吉林西-吉林小运转
2009-03-22T01:26:23+00:00
http://greenmooon55.com/090321-jilinxi-jilin
<p>图片集:<a href="http://picasaweb.google.com/greenmoon55/090321">http://picasaweb.google.com/greenmoon55/090321</a>
第一次拍,还是别人的破相机,我技术也不好,所以大部分都很模糊</p>
<p>先发车票,好贵啊</p>
<p><img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScUMY8mbCwI/AAAAAAAAAko/_VQdxMjd-uM/s512/%E6%89%AB%E6%8F%8F0012.jpg" alt="undefined" /></p>
<!-- more -->
<p>5点出发从某学校门口出发 :lol:
<img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThPwMQcKI/AAAAAAAAAfQ/muMlBAcpHQk/s512/DSCN5702.JPG" alt="" /><img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThRMPO5EI/AAAAAAAAAfg/lANjowNon3A/s512/DSCN5704.JPG" alt="" /></p>
<p>前一天刚下完雨,路不好走
<img src="http://lh5.ggpht.com/_u3r6PXK-L-s/ScThSNaIYmI/AAAAAAAAAfo/eObDxSXw2-4/s512/DSCN5705.JPG" alt="" /></p>
<p>船营区人民法院
<img src="http://lh6.ggpht.com/_u3r6PXK-L-s/ScThS0EmGJI/AAAAAAAAAfw/4CnqzqjhfD4/s512/DSCN5706.JPG" alt="" /></p>
<p>想从这里往前走,可是很难走,也不熟悉,听声音感觉里车站很远,于是走上解放大路。
<img src="http://lh6.ggpht.com/_u3r6PXK-L-s/ScThT-mmA8I/AAAAAAAAAf4/S-G5KIE5TKU/s512/DSCN5707.JPG" alt="" /></p>
<p>问了出租车司机,拐进某小路向西走,此时6点左右。</p>
<p><img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThUo4JAEI/AAAAAAAAAgA/ySvUVlOy6mo/s512/DSCN5709.JPG" alt="" /></p>
<p>绕了一圈,终于看到站房了。这是路牌。
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThVfutkdI/AAAAAAAAAgI/GEkYDMhiPMw/s512/DSCN5710.JPG" alt="" /></p>
<p>回望学校
<img src="http://lh6.ggpht.com/_u3r6PXK-L-s/ScThWBBB0wI/AAAAAAAAAgQ/wCsHM-j7bT8/s512/DSCN5711.JPG" alt="" /></p>
<p>这是啥地方?没听说过
<img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThYnvxLvI/AAAAAAAAAgo/TXDs3YW0qc4/s512/DSCN5715.JPG" alt="" /></p>
<p>34路破站牌
<img src="http://lh5.ggpht.com/_u3r6PXK-L-s/ScThZAUcYaI/AAAAAAAAAgw/nabZnM5nFiU/s512/DSCN5716.JPG" alt="" /></p>
<p>站房
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThat9U81I/AAAAAAAAAhA/H-m31dMTnII/s512/DSCN5718.JPG" alt="" /></p>
<p>进站了,首先看到这个 好像和MSTS里的很像
<img src="http://lh5.ggpht.com/_u3r6PXK-L-s/ScThbX7THgI/AAAAAAAAAhI/U-lFuN6-3KY/s512/DSCN5719.JPG" alt="" />
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThcTGJt3I/AAAAAAAAAhQ/JdVdK46CNdM/s512/DSCN5720.JPG" alt="" /><img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThdSLFcOI/AAAAAAAAAhY/BzlT38hBbYI/s512/DSCN5721.JPG" alt="" />
这时已经听到鸣笛声,来车了。</p>
<p>DF4D3097牵引宁波车2道通过
相机时间不准,忘了是什么时候了。
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThd4pDzJI/AAAAAAAAAhg/5V_Z0rDmNVA/s512/DSCN5722.JPG" alt="" />
只拍了这一张,后面的YZ人很少。</p>
<p>“运转”是什么意思?
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThetG8BKI/AAAAAAAAAho/W7yA2I4VXGE/s512/DSCN5723.JPG" alt="" /></p>
<p>站牌和站房,在吉林这么多年这可是第一次进去。以前还坐过北山和马相屯都停的4236呢
<img src="http://lh5.ggpht.com/_u3r6PXK-L-s/ScThfgeKV8I/AAAAAAAAAhw/X7hm1k_sdLw/s512/DSCN5724.JPG" alt="" /><img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThgdo5bGI/AAAAAAAAAh4/5fGxlVkKteA/s512/DSCN5725.JPG" alt="" /></p>
<p>6点20多,西瓜牵引某货列3道停车 视频的效果还不错,早知道多录点好了。</p>
<p>停下后尾部好像没过道岔,又往前开了点,然后又倒回去。我第一次看到这种情况 我没理解错吧?</p>
<p><img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThiXD5H9I/AAAAAAAAAiI/90T1YvFv9yA/s512/DSCN5729.JPG" alt="" />
这是啥?</p>
<p>拍完货列就有人来,不想让我拍…</p>
<p>6点40多 4239一道停车
<img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThja3S5FI/AAAAAAAAAiQ/g-tIjZMhkrE/s512/DSCN5730.JPG" alt="" /><img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThjy9UzNI/AAAAAAAAAiY/-qKzw-vLapI/s512/DSCN5732.JPG" alt="" />
DF4D0096 游戏里好像有
22 22B 25B都有 1RW 1或2YW(没太注意)</p>
<p>和谐的客流
<img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThkrIJZnI/AAAAAAAAAig/8Hu5YEccQZU/s512/DSCN5733.JPG" alt="" />
广播里一直在放新闻和报纸摘要。</p>
<p>通过北山</p>
<p>沈吉线桃源路段 从龙鼎开始拍的,小时候常在桃源路看火车。</p>
<p><img src="http://lh6.ggpht.com/_u3r6PXK-L-s/ScThmE099RI/AAAAAAAAAiw/oiALjSIcXxI/s512/DSCN5738.JPG" alt="" />
这是新修的雾凇大路,图中有长图和沈吉的联络线,我很小的时候好像联络线还没修呢。</p>
<p><img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThmtrwCFI/AAAAAAAAAi4/mcBUsXwM7-Q/s512/DSCN5739.JPG" alt="" />
拉绿皮,橘子的灯开了</p>
<p>想照长图线,结果就这样了,还不知道是不是。
<img src="http://lh5.ggpht.com/_u3r6PXK-L-s/ScThnOS4YWI/AAAAAAAAAjA/D0zqm6a_qZk/s512/DSCN5740.JPG" alt="" /></p>
<p>T544的本务
<img src="http://lh6.ggpht.com/_u3r6PXK-L-s/ScThn-XS8MI/AAAAAAAAAjI/eqwP9hhODzE/s512/DSCN5741.JPG" alt="" /></p>
<p>N122硬座有不少空座,早上3趟车去长春呢。
4239到站了也没广播通知,还在转播新闻和报纸摘要</p>
<p><img src="http://lh6.ggpht.com/_u3r6PXK-L-s/ScTho4wC2kI/AAAAAAAAAjQ/Psr6HuFb9AQ/s512/DSCN5743.JPG" alt="" />
下车了,我坐的车厢 YZ22B 341475</p>
<p><img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThp8UTYLI/AAAAAAAAAjY/ZJ4RFUYCP94/s512/DSCN5744.JPG" alt="" />
应该是山海关—长春了,这还没改呢</p>
<p>下车后看到4239本务已经解挂
一站台停着2015,刚放人。好像全是YZ22。这车我几年前坐过一次。
这个提示牌显示车厢顺序。
<img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThrOJTQHI/AAAAAAAAAjg/75L-L84Aqlg/s512/DSCN5746.JPG" alt="" /><img src="http://lh4.ggpht.com/_u3r6PXK-L-s/ScThr3pgFcI/AAAAAAAAAjo/C8NwtocOP_U/s512/DSCN5747.JPG" alt="" />
哈局三段1773 是三棵树车辆段吧</p>
<p>出站,三张都这效果。。
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThtUQZBkI/AAAAAAAAAj4/ld_o6dZoL3Q/s512/DSCN5749.JPG" alt="" /><img src="http://lh5.ggpht.com/_u3r6PXK-L-s/ScThu3pNccI/AAAAAAAAAkA/RzSOEXI74XY/s512/DSCN5750.JPG" alt="" /><img src="http://lh6.ggpht.com/_u3r6PXK-L-s/ScThvziufQI/AAAAAAAAAkI/v3aEjBHYAfs/s512/DSCN5751.JPG" alt="" />
全部正点,2223那行坏了?</p>
<p>早上的吉林站
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/ScThw8gP4yI/AAAAAAAAAkQ/m1FB8t14mBE/s512/DSCN5752.JPG" alt="" />
人很少,站前也没出租车等车。街上也没多少人。</p>
<p>不错不错 :D</p>
二月一日长春行
2009-02-28T11:03:19+00:00
http://greenmooon55.com/0201-a-trip-to-changchun
<p>我还活着…好久没来blog了,这篇是2.1就想写的。
别看了…
<!-- more --></p>
<p>6点多出发,搭车到人民广场,步行到重庆路,发现新华书店没开,于是去KFC,在KFC流鼻血…
去书店,正好领导检查。先去看了音像,在卖盗版电脑盘,还发现好多老电影,还有很特别的像是个人做的CD。发现新的列车时刻表,上面居然有jpskb。计算机区看到《Code Craft编程匠艺》,看了一小会。然后领导来检查,测试报警器,说丢书现象很严重,是内部人拿的。还说年销售目标是300万。</p>
<p>然后坐362去胜利公园,听到雷人的报站,直接读出“市妇产科医院”的拼音。。售票处已经停用了,里面有很多人在滑冰,旁边的游乐场没人。发现一蒸汽机车,不过老妈的破手机没调好,照成黑白的了,不过正好有历史感。
<img src="http://lh5.ggpht.com/_u3r6PXK-L-s/SakRVT4qpYI/AAAAAAAAAbU/IVhLYq598HA/s512/IMG0078A.jpg" alt="" /><img src="http://lh3.ggpht.com/_u3r6PXK-L-s/SakRWMONAuI/AAAAAAAAAbc/dqj0h-O6lz0/s512/IMG0080A.jpg" alt="" /><img src="http://lh6.ggpht.com/_u3r6PXK-L-s/SakRW2W1S6I/AAAAAAAAAbk/c8KDkso3zZA/s512/IMG0081A.jpg" alt="" /><img src="http://lh6.ggpht.com/_u3r6PXK-L-s/SakRXlAeW9I/AAAAAAAAAbs/XiOewgyywf4/s512/IMG0083A.jpg" alt="" />
步行去联合书城,到了才发现这个地方就在某次来长春住的招待所对面。其实这和江南书城是一家的,那里计算机书很多,我居然找到了一本GDKOI的几年前的考题,还发现一本有关电脑的某小说被错放在那里。。买了第一期华夏地理、和一个到现在都没看的元素周期表。。</p>
<p>打车回重庆路,去吃东方饺子王,有两人桌,一侧是长软凳,还能再坐人,空间利用得很充分。环境不错,可是那厕所不怎么样。吃完饭去沃尔玛,这是老项目了,不过这次只买了两瓶矿泉水。发现一楼开了一个牛排店,人不少。</p>
<p>出来就坐K362去欧亚商都了,重庆路堵车严重,很像吉林重庆路改为单行线之前的样子。K车甩小站,不过红绿灯+堵车也没快多少。可惜T车这里不停,我也一直没看到T车。进去之后感觉那地方好大好大(这辈子去过的最大滴 汗~~),有乡下人进城的感觉,东西超贵,人还是很多,有的店铺上甚至没有中文,都是英文,韩文…地下的超市人太太太多了,MS都拿购物券。最后,理所当然的,我们什么都没买出去了,因为本来就什么都没想买。出来以后坐25路车回火车站,车开得很快,MS25路车都叫快25。</p>
<p>下面才是重点:
进站后去问询处问火车信息,遭遇两人插队(素质啊。。难道看我好欺负),那个人居然说晚7点(or 9点)才有车,鬼才信呢!买票时老妈很聪明,发现改签窗口也卖票,没多少人排队,就去那里买了。忘了前一天查好的车次(T543),结果那帅哥直接打了这车次的票,买的3车110,这时还有1个半小时开车。决定去旁边的古本良田,发现原来不是日本的,只是沈阳的。老爸说牛肉饭好吃,我可不觉得,感觉像火锅一样。</p>
<p>吃完被拉去旁边的商场,提前半小时左右进站,人不少。找了一会票,在队尾检票进的站。果然是25K的T271/2套跑的(可怜的七家子客技站),上次坐这车是04年和姐姐一起坐硬座回吉林,照了几个车厢号都忘保存了。只有这个了….
<img src="http://lh3.ggpht.com/_u3r6PXK-L-s/SakfUPlFu7I/AAAAAAAAAcs/Z6MhRwyK-Oc/s512/IMG0085A.jpg" alt="" />
上车后花了好一会才弄清方向,开车后才敢确认。等待发车过程中有两列货车向南开去,一SS9G在南侧换挂,北侧某西瓜(or 橘子。这记性,汗死~~)刚牵引来某车。两车都是蓝白的25K,不过不知道是什么车次,时刻表没查到。坐的位置是逆向南侧,这可不是什么好位置,我最喜欢的是正向北侧,那样可以看看九台站。不过这次天全黑了,长吉城际没看到,什么时候过的九台我都不知道,我还把孤店子当成新九站了。途中遇过红皮和不止一个绿皮,长图线貌似不太繁忙,一共也就遇到五六个车。列车正点到站,吉林站那个空啊!!啥都没有啊,真可怜啊!希望封站扩建快点开始吧,让吉林西、哈达弯、龙潭山始发车吧^_^,艺术节时逃出去看看。XD</p>
<p>整个假期,我沉迷在火车中,就像我在05年找到了霏凡、中天、剑盟、箫心一样。今年我找到了海子、sscz、our rail论坛和MSTS游戏,还在网上遇见同为火车迷的某学弟^_^。</p>
<p>我还弄了一个路线图,弄完才发现Google的My Maps不是做路线图的。。</p>
<p><a href="http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&msid=105087993106778372361.000462a268f77158f8003&ll=43.89245,125.32259&spn=0.043297,0.072956&z=13&source=embed">View Larger Map</a></p>
<p>//果然,又是小学生作文水平</p>
五大学科09年省区联赛正式取消保送
2009-01-16T18:49:51+00:00
http://greenmooon55.com/%e4%ba%94%e5%a4%a7%e5%ad%a6%e7%a7%9109%e5%b9%b4%e7%9c%81%e5%8c%ba%e8%81%94%e8%b5%9b%e6%ad%a3%e5%bc%8f%e5%8f%96%e6%b6%88%e4%bf%9d%e9%80%81
<p>在OIBH上搜索”保送 取消”,最早的<a href="http://www.oibh.org/bbs/viewthread.php?tid=6871">帖子</a>是2006年的,那是因为<a href="http://www.ccf.org.cn/web/assembly/action/browsePage.do?channelID=1099963972454&contentID=1140158517119">NOI内蒙古舞弊事件</a>。</p>
<p>或许由于信息竞赛的特殊(不知道其他科),有过许多此类事件:
<a href="http://www.oibh.org/bbs/viewthread.php?tid=5846">天津NOIP的黑暗</a>
<a href="http://www.nocow.cn/index.php/Article:%E8%87%B4%E4%B8%AD%E5%9B%BD%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%AD%A6%E4%BC%9A%E7%9A%84%E4%B8%80%E5%B0%81%E4%BF%A1_%28%E5%BE%90%E4%BC%9F%E4%BA%8B%E4%BB%B6%29">徐伟事件</a></p>
<p>最近一直有取消保送的帖子,有人还给教育局打电话确认,正式<a href="http://www.oibh.org/bbs/viewthread.php?tid=28498">确认此消息</a>是在1月14号冬令营开营式上。此贴从晚9点到12点回复超过100楼,当天OIBH保送区发帖量超过400。</p>
<p>[caption id=”attachment_134” align=”alignnone” width=”237” caption=”1月14日OIBH保送区(截图于23:59)”]<img src="http://greenmoon55.com/wp-content/uploads/2009/01/20090117010712203.png" alt="1月14日OIBH保送区(截图于23:59)" />[/caption]</p>
<p>于是最近这几天大家都在猜08NOIP1=是否有效,其他科目省一是否有效。<a href="http://www.oibh.org/bbs/viewthread.php?tid=28550">此帖</a>说明“NOIP2008有保送资格,NOIP2009无保送资格。”和大部分人预想的一样。</p>
<p>为什么要取消呢?</p>
<ol>
<li>
<p>不公平?比如舞弊啦,NOIP初赛泄题啦……我感觉其实NOIP还算很公平,除非文件名打错,少有成绩出入特别大的情况,我们这里不道德行为不多。高考就公平了?这里可不是!请Google一下<a href="http://www.google.com/search?hl=en&newwindow=1&q=%E6%9D%BE%E5%8E%9F+%E9%AB%98%E8%80%83+%E4%BD%9C%E5%BC%8A">松原高考作弊</a>,重灾区啊!</p>
</li>
<li>
<p>还有的说要留住真正的OIer,这个不太现实,我感觉因兴趣学OI的人是最多的,但是就是再有兴趣,如果没保送,班主任、家长能让吗?</p>
</li>
<li>
<p>自主人多了?自主和保送能一样吗。减20分还是不到线怎么办?再说没1=也能自主啊,貌似自主难吧。我也不太清楚T_T。。</p>
</li>
<li>
<p>偏科?专心(放弃高考)搞OI的才有几个人啊!再说这些人都是弄NOI的,取消NOIP的保送对他们没什么影响,只影响业余的。那么高考学的有什么用?大部分没用,高中就像军训,磨练人的意志,有谁对课本感兴趣。。</p>
</li>
<li>
<p>难度太低?还不是CCF弄的。。故意弄简单让大学不重视?</p>
</li>
</ol>
<p>自主名额以后一定是越来越多的,现在的趋势不就是高考鼓励其他方式上大学吗,为什么要这样呢?</p>
<p>宁夏的生物竞赛已经把省一改为“优胜奖”了。 <a href="http://www.nxjy.cn/index_ArtShow.asp?Id=4306">via</a></p>
<p>其实07届OIer是获益最大的,因为其他科高一、高二很难拿省一的,高三拿就不算了。我们课改第一年,保送政策修改也是第一年,不知道保送名额会不会变少,如果不变OIer就太幸运了。</p>
<p>现在good good study, day day up……</p>
<p>Bless~</p>
<p>PS:</p>
<p>我OI巨菜+文化课菜,只能考虑nuaa, xmu。(夸张了点。。)飘过~~~~ 已全程跟踪OIBH上今年保送自主信息。</p>
<p>刚发现吉大保送信息生物居然还要求省前10,真BT!能招来人吗~自主2月才截止报名。什么呀!</p>
<p>谁能解释下为什么OIBH08年访问量下降?看图</p>
<p><img src="http://greenmoon55.com/wp-content/uploads/2009/01/oibhanalysis.png" alt="oibhanalysis" /></p>
FF扩展: PlayLink
2009-01-14T14:47:18+00:00
http://greenmooon55.com/firefox-addon-playlink
<p>好久没更新了,不能上Blog的时候特想更新,买好空间弄好模版就不想写了。。</p>
<p>这个插件的功能就是用外部程序打开当前界面或链接,最多可以设置7个程序,还提供一个工具栏按钮。</p>
<p>[caption id=”attachment_130” align=”alignnone” width=”556” caption=”设置”]<img src="http://greenmoon55.com/wp-content/uploads/2009/01/20090114211547890.png" alt="设置" />[/caption]</p>
<p>支持Google Chrome的应用程序窗口哦!就是没有菜单和地址栏什么的,全屏浏览。</p>
<p><img src="http://greenmoon55.com/wp-content/uploads/2009/01/20090114201959578.png" alt="20090114201959578" /></p>
<p>默认支持Windows Media Player, Realplayer, Winamp, Google Chrome, IDM,其实大部分都支持。</p>
<p>我测试支持世界之窗,但<strong>不支持迅雷</strong>。</p>
<p>Link: <a href="https://addons.mozilla.org/zh-CN/firefox/addon/7006">https://addons.mozilla.org/zh-CN/firefox/addon/7006</a></p>
<p>现在去下应该还没有中文版,作者还没更新我的翻译。</p>
NOIP2008传纸条
2008-12-28T15:45:52+00:00
http://greenmooon55.com/noip2008-message
<p>原来是一个简单的DP,当时用搜索得50分,现在做DP没清零只得60分。。
斜着划分阶段,f[i,x1,x2]第i个阶段,x1, x2是两点的横坐标,每点的横纵坐标之和与阶段有关系。根据右下角为(m,n)可判断阶段数。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="k">message</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">map</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..50</span><span class="p">,</span><span class="m">1..50</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">f</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..100</span><span class="p">,</span><span class="m">1..50</span><span class="p">,</span><span class="m">1..50</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">x1</span><span class="p">,</span><span class="n">y1</span><span class="p">,</span><span class="n">x2</span><span class="p">,</span><span class="n">y2</span><span class="p">,</span><span class="n">temp</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">init</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">readln</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="k">read</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">function</span> <span class="n">max</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">:</span><span class="kt">longint</span><span class="p">):</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">a</span><span class="p">></span><span class="n">b</span> <span class="k">then</span> <span class="k">exit</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="k">else</span> <span class="k">exit</span><span class="p">(</span><span class="n">b</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">init</span><span class="p">;</span>
<span class="n">f</span><span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="m">2</span><span class="p">]:=</span><span class="n">map</span><span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="m">2</span><span class="p">]+</span><span class="n">map</span><span class="p">[</span><span class="m">2</span><span class="p">,</span><span class="m">1</span><span class="p">];</span> <span class="c1">// 第一步需特殊处理
</span> <span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span><span class="p">+</span><span class="n">n</span><span class="p">-</span><span class="m">4</span> <span class="k">do</span> <span class="c1">//从上一个状态推下一个
</span> <span class="k">begin</span>
<span class="k">for</span> <span class="n">x1</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">y1</span><span class="p">:=</span><span class="n">i</span><span class="p">+</span><span class="m">3</span><span class="p">-</span><span class="n">x1</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">y1</span><span class="p"><</span><span class="m">1</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">y1</span><span class="p">></span><span class="n">n</span><span class="p">)</span> <span class="k">then</span> <span class="n">continue</span><span class="p">;</span>
<span class="k">for</span> <span class="n">x2</span><span class="p">:=</span><span class="n">x1</span><span class="p">+</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span> <span class="c1">//大于x1就行,否则有重复
</span> <span class="k">begin</span>
<span class="n">y2</span><span class="p">:=</span><span class="n">i</span><span class="p">+</span><span class="m">3</span><span class="p">-</span><span class="n">x2</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">y2</span><span class="p"><</span><span class="m">1</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">y2</span><span class="p">></span><span class="n">n</span><span class="p">)</span> <span class="k">then</span> <span class="n">continue</span><span class="p">;</span>
<span class="n">temp</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">if</span> <span class="n">x1</span><span class="p">></span><span class="m">1</span> <span class="k">then</span> <span class="n">temp</span><span class="p">:=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">x1</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">x2</span><span class="p">-</span><span class="m">1</span><span class="p">];</span>
<span class="k">if</span> <span class="n">y2</span><span class="p">></span><span class="m">1</span> <span class="k">then</span> <span class="n">temp</span><span class="p">:=</span><span class="n">max</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">x1</span><span class="p">,</span><span class="n">x2</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x1</span><span class="p">></span><span class="m">1</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">y2</span><span class="p">></span><span class="m">1</span><span class="p">)</span> <span class="k">then</span> <span class="n">temp</span><span class="p">:=</span><span class="n">max</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">x1</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">x2</span><span class="p">]);</span>
<span class="k">if</span> <span class="n">x1</span><span class="p">+</span><span class="m">1</span><span class="p"><></span><span class="n">x2</span> <span class="k">then</span> <span class="n">temp</span><span class="p">:=</span><span class="n">max</span><span class="p">(</span><span class="n">temp</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">x1</span><span class="p">,</span><span class="n">x2</span><span class="p">-</span><span class="m">1</span><span class="p">]);</span>
<span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">+</span><span class="m">1</span><span class="p">,</span><span class="n">x1</span><span class="p">,</span><span class="n">x2</span><span class="p">]:=</span><span class="n">temp</span><span class="p">+</span><span class="n">map</span><span class="p">[</span><span class="n">x1</span><span class="p">,</span><span class="n">y1</span><span class="p">]+</span><span class="n">map</span><span class="p">[</span><span class="n">x2</span><span class="p">,</span><span class="n">y2</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">f</span><span class="p">[</span><span class="n">m</span><span class="p">+</span><span class="n">n</span><span class="p">-</span><span class="m">3</span><span class="p">,</span><span class="n">m</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">m</span><span class="p">]);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
O2Jam-V3
2008-12-21T02:22:36+00:00
http://greenmooon55.com/o2jam-v3
<p>先说一下是最简单的V3。。</p>
<p>昨天用<a href="http://www.o2mania.com/">O2Mania</a>玩的,这么长时间终于没bad了。感觉O2Jam很难<em>_</em>,现在也就能玩到六级。还有现在新歌太少了。</p>
<p><img src="http://greenmoon55.com/wp-content/uploads/2008/12/20081221095826468.png" alt="20081221095826468" />
<img src="http://greenmoon55.com/wp-content/uploads/2008/12/20081221095833546.png" alt="20081221095833546" /></p>
<p>就是这个歌,这是别人的,我是只用1.5速玩的。</p>
NOIP2008笨小猴
2008-12-13T16:43:50+00:00
http://greenmooon55.com/noip2008-tg-p1
<p>NOIP2008提高组第一题,没什么说的。。没事闲的再打一遍。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">p1495</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">s</span><span class="p">:</span><span class="k">string</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">max</span><span class="p">,</span><span class="n">min</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">ch</span><span class="p">:</span><span class="kt">char</span><span class="p">;</span>
<span class="n">count</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="s">'a'</span><span class="p">..</span><span class="s">'z'</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">used</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="s">'a'</span><span class="p">..</span><span class="s">'z'</span><span class="p">]</span> <span class="k">of</span> <span class="kt">boolean</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">prime</span><span class="p">(</span><span class="n">x</span><span class="p">:</span><span class="kt">longint</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">p</span><span class="p">:</span><span class="kt">boolean</span><span class="p">;</span> <span class="c1">//质数否
</span><span class="k">begin</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span><span class="p">=</span><span class="m">1</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">x</span><span class="p">=</span><span class="m">0</span><span class="p">)</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'No Answer'</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="m">0</span><span class="p">);</span>
<span class="n">halt</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">p</span><span class="p">:=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">2</span> <span class="k">to</span> <span class="n">trunc</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> <span class="k">do</span> <span class="k">if</span> <span class="n">x</span> <span class="k">mod</span> <span class="n">i</span><span class="p">=</span><span class="m">0</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">p</span><span class="p">:=</span><span class="nb">false</span><span class="p">;</span>
<span class="n">break</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">p</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'Lucky Word'</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">x</span><span class="p">);</span>
<span class="k">end</span> <span class="k">else</span>
<span class="k">begin</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'No Answer'</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="m">0</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">count</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">count</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">length</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]]);</span>
<span class="n">used</span><span class="p">[</span><span class="n">s</span><span class="p">[</span><span class="n">i</span><span class="p">]]:=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">max</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">min</span><span class="p">:=</span><span class="n">maxint</span><span class="p">;</span>
<span class="k">for</span> <span class="n">ch</span><span class="p">:=</span><span class="s">'a'</span> <span class="k">to</span> <span class="s">'z'</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="k">not</span> <span class="n">used</span><span class="p">[</span><span class="n">ch</span><span class="p">]</span> <span class="k">then</span> <span class="n">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="n">count</span><span class="p">[</span><span class="n">ch</span><span class="p">]></span><span class="n">max</span> <span class="k">then</span> <span class="n">max</span><span class="p">:=</span><span class="n">count</span><span class="p">[</span><span class="n">ch</span><span class="p">];</span>
<span class="k">if</span> <span class="n">count</span><span class="p">[</span><span class="n">ch</span><span class="p">]<</span><span class="n">min</span> <span class="k">then</span> <span class="n">min</span><span class="p">:=</span><span class="n">count</span><span class="p">[</span><span class="n">ch</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">prime</span><span class="p">(</span><span class="n">max</span><span class="p">-</span><span class="n">min</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
High School Musical
2008-12-13T16:06:29+00:00
http://greenmooon55.com/high-school-musical
<p>以前在C6看过歌舞青春2,想看新出的3,没找到好的只好去下1,趁周三放假看的,感觉还不错,最喜欢musicale auditions那段。</p>
<p>本本没播放软件,下了QQ影音,很喜欢。无广告,支持大部分格式,不用像KMplayer再去下解码包。隐藏菜单、外观和其他QQ软件配套。支持双字幕,不过不支持手动加载双字幕。关了硬件加速截的图,效果不太好。</p>
<p><img src="http://greenmoon55.com/wp-content/uploads/2008/12/20081213235323828.png" alt="" /></p>
<p>(Emule)下载地址:<a href="http://www.verycd.com/topics/120201/">http://www.verycd.com/topics/120201/</a></p>
<p>PS:
现在在学自然码,刚把<a href="http://www.google.com/support/pinyin/bin/answer.py?hl=cn&answer=93317">双拼</a>背下来,但很不熟练。
晚上无线网络真稳定,刚才还总掉线。
EPSNAP官网终于挂了,多优秀的国产软件啊。。
明天升级WP去,还用英文版吧。
跑题了。。</p>
NOIP2008前后的RP
2008-11-30T01:08:05+00:00
http://greenmooon55.com/noip2008-rp
<p>考前两周</p>
<p>发现我在学校用的机器屏幕偶尔会闪一下,感觉不是眼睛的错觉。偶尔开机显示器无信号,得按电源按钮10s关掉再开。</p>
<p>考前周一</p>
<p>电脑彻底玩完,换显示器没用,重插内存条没用。用旁边的人(居然300分,省第四)的机子测出我的显示器没坏,只好趁自习用别人的。</p>
<p>PS:某天还在微机室待到21:40,感觉超级爽,当时没想到是最后一次。。</p>
<p>考前周五</p>
<p>英语课,居然叫我去写虚拟语气选择题答案,我前面的先写,他可是@#¥%,我很垃圾的。他写完和我有40%不一样。。。对答案的时候我只错一个(或许是两个),基本上都是他错的。</p>
<p>NOIP 2008</p>
<p>高一高二居然不上课,不爽^_^,不过也不用补课了,会不会给外地的留下周六不补课的印象~~外地的居然以没有花的花坛为背景照相,不明白问什么不转过去照那边的湖。
详见<a href="http://greenmoon55.com/my-oi-way/">我的OI之路</a>。对题目RP还是很高的,不过最后发现两个问题,最后一题break忘打分号,第三题忘记fillchar,改完之后没有装到桌面的文件夹里。让走的时候才想起来,copy到桌面的文件夹就走了,有点惊险。
还有就是11点的时候copy、重命名后fc了一遍程序,弄得有点乱。</p>
<p>PS:
NEPCS没过,116分,应该是后面丢分太多了,主要是作文吧,听力题感觉出得很好,几乎正好是我的极限。我们班有个130+直接进的。
以后这里写点什么呢?每周再学点OI吧,现在去写作业。。</p>
我的OI之路
2008-11-16T15:19:03+00:00
http://greenmooon55.com/my-oi-way
<p>清楚地记得我是从小学的某一天开始喜欢计算机的,下面大概写一下OI的经历。</p>
<p><strong>初中</strong></p>
<p>微机老师选数学好或计算机好的学生去学OI,貌似我是因为数学好被班主任选去自习课上课,当时班里去了好几个人学基础的pascal编程,只用Turbo Pascal,偶尔还能上上网,那时候就知道<a href="http://www.mydrs.org">大榕树</a>了,但不知道OIBH(或许那时候还没有),那时候经常玩暴力摩托。。至于学了什么,当时学了基本语句,什么var, begin, end 都讲了,变量类型只知道integer,我会的最难的语句就是for循环,当时还懂了栈的定义。</p>
<p>普及组初赛那天是下午,坐学校的班车去很远的地方考的,还看到了什么“自制火箭”(PS:豆瓣上<a href="http://www.douban.com/group/jlhscrewyou/">小组</a>有个帖子讨论OI,大家一说就发现04年都在那里考了,可惜现在找不到帖子了,MS被删了)。凭借对电脑的熟悉,选择打得很好。考试之前听说上一年分数线是40分,当时考完就觉得是40分以上,结果是41分,不过那年因为题简单,分数线是50。从此初中就远离OI了。后来也在家下过VB和易语言玩过,不过什么都不懂。</p>
<p>初三寒假,听说jlyz招各科竞赛大牛,就去报了。前几天还装模作样的拿出<a href="http://product.dangdang.com/product.aspx?product_id=8801663">买的书</a>看(现在好像找不到了~)。考试时,第一次看到FP,感觉背景很神奇。。第一次看到那么多张纸的题(A4),只会第一题,本来想打一下,忘了integer怎么拼,看了很长时间帮助也没找到,于是就放弃了。半小时之后,我撤了。那天是3月4日,东北下大雪,学校停课两天。那也是我第一次来YZ,感觉校园很大,桌椅很好。</p>
<p><strong>高中</strong></p>
<p>本来以为OI与我已经没什么联系了,没想到微机课发了广告,招学生学这个,于是很高兴地参加了。第一天讲课是9月10日教师节。我和pjl决定人多就去上课,人少就去看初中老师,最后还是去听了怎么打开和关闭FP,以后慢慢的就学到了procedure, function, 数组什么的,NOIP前几天还讲了进制转换。。那时候大部分人已经跟不上了。PS:我NOIP前几天还傻乎乎的想自学DP。。我拿到准考证时还在<strong>诧异为什么是提高组</strong>,以为弱省是普及,强省才是提高。。考试时不会快排,别的排序也不太熟悉,所以第一题根本没做!剩余的时间基本都在打第二题,第四题输出0骗到10分,最后打多少也不知道,没找到人。PS:前几天打去年的第二题也才得60分,最烦恶心模拟题。</p>
<p>寒假培训是从08年1月17日开始的,我还拿到了好像0分就得奖的三等奖奖状。寒假学到了qsort,递归等等。(忘了DP, dfs, bfs是什么时候学得了,好像是开学后学的)整个假期都在做zoj的模拟、贪心,总之都是很简单的题目,然后发到<a href="http://www.jlyzoi.cn">学校论坛</a>上。</p>
<p>小马马老师以某年第四题讲01背包的时候我感觉很爽,从搜索到DP,再到滚动数组、最后讲一维数组直接做,再加上循环终值的优化好像都是一起讲完的。我除了最后一种方法以外都理解的不错,最后一种方法也很快想懂了。当时想是不是这个就是“算法艺术”。</p>
<p>后来就开始做USACO和ZOJ的题,也做了一些DP题,但没有一道是自己直接做出来的。暑假的时间也没有好好利用,留的题都没做完(虽然大多数人和我一样),就算是一天能做一道的话也能提高很多。</p>
<p>这学期又做了一阵USACO,然后就开始做近几年NOIP普及组和提高组的题。我做的慢比几个人慢,但也不知道为什么,或许是他们时间多,和我交流的人比我做的都少。到了复赛前一周才基本做完,好像剩3题没做,其中两道是恶心的模拟,另一道是去年第三题高精DP,没时间做这个了。在这个过程中学到石子归并的DP和高精度乘法。</p>
<p>近几年NOIP中印象最深的是过河(river),那道题是周六下午开始在微机室想,周日看了N多人的题解,晚上才想明白,然后AC了。周一音乐课(或许是美术)上想到可能会超过maxlongint,测了一下自己编的数据果然如此,后来自己给改了。这是自己想题时间最长的一次。</p>
<p>复赛前一周基本上都是晚上12点睡,所以数学讲的椭圆没怎么学。。</p>
<p><strong>NOIP 2008</strong></p>
<p>初赛81.5,和预想的差不多,省第12,要是复赛者名次就好了。最后一题不太懂,快排那题把if then 看成 while do,没理解要干嘛。。不过我答案应该也是对的。</p>
<p>复赛又是在本校,jlyz又是全省参赛人数最多的,抽签又抽到旧电脑,发现空格不太好用。装了3个FP(for noi, 2.0.2, 2.0.4),还装了notepad++。第一个字大,放弃,经测试2.0.4 alt+x 关闭时会自动保存,这个很不爽,于是就用了2.0.2。</p>
<p>目前还<strong>不知道成绩</strong>(联系不到老师5555555),下面纯属瞎扯:</p>
<p>考前没敢在网上发”bless”,初中在网上许愿后考得很垃圾留下阴影了。听巨牛zys的话,花了一段时间看题。看完前三题,感觉似乎不难,也<strong>感觉到第三题一定是经典DP</strong>,就是不会。。很仔细地开始做题,10多分钟做完第一题,打的时候就想过0、1的处理,好像是一次编译就OK了。然后开始看第二题,不会,想了想,捞分重要,去看第三题,更不会。。又回来想第二题,虽然都说要想好再打,我还是边想边打,搜所有可能情况,然后分三段,转成字符串再val成longint求和,只改了一个地方就过了两组样例。测了一下24时绝对也在1s以内出解。又试着输出第二组样例和n=24是的可行解,好像很正常。记住了n=24的答案:128。此时9:30。第三题想了十多分钟DP,没想出来,于是打搜索,搜出一条路径再从头搜下一条。打了很长时间,也调了一会才过样例。经测试30*30的数据就会超时,而且<strong>今天早上才想起来</strong>我第一次搜索就选择f[x,y]+map[tx,ty]<f[tx,ty]就不搜,这显然是不对的,我练习搜索也很少,出错比较正常。第四题最开始输出0骗分,后来又想骗顺序数据,输出a b a b,后来看到最小字典序就改成a a b b了,10分啊。花了半个多小时检查输入输出什么的,发现第三题没有fillchar visit数组,改过来了,到时间才发现没往要求的文件夹里存,不过当然,还是存进去了。还有考试之前发现电脑时间晚了一小时,赶快给改了回来,怕出问题。</p>
<p>出来以后很自信,心想大约250应该差不多1=吧,不一会就想到骗分骗错了。等到晚上5点,应该成绩出来了,没接到电话,心里很紧张,说明可能。。。后来就放松了。上OIBH上发消息给本省外地的某牛,答曰他230考砸了,分数线应该250以上。我没想到分数线提高这么多,今天群里消息是250上下10分。估计没希望了,除非RP大爆发+ccf真正全文比对必须换行才有可能。明天中午去看成绩,应该是二等的前几名吧(乐观地说)。</p>
<p>现在的问题是我应该怎么办?NOIP 2009是肯定要参加的了,在家做题是一定的,但是还接着学OI吗?马老师能让吗?班主任应该不清楚这些,应该不会管。家长也不会管。接着学指的是省队,显然不现实,半年明显达不到,即使达到,noi也什么都不是。但是我真的还想学,或许上大学再ACM,要是noip 2009没拿到1=拼高考去zju之类的也有点困难。</p>
<p>十一点了,时间过得好快。周五晚上写“和谐”为话题的作文,写得我晚饭都吃不下去。。</p>
<p>最后第一次bless一下所有oier,特别是高三没拿到1=,或没writeln 0分、不知CCF怎么处理,还有那个程序被还原的湖北<a href="http://www.oibh.org/bbs/viewthread.php?tid=27096">那个oier</a>..</p>
<p>又去oibh看了一眼,都在谈退役,都很伤心的样子。至少我们感受过OI,坚持着熬夜写代码,调试,至少我不是完全为了上大学学这个的。刚看了barty的“<a href="http://www.oibh.org/bbs/viewthread.php?tid=27116">最后的征途.pdf</a>“,或许我早点不上自习会有些帮助,不过没关系,一年的周末+寒暑假完全没问题。</p>
<p>Bless~</p>
期中考试流水帐
2008-10-31T10:50:24+00:00
http://greenmooon55.com/mid-of-term-exam-in-grade2
<p>是流水帐,没兴趣的不要看了~
<!-- more -->
Day 1 10.29
物理:最后一题tanα表示的是速度夹角,不知道所以错了。选择最后一个是高一知识。实验说要精确值,于是我就估读了,不知道对不对。
政治:选择果然都是练习册上的,当天上午花了1hr突击练习册,不过有的做完的也忘了。后面的大题是上课复习过的,话说似乎只有我傻乎乎的看没复习的,原来老师是知道题的。。
生物:很垃圾,感觉像答平时的卷一样,没感觉
Day 2 10.30
这天考三主科。。非本校出题。
语:前面还可以,背诵居然超纲。萤火虫吃蜗牛的材料作文很恶心,和mh写的题目差不多《提高警惕,远离诱惑》。这辈子最烦作文。
数:较简单,最后一道题晕了,不过错的人也很多。 2-2^(1-n)。。
英:听力居然考charred,没背,不会。后面的approve写成了approave,看来第一感觉还是很重要。完形是做过N遍的,这次发现hotel名是F1C中的一个赛道名。课文填空临时突击没起作用,得-2。
Day 3 Today
化:实验题一点不会,因为没认真做实验?最后一题差点错了,原来是计算错误。5.6/22.4不等于0.4等于0.25..
历史:选择50分,填空20分,只有一个大题30分,都蒙上了,及格没问题。在2考场也有超快交卷的,呵呵。(全是练习册上的题)
地理:晕死,选择题基本1秒一个,全是上午练习册上的题。大题也是指定卷上的,有几个问以前做过,但全忘没了。。10min答完1hr的卷感觉很好。mh16:15走的,后来我检查出选择的一个错误,20多走的。Cool 还是自然地理好^_^
———–
本来这次就没想好好考,复习时间约等于0。借口是NOIP,其实也没干什么。
To-do List
1.NOIP题…
2.二叉排序树
3.最小生成树
4.ZOJ1119 huffman POJ xxxx 染色问题。
—————————-
blogspot封了,zeng.jingyan的live blog 也封了,又看了一些关于胡+的事。</p>
合并果子
2008-10-12T10:20:35+00:00
http://greenmooon55.com/noip2004-fruit
<p>这是NOIP2004年提高组的一道题,随便搜索就能找到,VIJOS和RQNOJ都有。</p>
<p>这道题有很多很多种做法,首先最重要的是仔细读题,题中合并可以不按顺序,所以就不是石子归并的DP,直接贪心找最小即可。估计这道题当年坑了很多人。还有刚开始考虑时间复杂度,写得不一定对。。错了请指出来。</p>
<p>方法一,也就是最容易想到的,快排+插入排序。时间复杂度为O(n^2)。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">program</span> <span class="n">fruit</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span><span class="n">i</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">a</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..10000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">ans</span><span class="p">,</span><span class="n">temp</span><span class="p">,</span><span class="n">s</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">qsort</span><span class="p">(</span><span class="n">left</span><span class="p">,</span><span class="n">right</span><span class="p">:</span><span class="kt">longint</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">p</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">i</span><span class="p">:=</span><span class="n">left</span><span class="p">;</span>
<span class="n">j</span><span class="p">:=</span><span class="n">right</span><span class="p">;</span>
<span class="n">p</span><span class="p">:=</span><span class="n">i</span><span class="p">+</span><span class="n">random</span><span class="p">(</span><span class="n">j</span><span class="p">-</span><span class="n">i</span><span class="p">);</span>
<span class="n">x</span><span class="p">:=</span><span class="n">a</span><span class="p">[</span><span class="n">p</span><span class="p">];</span>
<span class="n">a</span><span class="p">[</span><span class="n">p</span><span class="p">]:=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">while</span> <span class="n">i</span><span class="p">=</span><span class="n">x</span><span class="p">)</span> <span class="k">do</span> <span class="k">inc</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]:=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]:=</span><span class="n">x</span><span class="p">;</span>
<span class="k">if</span> <span class="n">i</span><span class="p">></span><span class="n">left</span> <span class="k">then</span> <span class="n">qsort</span><span class="p">(</span><span class="n">left</span><span class="p">,</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">);</span>
<span class="k">if</span> <span class="n">i1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="p">-</span><span class="m">1</span><span class="p">]:=</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="p">-</span><span class="m">1</span><span class="p">]+</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
<span class="n">dec</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="n">s</span><span class="p">:=</span><span class="n">s</span><span class="p">+</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
<span class="n">i</span><span class="p">:=</span><span class="n">n</span><span class="p">-</span><span class="m">1</span><span class="p">;</span> <span class="c1">//这个地方很容易错,不减1则无法进入循环。
</span> <span class="n">temp</span><span class="p">:=</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">i</span><span class="p">></span><span class="m">0</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">temp</span><span class="p">></span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">+</span><span class="m">1</span><span class="p">]:=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">dec</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">+</span><span class="m">1</span><span class="p">]:=</span><span class="n">temp</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>方法二,堆排序,刚学的。时间复杂度为O(nlogn)</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">program</span> <span class="n">heaptest</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">s</span><span class="p">,</span><span class="n">t</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">a</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..10000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">shift</span><span class="p">(</span><span class="n">k</span><span class="p">:</span><span class="kt">longint</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">,</span><span class="n">x</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">x</span><span class="p">:=</span><span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="p">];</span>
<span class="n">i</span><span class="p">:=</span><span class="m">2</span><span class="p">*</span><span class="n">k</span><span class="p">;</span>
<span class="k">while</span> <span class="n">i</span><span class="p"><=</span><span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="p"><</span><span class="n">n</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]></span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">+</span><span class="m">1</span><span class="p">])</span> <span class="k">then</span> <span class="k">inc</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="k">if</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="m">1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">x</span><span class="p">:=</span><span class="n">a</span><span class="p">[</span><span class="m">1</span><span class="p">];</span>
<span class="n">a</span><span class="p">[</span><span class="m">1</span><span class="p">]:=</span><span class="n">a</span><span class="p">[</span><span class="n">n</span><span class="p">];</span>
<span class="n">dec</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="n">shift</span><span class="p">(</span><span class="m">1</span><span class="p">);</span>
<span class="n">y</span><span class="p">:=</span><span class="n">a</span><span class="p">[</span><span class="m">1</span><span class="p">];</span>
<span class="n">s</span><span class="p">:=</span><span class="n">s</span><span class="p">+</span><span class="n">x</span><span class="p">+</span><span class="n">y</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="m">1</span><span class="p">]:=</span><span class="n">x</span><span class="p">+</span><span class="n">y</span><span class="p">;</span>
<span class="n">shift</span><span class="p">(</span><span class="m">1</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">s</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>方法三,构造huffman树,而且可以简略一些,最后循环输出权值即可。但是只能过几组数据,会超时。时间复杂度O(n^2)。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">program</span> <span class="n">fruitvhuffman</span><span class="p">;</span>
<span class="k">type</span>
<span class="n">node</span><span class="p">=</span><span class="k">record</span>
<span class="n">parent</span><span class="p">:</span><span class="kt">boolean</span><span class="p">;</span>
<span class="n">data</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">a</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..19999</span><span class="p">]</span> <span class="k">of</span> <span class="n">node</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">ans</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">function</span> <span class="n">min</span><span class="p">(</span><span class="n">h</span><span class="p">:</span><span class="kt">longint</span><span class="p">):</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">m</span><span class="p">,</span><span class="n">i</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">m</span><span class="p">:=</span><span class="n">maxlongint</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">h</span> <span class="k">do</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">parent</span><span class="p">=</span><span class="nb">false</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">data</span><span class="p"><</span><span class="n">m</span><span class="p">)</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">m</span><span class="p">:=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">data</span><span class="p">;</span>
<span class="n">min</span><span class="p">:=</span><span class="n">i</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span><span class="s">'fruit.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span><span class="s">'fruit.out'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">a</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="k">read</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">data</span><span class="p">);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="k">for</span> <span class="n">k</span><span class="p">:=</span><span class="n">n</span><span class="p">+</span><span class="m">1</span> <span class="k">to</span> <span class="m">2</span><span class="p">*</span><span class="n">n</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">i</span><span class="p">:=</span><span class="n">min</span><span class="p">(</span><span class="n">k</span><span class="p">-</span><span class="m">1</span><span class="p">);</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">parent</span><span class="p">:=</span><span class="nb">true</span><span class="p">;</span>
<span class="n">j</span><span class="p">:=</span><span class="n">min</span><span class="p">(</span><span class="n">k</span><span class="p">-</span><span class="m">1</span><span class="p">);</span>
<span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">].</span><span class="n">parent</span><span class="p">:=</span><span class="nb">true</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="p">].</span><span class="n">data</span><span class="p">:=</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">data</span><span class="p">+</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">].</span><span class="n">data</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="n">n</span><span class="p">+</span><span class="m">1</span> <span class="k">to</span> <span class="m">2</span><span class="p">*</span><span class="n">n</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span> <span class="k">inc</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">data</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">ans</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>方法四,时间复杂度为O(n)。一下说明及程序均来源于<a href="http://yinyifan.com/blog/2008/10/noip2004_fruit_report">Misty Sky</a> (CC by-nc-sa)</p>
<blockquote>
<p>其实,这道题目还有一种更简单的做法,考虑到每次合并两个结点以后,得到的新结点大小是递增的,于是可以维护两个队列,一个是原队列A,一个是新加入的队列B。每次就一定是在A或(和)B的首部取数,在B的尾部插入。</p>
</blockquote>
<p>另外因为a[i]很小只有20000,所以可以使用基数排序,这样整体的时间复杂度就是O(n)。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">var</span>
<span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span> <span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..20000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">la</span><span class="p">,</span><span class="n">ra</span><span class="p">,</span><span class="n">lb</span><span class="p">,</span><span class="n">rb</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">p</span> <span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">sum</span> <span class="p">:</span> <span class="n">qword</span><span class="p">;</span>
<span class="k">function</span> <span class="n">get</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">la</span><span class="p">></span><span class="n">ra</span> <span class="k">then</span> <span class="k">begin</span> <span class="k">inc</span><span class="p">(</span><span class="n">lb</span><span class="p">);</span> <span class="k">exit</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="n">lb</span><span class="p">-</span><span class="m">1</span><span class="p">]);</span> <span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">lb</span><span class="p">></span><span class="n">rb</span> <span class="k">then</span> <span class="k">begin</span> <span class="k">inc</span><span class="p">(</span><span class="n">la</span><span class="p">);</span> <span class="k">exit</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">la</span><span class="p">-</span><span class="m">1</span><span class="p">]);</span> <span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">a</span><span class="p">[</span><span class="n">la</span><span class="p">]</span> <span class="p"><</span> <span class="n">b</span><span class="p">[</span><span class="n">lb</span><span class="p">]</span> <span class="k">then</span> <span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">la</span><span class="p">);</span>
<span class="k">exit</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">la</span><span class="p">-</span><span class="m">1</span><span class="p">]);</span>
<span class="k">end</span>
<span class="k">else</span> <span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">lb</span><span class="p">);</span>
<span class="k">exit</span><span class="p">(</span><span class="n">b</span><span class="p">[</span><span class="n">lb</span><span class="p">-</span><span class="m">1</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="k">begin</span>
<span class="k">read</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">inc</span><span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">ra</span> <span class="p">:=</span> <span class="m">0</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="m">20000</span> <span class="k">do</span>
<span class="k">while</span> <span class="k">not</span> <span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">=</span> <span class="m">0</span><span class="p">)</span> <span class="k">do</span> <span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">ra</span><span class="p">);</span>
<span class="n">a</span><span class="p">[</span><span class="n">ra</span><span class="p">]</span> <span class="p">:=</span> <span class="n">i</span><span class="p">;</span>
<span class="n">dec</span><span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">la</span> <span class="p">:=</span> <span class="m">1</span><span class="p">;</span>
<span class="n">lb</span> <span class="p">:=</span> <span class="m">1</span><span class="p">;</span> <span class="n">rb</span> <span class="p">:=</span> <span class="m">0</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="p">-</span> <span class="m">1</span> <span class="k">do</span> <span class="k">begin</span>
<span class="n">p</span> <span class="p">:=</span> <span class="n">get</span> <span class="p">+</span> <span class="n">get</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">rb</span><span class="p">);</span>
<span class="n">b</span><span class="p">[</span><span class="n">rb</span><span class="p">]</span> <span class="p">:=</span> <span class="n">p</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">,</span><span class="n">p</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">sum</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>下面是用CENA的时间对比
```</p>
<p>名称</p>
<p>排名</p>
<p>总得分</p>
<p>有效用时</p>
<p>array</p>
<p>1</p>
<p>100</p>
<p>0.16</p>
<p>heap</p>
<p>2</p>
<p>100</p>
<p>0.23</p>
<p>qsort+insert</p>
<p>3</p>
<p>100</p>
<p>1.97</p>
<p>randomqsort+insert</p>
<p>4</p>
<p>100</p>
<p>2.01</p>
<p>huffman</p>
<p>5</p>
<p>50</p>
<p>0.98</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>MS这篇不应该写,没什么意义。。就当是备份程序了。换了个显示程序的插件,美观些。
```
```
08.10.19 修改了一下heapsort的代码
</code></pre></div></div>
新加坡不属于法拉利
2008-09-28T15:24:09+00:00
http://greenmooon55.com/2008-f1-singapore-gp
<p>第一场F1夜战的胜利属于远离第一很久的Alonso了,正如官网的新闻<a href="http://www.formula1.com/results/season/2008/801/6568/">Alonso springs a Singapore surprise</a>。</p>
<p><a href="http://www.formula1.com/results/season/2008/801/6567/">排位</a>MC有些挣扎,Ferrari1、3,MAS以0.6秒多的优势轻松拿到杆位,这让Ferrari车迷稍稍放了点心。</p>
<p>正赛开始,只一圈MAS就带开很远,KIMI渐渐的也被HAM带开了。后来Kimi变得很快,从此到第一次SC出现前<strong>速度一直是Kimi>HAM>MAS</strong>,最快圈速Ferrari也要快得多,说明法拉利在街道赛(Monaco, Valencia)上还不错。三人也有2s以上距离。随后出现的事就人人皆知了,很明显绿灯亮了,然后又很快被调回红灯,Kimi也因此耽误了很多时间,出去都P15了,与HAM距离相当远。MAS几次失误、KIMI最后退赛和心态、体力都有关。</p>
<p>一、谈一下法拉利的<strong>灯光信号</strong>。这已经不知道是第几次出错了,个人觉得很显然看上面的灯要比看前面抬起更需要注意力。另外,注意一下法拉利的进站花费的时间,<strong>个人感觉有些慢</strong>,至少不快。感觉今年Spa的最后一次进站也缩短了HAM和KIMI的距离,但这好像和灯光信号关系不大。 Link: <a href="http://sports.sina.com.cn/f1/2008-08-27/12193906152.shtml">L-Pod”代替“棒棒糖” 法拉利否认系统过于复杂</a></p>
<p>二、新加坡赛道的难度。新加坡赛道真是难啊,感到难可不是听解说员说的。排位看KOV的车载就看出来很难了,今天找到F1C版的赛道,用mania2008 PRO mod开了<strong>十多圈都不熟练</strong>,刹车点难掌握,转向很费劲,常常撞车。后来又开了一下瓦伦西亚街道,<strong>2圈</strong>就熟悉很多。记得以前开A1-RING,<strong>一圈</strong>就熟悉了。</p>
<p>三、根据KIMI的载油量(比HAM多很多啊),如果MAS不出错,<strong>KIMI很可能紧跟在HAM后面</strong>,如果和第一次进站前一样,或许能超过HAM,包揽12。不过这个可能性比较低,因为即使不出错,KIMI也会等很长时间,这在06年MSC和MAS组合时常常是MSC被挡,原因还是法拉利两名车手<strong>往往很近</strong>,而MC一般会很远,在一圈进站也没什么影响。</p>
<p>看到KIMI退赛,我的第一反应就是还原全屏的PPS,发条<a href="http://twitter.com/greenmoon55/statuses/938103496">消息</a>,看台上有很多人离开,说明法拉利车迷还是很多的。HAM以第三完赛,MC就领先一分了,法拉利今年或许两个冠军都拿不到,因为后面的上海和日本雨站多。一旦雨站,法拉利几乎一定输。</p>
<p>其实今天的比赛能坚持下来就不错了,最后在恭喜一下ALO。真难得的胜利!不知道他2010年会不会来Ferrari,很多人都不能接受他,当年最大的对手就要变成自家人了吗?不管那些了,最后3站,希望法拉利能像去年一样追回来。<strong>无论如何我都会继续支持红色法拉利。</strong></p>
<p>另外说一下,今天看的是PPS上的上视纪实,信号不太好,断了一两次,没昨天TVUPlayer的上视体育好。</p>
FreePascal 2.2.2无法编译解决办法
2008-09-14T03:04:02+00:00
http://greenmooon55.com/freepascal222-compilation-aborted
<p>2.2.2是今年8月11号更新的,没感觉到有什么新东西,可是装上之后无法编译。Google到了解决办法,不过现在忘记在哪里看到的了,应该是freepascal.org的社区里。</p>
<p>错误提示:</p>
<blockquote>
<p>Fatal: Unable to open file D:FPC2.2.2bini386-win32fp.cfg
Fatal: Compilation aborted</p>
</blockquote>
<p>解决办法:删除安装目录下的fp.cfg即可,比如这个D:FPC2.2.2bini386-win32fp.cfg。 貌似Freepascal一有问题删掉配置文件就行。</p>
<p><a href="http://bugs.freepascal.org/view.php?id=11864">这是</a>freepascal里bugtracker的描述,应该就是这个问题。</p>
Delicious更新了
2008-08-01T14:38:25+00:00
http://greenmooon55.com/delicious-update
<p><img src="http://greenmoon55.com/wp-content/uploads/2008/08/20080801223303406.png" alt="" />
从今年3月15日起,我就一直用简单好用的delicious作为在线收藏夹。</p>
<p><a href="http://www.techcrunch.com/2007/09/06/exclusive-screen-shots-and-feature-overview-of-delicious-20-preview/">2007年9月</a>,这个Delicious 2.0就开始preview了,现在我们终于可以看到新版了。这是<a href="http://parandroid.com/delicious-bookmarks-delicious-new-release/">翻译的更新说明</a>,官方<a href="http://delicious.com/help/whatsnew">What’s New</a>界面也有介绍。新功能我倒是没感觉到什么,我只是觉得新界面看着很不舒服(<a href="http://twitter.com/greenmoon55/statuses/874215854">twitter</a>)。官方还开了一个<a href="http://support.delicious.com/forum/">论坛</a>,有很多人在抱怨,当然也有支持的。</p>
<p>这是<a href="http://delicious.com/greenmoon55">我的delicious</a>,看看就知道新版长什么样了。</p>
<p>我感觉到的更新内容:</p>
<blockquote>
<p>最有特色的del.icio.us改了,<a href="http://blog.delicious.com/blog/2008/07/oh-happy-day.html">官方解释</a>是容易拼写错。
以前用文字表示的tags等等都变成了图片,每个收藏都以格子形式表示,tag排到格子右下侧。页面中间也没多大空隙。这是我最烦的。
右侧多出来top 10 tags,取消了unbundled tags。
tag显示方式被做成tag options,默认不显示。all tags只加粗,不会根据使用频率改变字号。
多出来tags专页,字号会改变。</p>
</blockquote>
<p>总之我现在是越来越怀念以前的版本,但是论坛里开发组说改不回去,只能在新版界面上修改。我也很少去,只是常用FF扩展添加收藏。希望这个界面快点改进,还是简单的文本版好。</p>
淘宝禁售国外原版书
2008-07-27T04:28:28+00:00
http://greenmooon55.com/selling-foreign-books-is-not-permitted-on-taobao
<blockquote>
<p>亲爱的书籍类卖家:
淘宝网于2008年7月19日针对一级类目下“书籍/杂志/报纸”的二级类目“国外原版书/台版、港版书”做整改措施,只保留“生活类原版书”,其余都做不计数下架删除。
关于“港澳台”相关书籍涉及政治,色情,邪教等书籍的会员,属违规行为或违法行为,淘宝网将继续加大查处力度,给于严厉冻结账户处罚。</p>
</blockquote>
<p>最开始是在阿里旺旺上的NG群上看到的。这下<a href="http://www.ngfans.com/">NG</a>买不到了,我只买过一期,是5月的中国特刊。
在我这个小地方,淘宝几乎是买这些书的唯一渠道。(虽然我也不怎么买)针对奥运?那应该允许啊,根据这口气好像永久禁卖,不过现在还是可以访问的。点<a href="http://list.taobao.com/browse/33-50004870/50004870.htm?commend=all">这里</a>试试。</p>
Zju1366 Cash Machine
2008-07-26T08:42:12+00:00
http://greenmooon55.com/zju1366
<blockquote>
<p><a href="http://acm.zjnu.cn/bbs/showt.asp?boardid=2&id=120">翻译</a>
735 3 4 125 6 5 3 350
735代表要构成的货币数,3代表有3种货币面值。
4 125代表有4个125元
6 5代表有6个5元
3 350代表有3个350元.输出:
735 利用上述的货币可以构成的离735最近的货币总量.</p>
</blockquote>
<p>0 <= cash <= 100000
0 <= N <= 10
这个题呢可以用Zju1149的方法,这样就很简单了。注意输入时最后要readln,否则本地没问题,传上去就WA了。至于优化呢,如果加上if ans[cash] then break;时间不变或者会加长时间(POJ上16ms变成32ms),不明白为什么。
<!-- more --></p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">zju1366</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">cash</span><span class="p">,</span><span class="n">num</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">d</span><span class="p">,</span><span class="n">n</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..10</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">ans</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">0..100000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">boolean</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">while</span> <span class="k">not</span> <span class="n">eof</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">ans</span><span class="p">),</span><span class="nb">false</span><span class="p">);</span>
<span class="k">read</span><span class="p">(</span><span class="n">cash</span><span class="p">,</span><span class="n">num</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">num</span> <span class="k">do</span> <span class="k">read</span><span class="p">(</span><span class="n">n</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="n">ans</span><span class="p">[</span><span class="m">0</span><span class="p">]:=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">num</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">cash</span> <span class="k">downto</span> <span class="m">0</span> <span class="k">do</span>
<span class="k">if</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">k</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">j</span><span class="p">+</span><span class="n">k</span><span class="p">*</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">lt</span><span class="p">;=</span><span class="n">cash</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">+</span><span class="n">k</span><span class="p">*</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="k">then</span> <span class="n">break</span>
<span class="k">else</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">+</span><span class="n">k</span><span class="p">*</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]]:=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">end</span>
<span class="k">else</span> <span class="n">break</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="n">cash</span> <span class="k">downto</span> <span class="m">0</span> <span class="k">do</span> <span class="k">if</span> <span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">]=</span><span class="nb">true</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="n">break</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
Zju1136 Multiple
2008-07-26T04:48:52+00:00
http://greenmooon55.com/zju1136
<p>http://acm.zju.edu.cn/show_problem.php?pid=1136</p>
<blockquote>
<p>http://www.jlyzoi.cn/dispbbs.asp?BoardID=8&id;=64
给定除数n和允许使用的数字个数m,然后求出用该m个数字组成的n的倍数的最小那个数是多少。如果不能输出0。</p>
</blockquote>
<p>BFS+余数相同的不用处理(这个叫同余?)
MS<a href="http://acm.zjnu.cn/bbs/showt.asp?boardid=2&id=432">这里</a>有测试数据,不过:</p>
<blockquote>
<p>http://acm.pku.edu.cn/JudgeOnline/problem?id=1465
大家去poj交一下。2、3楼交上去都是WA,只有4楼的AC了。
zoj上数据比较弱,我的在zoj上AC了,但是在poj上却WA。
目前已经知道程序有问题,但还不知道怎么改,还没看楼的,现在去看。
答案长度可能超过256,所以第一个不对,不能用字符串存。参照第二个做成procedure即可。
例:
4999
1
1
答案为357个1</p>
</blockquote>
<p>注意问题:不能用字符串存答案,而要存新加上的数,然后递归输出,因为有的答案超过256位,而s:=s+’1’是不会给错误提示的,一直是256位。
<!-- more -->
晕,串行了,点上面的view plain看吧。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">zju1136</span><span class="p">;</span>
<span class="k">type</span>
<span class="n">bfs</span><span class="p">=</span><span class="k">record</span>
<span class="n">a</span><span class="p">:</span><span class="kt">shortint</span><span class="p">;</span><span class="c1">//新增的数
</span> <span class="n">n</span><span class="p">,</span><span class="n">pre</span><span class="p">:</span><span class="kt">integer</span><span class="p">;</span><span class="c1">//n是余数,pre是上一位
</span> <span class="k">end</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="n">temp</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">l</span><span class="p">,</span><span class="n">r</span><span class="p">,</span><span class="n">t</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">ans</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">0..5000</span><span class="p">]</span> <span class="k">of</span> <span class="n">bfs</span><span class="p">;</span><span class="c1">//主数组
</span> <span class="n">find</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">0..4999</span><span class="p">]</span> <span class="k">of</span> <span class="kt">boolean</span><span class="p">;</span>
<span class="n">num</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..10</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span><span class="c1">//最开始的数
</span> <span class="n">done</span><span class="p">:</span><span class="kt">boolean</span><span class="p">;</span><span class="c1">//找到答案
</span><span class="k">procedure</span> <span class="n">print</span><span class="p">(</span><span class="n">i</span><span class="p">:</span><span class="kt">longint</span><span class="p">);</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">pre</span><span class="p">&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">gt</span><span class="p">;</span><span class="m">0</span> <span class="k">then</span> <span class="n">print</span><span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">pre</span><span class="p">);</span>
<span class="k">write</span><span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span><span class="s">'dongjin.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span><span class="s">'dongjin.txt'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">while</span> <span class="k">not</span> <span class="n">eof</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">find</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">find</span><span class="p">),</span><span class="nb">false</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">ans</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">num</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">num</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">done</span><span class="p">:=</span><span class="nb">false</span><span class="p">;</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">m</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span> <span class="n">readln</span><span class="p">(</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span><span class="c1">//排序
</span> <span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">i</span><span class="p">+</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">if</span> <span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">]&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">gt</span><span class="p">;</span><span class="n">num</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">t</span><span class="p">:=</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">]:=</span><span class="n">num</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">num</span><span class="p">[</span><span class="n">j</span><span class="p">]:=</span><span class="n">t</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">n</span><span class="p">=</span><span class="m">0</span> <span class="k">then</span><span class="c1">//处理n=0情况
</span> <span class="k">begin</span>
<span class="k">writeln</span><span class="p">(</span><span class="m">0</span><span class="p">);</span>
<span class="n">continue</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">l</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">r</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">while</span> <span class="n">l</span><span class="p">&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">lt</span><span class="p">;=</span><span class="n">r</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">temp</span><span class="p">:=(</span><span class="n">ans</span><span class="p">[</span><span class="n">l</span><span class="p">].</span><span class="n">n</span><span class="p">*</span><span class="m">10</span><span class="p">+</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span><span class="p">=</span><span class="m">0</span><span class="p">)</span> <span class="k">then</span> <span class="n">continue</span><span class="p">;</span>
<span class="n">temp</span><span class="p">:=</span><span class="n">temp</span> <span class="k">mod</span> <span class="n">n</span><span class="p">;</span>
<span class="k">if</span> <span class="k">not</span> <span class="n">find</span><span class="p">[</span><span class="n">temp</span><span class="p">]</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">r</span><span class="p">);</span>
<span class="n">ans</span><span class="p">[</span><span class="n">r</span><span class="p">].</span><span class="n">n</span><span class="p">:=</span><span class="n">temp</span> <span class="k">mod</span> <span class="n">n</span><span class="p">;</span>
<span class="n">ans</span><span class="p">[</span><span class="n">r</span><span class="p">].</span><span class="n">a</span><span class="p">:=</span><span class="n">num</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">ans</span><span class="p">[</span><span class="n">r</span><span class="p">].</span><span class="n">pre</span><span class="p">:=</span><span class="n">l</span><span class="p">;</span>
<span class="n">find</span><span class="p">[</span><span class="n">ans</span><span class="p">[</span><span class="n">r</span><span class="p">].</span><span class="n">n</span><span class="p">]:=</span><span class="nb">true</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">find</span><span class="p">[</span><span class="m">0</span><span class="p">])</span> <span class="k">and</span> <span class="p">(</span><span class="n">l</span><span class="p">&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">gt</span><span class="p">;</span><span class="m">0</span><span class="p">)</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">done</span><span class="p">:=</span><span class="nb">true</span><span class="p">;</span>
<span class="n">print</span><span class="p">(</span><span class="n">r</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">;</span>
<span class="n">break</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">done</span> <span class="k">then</span> <span class="n">break</span> <span class="k">else</span> <span class="k">inc</span><span class="p">(</span><span class="n">l</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="k">not</span> <span class="n">done</span> <span class="k">then</span> <span class="k">writeln</span><span class="p">(</span><span class="m">0</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
在Google中搜索世界各地的时间
2008-07-26T03:55:50+00:00
http://greenmooon55.com/search-time-in-google
<p>在<a href="http://www.google.com/webhp?hl=en">英文版Google</a>中输入<a href="http://www.google.com/search?hl=en&q=time&btnG=Google+Search">time</a>会怎么样?会显示当地时间。
<img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080726114223296.png" alt="" /></p>
<p>如果输入别的呢?输入“<a href="http://www.google.com/search?hl=en&newwindow=1&q=time+italy&btnG=Search">time italy</a>”
<img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080726114253140.png" alt="" /></p>
<p>输入”<a href="http://www.google.com/search?hl=en&newwindow=1&q=time+changchun&btnG=Search">time changchun</a>“呢?
<img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080726114402171.png" alt="" /></p>
<p>很强吧,<a href="http://www.google.com/help/features.html">官方介绍</a>(英文版)是To see the time in many cities around the world, type in “time” and the name of the city.
不过这项功能只在<a href="http://www.google.com/webhp?hl=en">英文版Google</a>中有效,中文Google和谷歌都无效,在<a href="http://www.google.com/help/features.html">Google 特色</a>中文版上也没有介绍。</p>
Zju1196 Fast Food
2008-07-21T13:02:06+00:00
http://greenmooon55.com/zju1196
<blockquote>
<p>有一个公司,在一条街上有N个快餐店,公司决定修K个仓库以满足这些快餐电的原料需求.
现在给出N个快餐店的横坐标(他们都在一条直线上面),要求修K个仓库,使得所有的快餐店离其对应的仓库的距离最短.
<strong>仓库需要建在快餐店内。</strong></p>
</blockquote>
<p>分析 from <a href="http://www.programfan.com/blog/article.asp?id=17344">http://www.programfan.com/blog/article.asp?id=17344</a>,人家是All Rights Reserved?</p>
<blockquote>
<p>f是最小距离
i是仓库数
j是快餐店数
cost是中间仅1个仓库时的距离,在function c中,不难理解。
f[i,j]=min(f[i-1,k]+cost[k+1,j]) (i-1 <= k < j)</p>
</blockquote>
<!-- more -->
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">zju1196</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">t</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">l</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">d</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">f</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">0..30</span><span class="p">,</span><span class="m">0..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">cost</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..200</span><span class="p">,</span><span class="m">1..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">function</span> <span class="n">c</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">:</span><span class="kt">longint</span><span class="p">):</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">temp</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">mid</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">temp</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">mid</span><span class="p">:=(</span><span class="n">a</span><span class="p">+</span><span class="n">b</span><span class="p">)</span> <span class="k">div</span> <span class="m">2</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="n">a</span> <span class="k">to</span> <span class="n">b</span> <span class="k">do</span> <span class="n">temp</span><span class="p">:=</span><span class="n">temp</span><span class="p">+</span><span class="n">abs</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]-</span><span class="n">d</span><span class="p">[</span><span class="n">mid</span><span class="p">]);</span>
<span class="n">c</span><span class="p">:=</span><span class="n">temp</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">t</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">while</span> <span class="nb">true</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">t</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">);</span>
<span class="k">if</span> <span class="n">n</span><span class="p">=</span><span class="m">0</span> <span class="k">then</span> <span class="n">break</span><span class="p">;</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">readln</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">i</span><span class="p">+</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">cost</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]:=</span><span class="n">c</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">0</span> <span class="k">to</span> <span class="n">k</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]:=</span><span class="m">999999999</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">k</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">i</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">l</span><span class="p">:=</span><span class="n">i</span><span class="p">-</span><span class="m">1</span> <span class="k">to</span> <span class="n">j</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span>
<span class="k">if</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">l</span><span class="p">]+</span><span class="n">cost</span><span class="p">[</span><span class="n">l</span><span class="p">+</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">]&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">lt</span><span class="p">;</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="k">then</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]:=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">l</span><span class="p">]+</span><span class="n">cost</span><span class="p">[</span><span class="n">l</span><span class="p">+</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">];</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'Chain '</span><span class="p">,</span><span class="n">t</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'Total distance sum = '</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">k</span><span class="p">,</span><span class="n">n</span><span class="p">]);</span>
<span class="k">writeln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>可以预处理f[1,*],这样就可以用maxlongint了,更加稳妥。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">zju1196</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">t</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">l</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">d</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">f</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">0..30</span><span class="p">,</span><span class="m">1..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">cost</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..200</span><span class="p">,</span><span class="m">1..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">function</span> <span class="n">c</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">:</span><span class="kt">longint</span><span class="p">):</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">temp</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">mid</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">temp</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">mid</span><span class="p">:=(</span><span class="n">a</span><span class="p">+</span><span class="n">b</span><span class="p">)</span> <span class="k">div</span> <span class="m">2</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="n">a</span> <span class="k">to</span> <span class="n">b</span> <span class="k">do</span> <span class="n">temp</span><span class="p">:=</span><span class="n">temp</span><span class="p">+</span><span class="n">abs</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]-</span><span class="n">d</span><span class="p">[</span><span class="n">mid</span><span class="p">]);</span>
<span class="n">c</span><span class="p">:=</span><span class="n">temp</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">t</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">while</span> <span class="nb">true</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">t</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">);</span>
<span class="k">if</span> <span class="n">n</span><span class="p">=</span><span class="m">0</span> <span class="k">then</span> <span class="n">break</span><span class="p">;</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">readln</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">i</span><span class="p">+</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">cost</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]:=</span><span class="n">c</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">2</span> <span class="k">to</span> <span class="n">k</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]:=</span><span class="n">maxlongint</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">f</span><span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="n">i</span><span class="p">]:=</span><span class="n">cost</span><span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="n">i</span><span class="p">];</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">2</span> <span class="k">to</span> <span class="n">k</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">i</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">l</span><span class="p">:=</span><span class="n">i</span><span class="p">-</span><span class="m">1</span> <span class="k">to</span> <span class="n">j</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span>
<span class="k">if</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">l</span><span class="p">]+</span><span class="n">cost</span><span class="p">[</span><span class="n">l</span><span class="p">+</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">]<</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="k">then</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]:=</span><span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">l</span><span class="p">]+</span><span class="n">cost</span><span class="p">[</span><span class="n">l</span><span class="p">+</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">];</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'Chain '</span><span class="p">,</span><span class="n">t</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'Total distance sum = '</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">k</span><span class="p">,</span><span class="n">n</span><span class="p">]);</span>
<span class="k">writeln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>f还可以优化成一维数组:f:array[0..200] of longint;从后向前推即可,这样时间能从00:00.05降到00:00.04。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">zju1196</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">t</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">l</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">d</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">f</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">0..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">cost</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..200</span><span class="p">,</span><span class="m">1..200</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">function</span> <span class="n">c</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">:</span><span class="kt">longint</span><span class="p">):</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">temp</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">mid</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">temp</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">mid</span><span class="p">:=(</span><span class="n">a</span><span class="p">+</span><span class="n">b</span><span class="p">)</span> <span class="k">div</span> <span class="m">2</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="n">a</span> <span class="k">to</span> <span class="n">b</span> <span class="k">do</span> <span class="n">temp</span><span class="p">:=</span><span class="n">temp</span><span class="p">+</span><span class="n">abs</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]-</span><span class="n">d</span><span class="p">[</span><span class="n">mid</span><span class="p">]);</span>
<span class="n">c</span><span class="p">:=</span><span class="n">temp</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span><span class="s">'zju.in'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">f</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">t</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">while</span> <span class="nb">true</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">t</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">);</span>
<span class="k">if</span> <span class="n">n</span><span class="p">=</span><span class="m">0</span> <span class="k">then</span> <span class="n">break</span><span class="p">;</span>
<span class="n">f</span><span class="p">[</span><span class="m">0</span><span class="p">]:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">readln</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">i</span><span class="p">+</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">cost</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]:=</span><span class="n">c</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">f</span><span class="p">[</span><span class="n">i</span><span class="p">]:=</span><span class="n">cost</span><span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="n">i</span><span class="p">];</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">2</span> <span class="k">to</span> <span class="n">k</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="n">n</span> <span class="k">downto</span> <span class="n">i</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">f</span><span class="p">[</span><span class="n">j</span><span class="p">]:=</span><span class="n">maxlongint</span><span class="p">;</span>
<span class="k">for</span> <span class="n">l</span><span class="p">:=</span><span class="n">j</span><span class="p">-</span><span class="m">1</span> <span class="k">downto</span> <span class="n">i</span><span class="p">-</span><span class="m">1</span> <span class="k">do</span>
<span class="k">if</span> <span class="n">f</span><span class="p">[</span><span class="n">l</span><span class="p">]+</span><span class="n">cost</span><span class="p">[</span><span class="n">l</span><span class="p">+</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">]<</span><span class="n">f</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="k">then</span> <span class="n">f</span><span class="p">[</span><span class="n">j</span><span class="p">]:=</span><span class="n">f</span><span class="p">[</span><span class="n">l</span><span class="p">]+</span><span class="n">cost</span><span class="p">[</span><span class="n">l</span><span class="p">+</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'Chain '</span><span class="p">,</span><span class="n">t</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="s">'Total distance sum = '</span><span class="p">,</span><span class="n">f</span><span class="p">[</span><span class="n">n</span><span class="p">]);</span>
<span class="k">writeln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
Zju1107
2008-07-15T08:22:21+00:00
http://greenmooon55.com/zju1107
<p>转自<a href="http://www.jlyzoi.cn">http://www.jlyzoi.cn</a></p>
<blockquote>
<p>在一个N*N的方阵中,从第一行,第一个格子出发,
每次可上下左右走,走一格算一步.至多走K步。
要求每次走到的格子的cheese数大于先前所在格子的。求取得的最大的数.
例如N=3,k=2
1 2 5
10 11 6
12 12 7
走法为:1–> 2–> 5–> 6–> 10–> 11–> 12.</p>
</blockquote>
<!-- more -->
<p>搜索即可,不过还要循环k。
程序:</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">zju1107</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">map</span><span class="p">,</span><span class="n">ans</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..100</span><span class="p">,</span><span class="m">1..100</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">best</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">sum</span><span class="p">:</span><span class="kt">longint</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">step</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">sum</span><span class="p"><=</span><span class="n">ans</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">]</span> <span class="k">then</span> <span class="k">exit</span><span class="p">;</span>
<span class="n">ans</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">]:=</span><span class="n">sum</span><span class="p">;</span>
<span class="k">if</span> <span class="n">sum</span><span class="p">></span><span class="n">best</span> <span class="k">then</span> <span class="n">best</span><span class="p">:=</span><span class="n">sum</span><span class="p">;</span>
<span class="k">for</span> <span class="n">step</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">k</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span><span class="p">-</span><span class="n">step</span><span class="p">></span><span class="m">0</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">-</span><span class="n">step</span><span class="p">,</span><span class="n">y</span><span class="p">]></span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span> <span class="k">then</span> <span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">-</span><span class="n">step</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">sum</span><span class="p">+</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">-</span><span class="n">step</span><span class="p">,</span><span class="n">y</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">y</span><span class="p">-</span><span class="n">step</span><span class="p">></span><span class="m">0</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">-</span><span class="n">step</span><span class="p">]></span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span> <span class="k">then</span> <span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">-</span><span class="n">step</span><span class="p">,</span><span class="n">sum</span><span class="p">+</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">-</span><span class="n">step</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span><span class="p">+</span><span class="n">step</span><span class="p"><=</span><span class="n">n</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">+</span><span class="n">step</span><span class="p">,</span><span class="n">y</span><span class="p">]></span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span> <span class="k">then</span> <span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">+</span><span class="n">step</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">sum</span><span class="p">+</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">+</span><span class="n">step</span><span class="p">,</span><span class="n">y</span><span class="p">]);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">y</span><span class="p">+</span><span class="n">step</span><span class="p"><=</span><span class="n">n</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">+</span><span class="n">step</span><span class="p">]></span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span> <span class="k">then</span> <span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">+</span><span class="n">step</span><span class="p">,</span><span class="n">sum</span><span class="p">+</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">+</span><span class="n">step</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span><span class="s">'zju.in'</span><span class="p">);</span><span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">);</span>
<span class="k">while</span> <span class="p">(</span><span class="n">n</span><span class="p"><>-</span><span class="m">1</span><span class="p">)</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">ans</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">ans</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="k">read</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">best</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">search</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="n">map</span><span class="p">[</span><span class="m">1</span><span class="p">,</span><span class="m">1</span><span class="p">]);</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">best</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">k</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>PS:题中图片很可爱。</p>
Zju1027
2008-07-15T07:24:09+00:00
http://greenmooon55.com/zju1027
<p>题目翻译(转自<a href="http://www.jlyzoi.cn">http://www.jlyzoi.cn</a>,估计来源是衡阳市八中论坛,但是论坛暂时打不开):</p>
<blockquote>
<p>众所周知,人类基因可以被简单认为是一个字符串,包含四种分别用A,C,T,G表示的核苷酸。生物学家对鉴别人类基因核确定他们的功能很感兴趣。因 为这对诊断人类疾病和开发新药很有用。 人类基因可以用一堆特别的快速的试验来鉴别,而且通常要借助电脑的帮助一旦基因序列测定了,下一步就可以确定它的功能了。生物学家确定一个新鉴定了的基因 的功能的方法之一是在在基因数据库里和其他基因对照。要搜索的数据库里储存了很多的基因和它们的功能--很多研究人员提交了他们的研究基因和功能到数据 库,而数据库是在互联网上公开的。</p>
</blockquote>
<p>数据库会返回一堆最相近基因。生物学家们假设类似的基因表示类似的功能。所以新基因的功能也包含在列表里的基因里。所以严格确定最相近的一个对生物试验非常必要。</p>
<p>你的任务是写一个程序来按一下规则比较两个基因和决定他们的相似程度。给出两个基因 AGTGATG 和 GTTAG,他们有多相似呢?一个测量两个基因相似程度的方法就叫做alignment。在alignment里, 如果必要是可以在基因的适当位置插进空格以令他们的长度相等。例如,一个空格插进了AGTGATG以后就得到AGTGAT-G,三个空格插进了GTTAG 就得到–GT–TAG。空格用减号(-)表示。现在两个串的长度就相等了。现在排在一齐就成了:</p>
<p>AGTGAT-G
-GT–TAG
<!-- more --></p>
<p>在这个alignment里,有四个基因是相配的:第二位的G,第三位的 T,第六位的T,和第八位的G。每对排列排列的字母用一下的矩阵分配了不同的分值。* 表示空格对空格是不允许的。所以以上这个alignment的分值是(-3)+5+5+(-2)+(-3)+5+(-3)+5=9 。</p>
<p>当然,其他alignments也是有可能的。一下有另一种排列 (不同数目的空格插进不同的位置):</p>
<p>AGTGATG
-GTTA-G</p>
<p>这个alignment 给出了的分值是 (-3)+5+5+(-2)+5+(-1) +5=14。 所以这一个比前一个要好。没有其他的alignment有更高的分值了,所以说这两个基因的相似程度是14。</p>
<p>输入格式</p>
<p>输入数据有T组测试数据。测试数据的数目 (T)在输入的第一行给出。每组测试数据有两行:每行有一个表示基因长度的整数和一个基因序列。每个基因的长度都不超过100.。
输出格式</p>
<p>输出只要输出每组测试数据的相似程度,每组一行。
Sample Input</p>
<p>2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA
Output for the Sample Input</p>
<p>14
21</p>
<p>从来没做过这种DP题,推荐看下Eruca的<a href="http://eruca.blog.hexun.com/1721716_d.html">分析</a>:</p>
<blockquote>
<p>设两个DNA序列分别为s1,s2,长度分别为len1,len2,score为分值表。f[i,j]表示子串s1[1..i]和s2[1..j]的分值。考虑一个f[i,j],我们有:
1.s1取第i个字母,s2取“-”:f[i-1,j] + score[s1[i],’-‘]
2.s1取“-”,s2取第j个字母:f[i,j-1] + score[’-‘,s2[j]]
3.s1取第i个字母,s2取第j个字母:f[i-1,j-1] + score[s1[i],s2[j]]
即f[i,j] = max(f[i-1,j] + score[s1[i],’-‘], f[i,j-1] + score[’-‘,s2[j]], f[i-1,j-1] + score[s1[i],s2[j]]);</p>
</blockquote>
<p>f[0,0]=0 f[0,<em>]和f[</em>,0]都应该用字母与’-‘相对。这样,可以用两个一维数组存储,互相导。</p>
<p>2976417</p>
<p>2008-07-14 10:41:39</p>
<p>Accepted</p>
<p><a href="http://acm.zju.edu.cn/show_problem.php?pid=1027">1027</a></p>
<p>FPC</p>
<p>00:00.00</p>
<p>404K</p>
<p><a href="http://acm.zju.edu.cn/user_status.php?user=greenmoon55">greenmoon55</a></p>
<p>下面是程序:</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">zju1027</span><span class="p">;</span>
<span class="k">const</span>
<span class="n">match</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..5</span><span class="p">,</span><span class="m">1..5</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">=</span>
<span class="p">((</span><span class="m">5</span><span class="p">,-</span><span class="m">1</span><span class="p">,-</span><span class="m">2</span><span class="p">,-</span><span class="m">1</span><span class="p">,-</span><span class="m">3</span><span class="p">),</span>
<span class="p">(-</span><span class="m">1</span><span class="p">,</span><span class="m">5</span><span class="p">,-</span><span class="m">3</span><span class="p">,-</span><span class="m">2</span><span class="p">,-</span><span class="m">4</span><span class="p">),</span>
<span class="p">(-</span><span class="m">2</span><span class="p">,-</span><span class="m">3</span><span class="p">,</span><span class="m">5</span><span class="p">,-</span><span class="m">2</span><span class="p">,-</span><span class="m">2</span><span class="p">),</span>
<span class="p">(-</span><span class="m">1</span><span class="p">,-</span><span class="m">2</span><span class="p">,-</span><span class="m">2</span><span class="p">,</span><span class="m">5</span><span class="p">,-</span><span class="m">1</span><span class="p">),</span>
<span class="p">(-</span><span class="m">3</span><span class="p">,-</span><span class="m">4</span><span class="p">,-</span><span class="m">2</span><span class="p">,-</span><span class="m">1</span><span class="p">,</span><span class="m">999</span><span class="p">));</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">n</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">s1</span><span class="p">,</span><span class="n">s2</span><span class="p">:</span><span class="k">string</span><span class="p">;</span>
<span class="n">l1</span><span class="p">,</span><span class="n">l2</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">f1</span><span class="p">,</span><span class="n">f2</span><span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">0..100</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">function</span> <span class="n">max</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">,</span><span class="n">c</span><span class="p">:</span><span class="kt">longint</span><span class="p">):</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">>=</span><span class="n">b</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">a</span><span class="p">>=</span><span class="n">c</span><span class="p">)</span> <span class="k">then</span> <span class="k">exit</span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">b</span><span class="p">>=</span><span class="n">a</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">b</span><span class="p">>=</span><span class="n">c</span><span class="p">)</span> <span class="k">then</span> <span class="k">exit</span><span class="p">(</span><span class="n">b</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">c</span><span class="p">>=</span><span class="n">a</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">c</span><span class="p">>=</span><span class="n">b</span><span class="p">)</span> <span class="k">then</span> <span class="k">exit</span><span class="p">(</span><span class="n">c</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">function</span> <span class="n">c</span><span class="p">(</span><span class="n">ch</span><span class="p">:</span><span class="kt">char</span><span class="p">):</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">case</span> <span class="n">ch</span> <span class="k">of</span>
<span class="s">'A'</span><span class="p">:</span><span class="k">exit</span><span class="p">(</span><span class="m">1</span><span class="p">);</span>
<span class="s">'C'</span><span class="p">:</span><span class="k">exit</span><span class="p">(</span><span class="m">2</span><span class="p">);</span>
<span class="s">'G'</span><span class="p">:</span><span class="k">exit</span><span class="p">(</span><span class="m">3</span><span class="p">);</span>
<span class="s">'T'</span><span class="p">:</span><span class="k">exit</span><span class="p">(</span><span class="m">4</span><span class="p">);</span>
<span class="s">'-'</span><span class="p">:</span><span class="k">exit</span><span class="p">(</span><span class="m">5</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span><span class="s">'in.txt'</span><span class="p">);</span><span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span><span class="s">'out.txt'</span><span class="p">);</span><span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">read</span><span class="p">(</span><span class="n">l1</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">s1</span><span class="p">);</span>
<span class="n">delete</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="m">1</span><span class="p">);</span>
<span class="k">read</span><span class="p">(</span><span class="n">l2</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">s2</span><span class="p">);</span>
<span class="n">delete</span><span class="p">(</span><span class="n">s2</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="m">1</span><span class="p">);</span>
<span class="n">f1</span><span class="p">[</span><span class="m">0</span><span class="p">]:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">l2</span> <span class="k">do</span> <span class="n">f1</span><span class="p">[</span><span class="n">j</span><span class="p">]:=</span><span class="n">f1</span><span class="p">[</span><span class="n">j</span><span class="p">-</span><span class="m">1</span><span class="p">]+</span><span class="n">match</span><span class="p">[</span><span class="m">5</span><span class="p">,</span><span class="n">c</span><span class="p">(</span><span class="n">s2</span><span class="p">[</span><span class="n">j</span><span class="p">])];</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">l1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">f2</span><span class="p">[</span><span class="m">0</span><span class="p">]:=</span><span class="n">f1</span><span class="p">[</span><span class="m">0</span><span class="p">]+</span><span class="n">match</span><span class="p">[</span><span class="n">c</span><span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">j</span><span class="p">]),</span><span class="m">5</span><span class="p">];</span>
<span class="k">for</span> <span class="n">k</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">l2</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">f2</span><span class="p">[</span><span class="n">k</span><span class="p">]:=</span><span class="n">max</span><span class="p">(</span><span class="n">f1</span><span class="p">[</span><span class="n">k</span><span class="p">-</span><span class="m">1</span><span class="p">]+</span><span class="n">match</span><span class="p">[</span><span class="n">c</span><span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">j</span><span class="p">]),</span><span class="n">c</span><span class="p">(</span><span class="n">s2</span><span class="p">[</span><span class="n">k</span><span class="p">])],</span><span class="n">f1</span><span class="p">[</span><span class="n">k</span><span class="p">]+</span><span class="n">match</span><span class="p">[</span><span class="n">c</span><span class="p">(</span><span class="n">s1</span><span class="p">[</span><span class="n">j</span><span class="p">]),</span><span class="m">5</span><span class="p">],</span><span class="n">f2</span><span class="p">[</span><span class="n">k</span><span class="p">-</span><span class="m">1</span><span class="p">]+</span><span class="n">match</span><span class="p">[</span><span class="m">5</span><span class="p">,</span><span class="n">c</span><span class="p">(</span><span class="n">s2</span><span class="p">[</span><span class="n">k</span><span class="p">])]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">f1</span><span class="p">:=</span><span class="n">f2</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">f2</span><span class="p">[</span><span class="n">l2</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
Read it Later
2008-07-11T01:12:22+00:00
http://greenmooon55.com/read-it-later
<p>众所周知,Firefox有许多插件,对一些人来说,Firefox插件的丰富甚至是使用FF的理由。昨天,我在<a href="http://www.babelzilla.org/">Babelzilla</a>的Latest submissions中发现了一个很优秀的插件:Read it Later,就把它翻译了。</p>
<p>这有个介绍视频</p>
<p>下面我来简单介绍一下:</p>
<p>安装后在地址栏中星号收藏标记右侧会出现一个对号,<a href="http://greenmoon55.com/wp-content/uploads/2008/07/20080711081542234.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080711081542234.png" alt="" /></a>点击对号就会添加到书签中的Read It Later文件夹。再点击一下即可标记为已读,还可以方便地添加到各种在线收藏中。<!-- more --></p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/07/20080711082118890.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080711082118890.png" alt="" /></a></p>
<p>本插件会在搜索框右侧添加一个按钮,与Adblock相似。打开右侧菜单就能看到未读列表了,在这里可以看到各项目的保存时间。<a href="http://greenmoon55.com/wp-content/uploads/2008/07/20080711083213718.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080711083213718.png" alt="" /></a></p>
<p>下面我开始介绍最爽的功能了 :D</p>
<p>此插件的网站上提供RSSfeed同步功能,可以把未读列表同步到这个RSS上,这样就可在其他电脑上用了,和在线收藏夹相似。这项功能是通过Feed ID和同步密码实现的。</p>
<p>看图:</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/07/20080711083558453.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080711083558453.png" alt="" /></a></p>
<p>Read it Later还可以帮您离线浏览,只需点击“离线浏览”</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/07/20080711085838968.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080711085838968.png" alt="" /></a></p>
<p>很强吧!下载地址:<a href="https://addons.mozilla.org/zh-CN/firefox/addon/7661"></a></p>
<p>AMO: <a href="https://addons.mozilla.org/zh-CN/firefox/addon/7661">https://addons.mozilla.org/zh-CN/firefox/addon/7661</a></p>
<p>作者网站:<a href="http://www.ideashower.com/ideas/launched/read-it-later/">http://www.ideashower.com/ideas/launched/read-it-later/</a></p>
<p>NOTE:</p>
<p>1.本翻译有问题,有的字符串有些问题。</p>
<p>2.官网暂未更新中文版,不过很快就会更新,请耐心等待</p>
<p>3.ideashower.com似乎被墙了,昨晚还可以!因此如果不翻墙同步功能无法使用。</p>
<p>4.缺点:不能保存浏览网页的滚动的位置和表单内容。这可以通过<a href="https://addons.mozilla.org/zh-CN/firefox/addon/5756">Taboo</a>实现。</p>
吉林2008省选题扫描版
2008-06-14T15:24:21+00:00
http://greenmooon55.com/jilin2008oi
<p>6月14日 12:00-16:00
下载地址: <a href="http://tinyurl.com/3nvzmj">http://tinyurl.com/3nvzmj</a></p>
<p>:)</p>
<p>过程以后有时间再写 :)</p>
The Castle
2008-05-31T23:24:22+00:00
http://greenmooon55.com/the-castle
<p>翻译:<a href="http://www.nocow.cn/index.php/Translate:USACO/castle">http://www.nocow.cn/index.php/Translate:USACO/castle</a></p>
<p>比较简单,<a href="http://greenmoon55.com/programing-problem-about-island/">走岛</a>、迷宫系列问题。重要问题:1.对墙的记录 2.对roomsize的求法 3.拆墙只需求墙两边的面积和。</p>
<p>另外,我准备用4个格的tab了,2个空格太短,8个格的tab太长。
<!-- more --></p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">{
ID:djgreen1
PROG:castle
LANG:PASCAL
}</span>
<span class="k">program</span> <span class="n">castlev1</span><span class="p">;</span>
<span class="k">const</span>
<span class="n">dx</span> <span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..4</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">=(</span><span class="m">0</span><span class="p">,-</span><span class="m">1</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">1</span><span class="p">);</span>
<span class="n">dy</span> <span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..4</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">=(-</span><span class="m">1</span><span class="p">,</span><span class="m">0</span><span class="p">,</span><span class="m">1</span><span class="p">,</span><span class="m">0</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">wall</span> <span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..50</span><span class="p">,</span><span class="m">1..50</span><span class="p">,</span><span class="m">1..4</span><span class="p">]</span> <span class="k">of</span> <span class="kt">boolean</span><span class="p">;</span>
<span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span> <span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">temp</span><span class="p">,</span><span class="n">roomnum</span> <span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="n">room</span> <span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..50</span><span class="p">,</span><span class="m">1..50</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">roomsize</span> <span class="p">:</span><span class="k">array</span><span class="p">[</span><span class="m">1..2550</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">max</span><span class="p">,</span><span class="n">besti</span><span class="p">,</span><span class="n">bestj</span><span class="p">,</span><span class="n">bestd</span><span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">init</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">readln</span><span class="p">(</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">read</span><span class="p">(</span><span class="n">temp</span><span class="p">);</span>
<span class="k">for</span> <span class="n">k</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="m">4</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">temp</span> <span class="k">mod</span> <span class="m">2</span><span class="p">></span><span class="m">0</span> <span class="k">then</span> <span class="n">wall</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">]:=</span><span class="nb">true</span><span class="p">;</span>
<span class="n">temp</span><span class="p">:=</span><span class="n">temp</span> <span class="k">div</span> <span class="m">2</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">readln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">roomnum</span><span class="p">:</span><span class="kt">longint</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">dir</span><span class="p">,</span><span class="n">tx</span><span class="p">,</span><span class="n">ty</span> <span class="p">:</span><span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">room</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">]:=</span><span class="n">roomnum</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">roomsize</span><span class="p">[</span><span class="n">roomnum</span><span class="p">]);</span>
<span class="k">for</span> <span class="n">dir</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="m">4</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">wall</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">dir</span><span class="p">]</span> <span class="k">then</span> <span class="n">continue</span><span class="p">;</span>
<span class="n">tx</span><span class="p">:=</span><span class="n">x</span><span class="p">+</span><span class="n">dx</span><span class="p">[</span><span class="n">dir</span><span class="p">];</span>
<span class="n">ty</span><span class="p">:=</span><span class="n">y</span><span class="p">+</span><span class="n">dy</span><span class="p">[</span><span class="n">dir</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">tx</span><span class="p"><</span><span class="m">1</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">tx</span><span class="p">></span><span class="n">n</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">ty</span><span class="p"><</span><span class="m">1</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">ty</span><span class="p">></span><span class="n">m</span><span class="p">)</span> <span class="k">then</span> <span class="n">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="n">room</span><span class="p">[</span><span class="n">tx</span><span class="p">,</span><span class="n">ty</span><span class="p">]=</span><span class="m">0</span> <span class="k">then</span> <span class="n">search</span><span class="p">(</span><span class="n">tx</span><span class="p">,</span><span class="n">ty</span><span class="p">,</span><span class="n">roomnum</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">size</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">if</span> <span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]=</span><span class="m">0</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">inc</span><span class="p">(</span><span class="n">roomnum</span><span class="p">);</span>
<span class="n">search</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">roomnum</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">delete</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">j</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="n">n</span> <span class="k">downto</span> <span class="m">1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">wall</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="m">2</span><span class="p">]</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="p">></span><span class="m">1</span><span class="p">)</span> <span class="k">and</span> <span class="k">not</span> <span class="p">(</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">]=</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">])</span> <span class="k">then</span>
<span class="k">if</span> <span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">]]+</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]]></span><span class="n">max</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">max</span><span class="p">:=</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">-</span><span class="m">1</span><span class="p">,</span><span class="n">j</span><span class="p">]]+</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]];</span>
<span class="n">besti</span><span class="p">:=</span><span class="n">i</span><span class="p">;</span>
<span class="n">bestj</span><span class="p">:=</span><span class="n">j</span><span class="p">;</span>
<span class="n">bestd</span><span class="p">:=</span><span class="m">2</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">wall</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="m">3</span><span class="p">]</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span><span class="p"><</span><span class="n">m</span><span class="p">)</span> <span class="k">and</span> <span class="k">not</span> <span class="p">(</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]=</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">+</span><span class="m">1</span><span class="p">])</span> <span class="k">then</span>
<span class="k">if</span> <span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">+</span><span class="m">1</span><span class="p">]]+</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]]></span><span class="n">max</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">max</span><span class="p">:=</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">+</span><span class="m">1</span><span class="p">]]+</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]];</span>
<span class="n">besti</span><span class="p">:=</span><span class="n">i</span><span class="p">;</span>
<span class="n">bestj</span><span class="p">:=</span><span class="n">j</span><span class="p">;</span>
<span class="n">bestd</span><span class="p">:=</span><span class="m">3</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span><span class="s">'castle.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span><span class="s">'castle.out'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="n">init</span><span class="p">;</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">room</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">room</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">roomsize</span><span class="p">,</span><span class="n">sizeof</span><span class="p">(</span><span class="n">room</span><span class="p">),</span><span class="m">0</span><span class="p">);</span>
<span class="n">roomnum</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">size</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">roomnum</span><span class="p">);</span>
<span class="n">max</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span><span class="p">:=</span><span class="m">1</span> <span class="k">to</span> <span class="n">roomnum</span> <span class="k">do</span> <span class="k">if</span> <span class="n">roomsize</span><span class="p">[</span><span class="n">i</span><span class="p">]></span><span class="n">max</span> <span class="k">then</span> <span class="n">max</span><span class="p">:=</span><span class="n">roomsize</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">max</span><span class="p">);</span>
<span class="n">max</span><span class="p">:=</span><span class="m">0</span><span class="p">;</span>
<span class="n">delete</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">max</span><span class="p">);</span>
<span class="k">write</span><span class="p">(</span><span class="n">besti</span><span class="p">,</span><span class="s">' '</span><span class="p">,</span><span class="n">bestj</span><span class="p">,</span><span class="s">' '</span><span class="p">);</span>
<span class="k">if</span> <span class="n">bestd</span><span class="p">=</span><span class="m">2</span> <span class="k">then</span> <span class="k">writeln</span><span class="p">(</span><span class="s">'N'</span><span class="p">)</span> <span class="k">else</span> <span class="k">writeln</span><span class="p">(</span><span class="s">'E'</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>**
Update @ 2010/5/25 0:50
**C语言版</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID:djgreen1
PROG:castle
LANG:C
*/</span>
<span class="cp">#include
</span><span class="kt">int</span> <span class="n">roomnum</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">roomsize</span><span class="p">[</span><span class="mi">2501</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">},</span><span class="n">m</span><span class="p">,</span><span class="n">n</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">map</span><span class="p">[</span><span class="mi">51</span><span class="p">][</span><span class="mi">51</span><span class="p">][</span><span class="mi">5</span><span class="p">],</span><span class="n">room</span><span class="p">[</span><span class="mi">51</span><span class="p">][</span><span class="mi">51</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">search</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">,</span><span class="kt">int</span> <span class="n">y</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">const</span> <span class="kt">int</span> <span class="n">dx</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">},</span><span class="n">dy</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">};</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">;</span>
<span class="n">room</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">]</span><span class="o">=</span><span class="n">roomnum</span><span class="p">;</span>
<span class="n">roomsize</span><span class="p">[</span><span class="n">roomnum</span><span class="p">]</span><span class="o">++</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">4</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">dx</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o"><</span><span class="mi">1</span> <span class="o">||</span> <span class="n">x</span><span class="o">+</span><span class="n">dx</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">></span><span class="n">n</span> <span class="o">||</span> <span class="n">y</span><span class="o">+</span><span class="n">dy</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o"><</span><span class="mi">1</span> <span class="o">||</span> <span class="n">y</span><span class="o">+</span><span class="n">dy</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">></span><span class="n">m</span><span class="p">)</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">x</span><span class="p">][</span><span class="n">y</span><span class="p">][</span><span class="n">i</span><span class="p">])</span> <span class="k">continue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">room</span><span class="p">[</span><span class="n">x</span><span class="o">+</span><span class="n">dx</span><span class="p">[</span><span class="n">i</span><span class="p">]][</span><span class="n">y</span><span class="o">+</span><span class="n">dy</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="n">search</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="n">dx</span><span class="p">[</span><span class="n">i</span><span class="p">],</span><span class="n">y</span><span class="o">+</span><span class="n">dy</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"castle.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">,</span><span class="n">stdin</span><span class="p">);</span>
<span class="n">freopen</span><span class="p">(</span><span class="s">"castle.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">,</span><span class="n">stdout</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">,</span><span class="n">temp</span><span class="p">,</span><span class="n">max</span><span class="p">,</span><span class="n">maxn</span><span class="p">,</span><span class="n">maxm</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">maxd</span><span class="p">;</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">m</span><span class="p">;,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">m</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">scanf</span><span class="p">(</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">temp</span><span class="p">;);</span>
<span class="k">for</span> <span class="p">(</span><span class="n">k</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">k</span><span class="o"><</span><span class="mi">4</span><span class="p">;</span><span class="n">k</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="n">k</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="o">%</span><span class="mi">2</span><span class="p">;</span>
<span class="n">temp</span><span class="o">=</span><span class="n">temp</span><span class="o">/</span><span class="mi">2</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">m</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">roomnum</span><span class="o">++</span><span class="p">;</span>
<span class="n">search</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">max</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">roomnum</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">roomsize</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">></span><span class="n">max</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">max</span><span class="o">=</span><span class="n">roomsize</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">roomnum</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">max</span><span class="p">);</span>
<span class="n">max</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">m</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">></span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">&&</span><span class="n">i</span><span class="p">;</span><span class="o">></span><span class="mi">1</span><span class="o">&&</span><span class="n">room</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">!=</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">temp</span><span class="o">=</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]]</span><span class="o">+</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">j</span><span class="p">]];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span><span class="o">></span><span class="n">max</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">max</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="n">maxn</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="n">maxm</span><span class="o">=</span><span class="n">j</span><span class="p">;</span>
<span class="n">maxd</span><span class="o">=</span><span class="sc">'N'</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">&&</span><span class="n">j</span><span class="p">;</span><span class="o"><</span><span class="n">m</span><span class="o">&&</span><span class="n">room</span><span class="p">;[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span><span class="o">!=</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">])</span>
<span class="p">{</span>
<span class="n">temp</span><span class="o">=</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]]</span><span class="o">+</span><span class="n">roomsize</span><span class="p">[</span><span class="n">room</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">]];</span>
<span class="k">if</span> <span class="p">(</span><span class="n">temp</span><span class="o">></span><span class="n">max</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">max</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="n">maxn</span><span class="o">=</span><span class="n">i</span><span class="p">;</span>
<span class="n">maxm</span><span class="o">=</span><span class="n">j</span><span class="p">;</span>
<span class="n">maxd</span><span class="o">=</span><span class="sc">'E'</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">max</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%d %d %c</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">maxn</span><span class="p">,</span><span class="n">maxm</span><span class="p">,</span><span class="n">maxd</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">stdin</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">stdout</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
空白垃圾邮件
2008-05-31T11:48:53+00:00
http://greenmooon55.com/blank-junk-mail
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/05/20080531181854015.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/05/20080531181854015.png" alt="" /></a></p>
<p>最近,收到了这样一封垃圾邮件。无主题、无内容、无发件人,只有发送时间。这是我第一次看到这种空白邮件。</p>
<p>今天我还发现我的gmail邮箱中又出现了中文垃圾邮件,以前出现过的中文垃圾邮件已经消失很长时间了。于是,我就到搜索引擎上搜了一下我的email地址。发现在中关村在线的个人资料中的email地址是<strong>公开的</strong>(地址:http://service.zol.com.cn/user/user_score/index.php?uid=*),并且<strong>不可修改</strong>!没想到ZOL居然这样,我己经给zol博客的一个管理员(似乎是)发站内消息了,不过估计很难解决。大家注册时一定小心啊!</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/05/20080531192822515.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/05/20080531192822515.png" alt="" /></a></p>
<p>PS: Google终于收录了本小站(上周发了重新审核申请) :D</p>
CookieMan Context
2008-05-26T11:50:43+00:00
http://greenmooon55.com/cookieman-context
<p>介绍:向Firefox的Cookie管理器和Cookie例外列表中添加右键菜单,可以在那选择“允许”、“会话中允许”或“阻止”,这就不用去例外列表中添加了。</p>
<p>我已经在BabelZilla把它翻译成中文了,以后(很快)就可以下载到中文版本。</p>
<p><a href="http://www.codedawn.com/firefox-extensions/cookieman-context/">作者页面</a> <a href="https://addons.mozilla.org/zh-CN/firefox/addon/4462">官方FF附加组件</a> (都有图,我已经删了,就不截图了)</p>
关于地震的更多思考
2008-05-24T15:55:41+00:00
http://greenmooon55.com/more-about-the-wenchuan-earthquake
<p><a href="http://www.gov.cn/ztzl/kzjz/content_981614.htm">国务院</a>决定,2008年5月19日至21日为全国哀悼日。周二看了第二段视频,很感人。</p>
<p>这是当天全国报纸头版汇集(来自<a href="http://www.hecaitou.net/?p=3029">和菜头</a>),<a href="http://www.donews.com/Content/200805/8717be6dcb504bcba8605c4262d326aa.shtm">国内网游停运</a>,网站都改为黑白色。</p>
<p><a href="http://www.hecaitou.net/?p=3029"><img src="http://pic.yupoo.com/hecaitou/5769159526a9/8zkw0k22.jpg" alt="5月19日报纸头版汇集" /></a></p>
<p>这次地震zf反应迅速,国外媒体似乎少有不失报道。如:<a href="http://search.cnn.com/search.jsp?query=china%20earthquake&type=news&sortBy=date&intl=true">CNN</a>。很多人都捐款了,但是对于红十字会的捐款使用问题大家都很关心。从网易以无法对捐款有效监控为由<a href="http://www.cnbeta.com/articles/55910.htm">停止与“中国红十字总会”合作</a>改成与廖冰兄基金会合作,并推出<a href="http://news.163.com/special/00012MVQ/sos01.html">投票</a>。红十字会刚开始还<a href="http://finance.baidu.com/hongguan/guonei/2008-05-15/145518113113.html">否认合作</a>,后来又因万元帐篷受质疑<a href="http://www.cnbeta.com/articles/56114.htm">1</a>,<a href="http://news.xinhuanet.com/local/2008-05/24/content_8242727.htm">2</a>,<a href="http://news.xinhuanet.com/newscenter/2008-05/24/content_8243522.htm">3</a>。还有<a href="http://finance.sina.com.cn/g/20080524/14464906790.shtml">红十字按国际惯例收取项目支持费不超6.5%</a>,但我没在新华网上找到(删了?),<a href="http://www.cnbeta.com/articles/56361.htm">CB</a>上有人这样说:</p>
<blockquote>
<p>100亿*6.5%=6.5亿….
估计这是人类有史以来最昂贵的管理费…..</p>
</blockquote>
<p>不过,我觉得这次红十字会很难把这笔钱花到别的地方去。但是还是推荐捐款到别处,比如<a href="http://www.onefoundation.cn">李连杰壹基金</a>(<a href="http://gongyi.qq.com/juanzeng/llj_dizhen.htm">tx</a>,<a href="http://jifen.alipay.com/operating/sichuandizhen/index.html">阿里巴巴</a>)。现在终于知道这个基金是怎么回事了(来自<a href="http://dycj.ynet.com/article.jsp?oid=40631944">北青网</a>):</p>
<blockquote>
<p>范娜介绍说,壹基金筹来的善款全部进入中国红十字会总会的专属账户。在这个过程中,壹基金不会直接接触到募集资金。壹基金的善款使用主要有三个方向,自然灾难的救助是其中之一,其他两个是传播公益文化和搭建公益平台。</p>
</blockquote>
<p>也就是说,壹基金<strong>不负责管钱,但是有权监督款项的使用</strong>。以这次救灾捐款过程为例,壹基金属于中国红十字会总会,所有捐款直接进入红会账户下的壹基金专属账户,资金的使用通过红十字会渠道。 但是,壹基金可以对资金的使用进行<strong>全程监管</strong>,壹基金管理委员对捐款的使用有<strong>决策权</strong>,此外,德勤会计师事务所将对善款的使用进行审计,并定期向大众公布。</p>
<p>据记者了解,在创办壹基金的过程中,李连杰思考最多的一个问题就是,“怎么样有一个制度,能够长久地保证透明、公正、可持续、符合法律法规地来运作一个机构?”
因此,壹基金采用了这样的管理架构:李连杰壹基金、李连杰在美国的OneFoundation、中国红十字总会各出两名人员,组成壹基金管理委员会,李连杰担任主任,其余5人为董事。每一个申请的项目和预算,都要由管委会集体讨论通过,才能签发文件拨款。</p>
<p>另外,房屋建设一定是有问题,以下文章中所提学校都没有问题:<a href="http://www.zaobao.com/zg/zg080522_506.shtml">港慈善团体所建学校不倒</a>、<a href="http://news.sina.com.cn/c/2008-05-24/123515610224.shtml">中学校长加固教学楼使2300余师生震后无一伤亡</a>、<a href="http://blog.sina.com.cn/s/blog_46e7ba41010091pk.html">北川邓家“刘汉小学”无一死亡奇迹背后的真相</a>(注意后面)。</p>
<p>最后,祝愿四川灾区早日恢复,奥运能成功举办,希望善款能够全部用在灾民身上,希望08年中国不要再不幸了。Bless~~ :D</p>
<p>Update _May 25, 2008 @17:55 _: 刚发现可能吧有一篇红十字会事件的<a href="http://www.kenengba.com/post/448.html">总结</a>很全,推荐。</p>
<p>Update _May 25, 2008 @18:42 _: 昨天忘写了,还有谷歌19日14时28分左右的<a href="http://googlechinablog.com/2008/05/blog-post_22.html">流量数据曲线</a>,几乎为0。</p>
Milking Cows
2008-05-18T09:59:43+00:00
http://greenmooon55.com/milking-cows
<p>翻译:<a href="http://www.nocow.cn/index.php/Translate:USACO/milk2">http://www.nocow.cn/index.php/Translate:USACO/milk2</a></p>
<p>先qsort,然后把每小段的起始存起来,再循环找一下就行。神奇的是,我qsort都打错了却过了6组。。:D</p>
<hr />
<p><strong>UPDATE @ 2010/3/12 17:19</strong> 当年发错程序了,删掉了。
今天做的这个最开始总是不对,本机没问题,传上去就出错。后来发现不能写成bool time[1000001]={0},用了memset,MS用法和pascal里的fillchar一样。time[i]表示从i到i+1的时间被占用,这应该是最白痴的做法了。
<strong>UPDATE @ 2010/3/25 18:51</strong>memset好像用错了。。好像是memset(<strong>,0,sizeof(</strong>))。。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
TASK: milk2
*/</span>
<span class="cp">#include
#include
</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">bool</span> <span class="n">time</span><span class="p">[</span><span class="mi">1000001</span><span class="p">];</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">n</span><span class="p">;</span>
<span class="kt">long</span> <span class="n">j</span><span class="p">,</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">;</span>
<span class="kt">long</span> <span class="n">low</span><span class="p">,</span><span class="n">high</span><span class="p">,</span><span class="n">count</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="n">max</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"milk2.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"milk2.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="n">memset</span><span class="p">(</span><span class="n">time</span><span class="p">,</span><span class="k">sizeof</span><span class="p">(</span><span class="n">time</span><span class="p">),</span><span class="nb">false</span><span class="p">);</span>
<span class="n">low</span><span class="o">=</span><span class="mi">1000000</span><span class="p">;</span>
<span class="n">high</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
<span class="n">max</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">max</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">count</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">count</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d %d"</span><span class="p">,</span><span class="o">&</span><span class="n">a</span><span class="p">;,</span><span class="o">&</span><span class="n">b</span><span class="p">;);</span>
<span class="k">if</span><span class="p">(</span><span class="n">a</span><span class="o"><</span><span class="n">low</span><span class="p">)</span> <span class="n">low</span><span class="o">=</span><span class="n">a</span><span class="p">;</span>
<span class="k">if</span><span class="p">(</span><span class="n">b</span><span class="o">></span><span class="n">high</span><span class="p">)</span> <span class="n">high</span><span class="o">=</span><span class="n">b</span><span class="p">;</span>
<span class="k">for</span><span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="n">a</span><span class="p">;</span><span class="n">j</span><span class="o"><</span><span class="n">b</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span> <span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="nb">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">for</span><span class="p">(</span><span class="n">j</span><span class="o">=</span><span class="n">low</span><span class="p">;</span><span class="n">j</span><span class="o"><=</span><span class="n">high</span><span class="p">;</span><span class="n">j</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">count</span><span class="p">[</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">]]</span><span class="o">++</span><span class="p">;</span>
<span class="k">if</span><span class="p">(</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">!=</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">])</span>
<span class="p">{</span>
<span class="k">if</span><span class="p">(</span><span class="n">count</span><span class="p">[</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">]]</span><span class="o">></span><span class="n">max</span><span class="p">[</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">]])</span> <span class="n">max</span><span class="p">[</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">]]</span><span class="o">=</span><span class="n">count</span><span class="p">[</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">]];</span>
<span class="n">count</span><span class="p">[</span><span class="n">time</span><span class="p">[</span><span class="n">j</span><span class="p">]]</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">max</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">max</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
<hr />
<p><strong>UPDATE @ 2010/3/13 21:38</strong>
C语言的struct、随机快排。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
TASK: milk2
*/</span>
<span class="cp">#include
#include
</span>
<span class="k">struct</span> <span class="n">time</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">;</span>
<span class="p">};</span>
<span class="k">struct</span> <span class="n">time</span> <span class="n">milk</span><span class="p">[</span><span class="mi">5000</span><span class="p">];</span>
<span class="kt">void</span> <span class="nf">quicksort</span><span class="p">(</span><span class="kt">long</span> <span class="n">l</span><span class="p">,</span> <span class="kt">long</span> <span class="n">r</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">long</span> <span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">pivot</span><span class="p">;</span>
<span class="k">struct</span> <span class="n">time</span> <span class="n">temp</span><span class="p">;</span>
<span class="n">pivot</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="n">rand</span><span class="p">()</span><span class="o">%</span><span class="p">(</span><span class="n">r</span><span class="o">-</span><span class="n">l</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="n">l</span><span class="p">].</span><span class="n">a</span><span class="p">;</span>
<span class="n">i</span><span class="o">=</span><span class="n">l</span><span class="p">;</span>
<span class="n">j</span><span class="o">=</span><span class="n">r</span><span class="p">;</span>
<span class="k">while</span><span class="p">(</span><span class="n">i</span><span class="o"><</span><span class="n">j</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">while</span><span class="p">(</span><span class="n">milk</span><span class="p">[</span><span class="n">j</span><span class="p">].</span><span class="n">a</span><span class="o">></span><span class="n">pivot</span><span class="p">)</span> <span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="k">while</span><span class="p">(</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="o"><</span><span class="n">pivot</span><span class="p">)</span> <span class="n">i</span><span class="o">++</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o"><=</span><span class="n">j</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">temp</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">milk</span><span class="p">[</span><span class="n">j</span><span class="p">]</span><span class="o">=</span><span class="n">temp</span><span class="p">;</span>
<span class="n">i</span><span class="o">++</span><span class="p">;</span>
<span class="n">j</span><span class="o">--</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">i</span><span class="o"><</span><span class="n">r</span><span class="p">)</span> <span class="n">quicksort</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">r</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">j</span><span class="o">></span><span class="n">l</span><span class="p">)</span> <span class="n">quicksort</span><span class="p">(</span><span class="n">l</span><span class="p">,</span><span class="n">j</span><span class="p">);</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"milk2.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"milk2.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">i</span><span class="p">,</span><span class="n">n</span><span class="p">;</span>
<span class="kt">long</span> <span class="n">start</span><span class="p">,</span><span class="n">end</span><span class="p">,</span><span class="n">work</span><span class="p">,</span><span class="n">idle</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="n">srand</span><span class="p">(</span><span class="n">time</span><span class="p">(</span><span class="nb">NULL</span><span class="p">));</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d%d"</span><span class="p">,</span><span class="o">&</span><span class="n">milk</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="p">,</span><span class="o">&</span><span class="n">milk</span><span class="p">;[</span><span class="n">i</span><span class="p">].</span><span class="n">b</span><span class="p">);</span>
<span class="n">quicksort</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">);</span>
<span class="n">start</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">a</span><span class="p">;</span>
<span class="n">end</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">b</span><span class="p">;</span>
<span class="n">work</span><span class="o">=</span><span class="n">end</span><span class="o">-</span><span class="n">start</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="o">></span><span class="n">end</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">end</span><span class="o">-</span><span class="n">start</span><span class="o">></span><span class="n">work</span><span class="p">)</span> <span class="n">work</span><span class="o">=</span><span class="n">end</span><span class="o">-</span><span class="n">start</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="o">-</span><span class="n">end</span><span class="o">></span><span class="n">idle</span><span class="p">)</span> <span class="n">idle</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="o">-</span><span class="n">end</span><span class="p">;</span>
<span class="n">start</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">a</span><span class="p">;</span>
<span class="n">end</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">b</span><span class="o">></span><span class="n">end</span><span class="p">)</span> <span class="n">end</span><span class="o">=</span><span class="n">milk</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">b</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">work</span><span class="p">,</span><span class="n">idle</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
Score Inflation
2008-05-18T09:39:50+00:00
http://greenmooon55.com/score-inflation
<p>翻译:<a href="http://www.nocow.cn/index.php/Translate:USACO/inflate">http://www.nocow.cn/index.php/Translate:USACO/inflate</a></p>
<p>第一个递归会超时,第二个是背包:f[n,m]=max{f[n-1,m]+f[n,m-t[n]]+s[n]}</p>
<!-- more -->
<blockquote>
<p>USER: Jin Dong [djgreen1]
TASK: inflate
LANG: PASCAL</p>
</blockquote>
<p>Compiling…
Compile: OK</p>
<p>Executing…
Test 1: TEST OK [0.000 secs, 276 KB]
Test 2: TEST OK [0.000 secs, 280 KB]
Test 3: TEST OK [0.011 secs, 280 KB]</p>
<blockquote>
<p>Run 4: Execution error: Your program (`inflate’) used more than
the allotted runtime of 1 seconds (it ended or was stopped at
2.700 seconds) when presented with test case 4. It used 280 KB of
memory.</p>
</blockquote>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Test 4: RUNTIME 2.700>1 (280 KB)
</code></pre></div></div>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">{
ID: djgreen1
PROG: inflate
LANG: PASCAL
}</span>
<span class="k">program</span> <span class="n">inflatev1</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">score</span><span class="p">,</span> <span class="n">time</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..10000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">max</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">work</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">p</span><span class="p">:</span> <span class="kt">longint</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">t</span> <span class="p">&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">gt</span><span class="p">;</span> <span class="n">m</span> <span class="k">then</span> <span class="k">exit</span><span class="p">;</span>
<span class="k">if</span> <span class="n">s</span> <span class="p">&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">gt</span><span class="p">;</span> <span class="n">max</span> <span class="k">then</span> <span class="n">max</span> <span class="p">:=</span> <span class="n">s</span><span class="p">;</span>
<span class="k">if</span> <span class="n">p</span> <span class="p">&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">gt</span><span class="p">;</span> <span class="n">n</span> <span class="k">then</span> <span class="k">exit</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">0</span> <span class="k">to</span> <span class="n">m</span> <span class="k">div</span> <span class="n">time</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="k">do</span> <span class="n">work</span><span class="p">(</span><span class="n">s</span> <span class="p">+</span> <span class="n">score</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="p">*</span> <span class="n">i</span><span class="p">,</span> <span class="n">t</span> <span class="p">+</span> <span class="n">time</span><span class="p">[</span><span class="n">p</span><span class="p">]</span> <span class="p">*</span> <span class="n">i</span><span class="p">,</span> <span class="n">p</span> <span class="p">+</span> <span class="m">1</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'inflate.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="s">'inflate.out'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">);</span>
<span class="n">max</span> <span class="p">:=</span> <span class="m">0</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">readln</span><span class="p">(</span><span class="n">score</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">time</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">work</span><span class="p">(</span><span class="m">0</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="m">1</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">max</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<blockquote>
<p>USER: Jin Dong [djgreen1]
TASK: inflate
LANG: PASCAL</p>
</blockquote>
<p>Compiling…
Compile: OK</p>
<p>Executing…
Test 1: TEST OK [0.000 secs, 320 KB]
Test 2: TEST OK [0.000 secs, 320 KB]
Test 3: TEST OK [0.000 secs, 324 KB]
Test 4: TEST OK [0.000 secs, 324 KB]
Test 5: TEST OK [0.011 secs, 324 KB]
Test 6: TEST OK [0.032 secs, 324 KB]
Test 7: TEST OK [0.130 secs, 320 KB]
Test 8: TEST OK [0.346 secs, 320 KB]
Test 9: TEST OK [0.583 secs, 324 KB]
Test 10: TEST OK [0.605 secs, 320 KB]
Test 11: TEST OK [0.000 secs, 324 KB]
Test 12: TEST OK [0.000 secs, 324 KB]</p>
<p>All tests OK.
Your program (‘inflate’) produced all correct answers! This is your
submission #3 for this problem. Congratulations!</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">{
ID: djgreen1
PROG: inflate
LANG: PASCAL
}</span>
<span class="k">program</span> <span class="n">inflatev2</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">score</span><span class="p">,</span> <span class="n">time</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..10000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">max</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">ans</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..10000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'inflate.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="s">'inflate.out'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">n</span><span class="p">);</span>
<span class="n">max</span> <span class="p">:=</span> <span class="m">0</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="n">readln</span><span class="p">(</span><span class="n">score</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">time</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="n">time</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">&</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">amp</span><span class="p">;</span><span class="n">lt</span><span class="p">;</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span> <span class="p">-</span> <span class="n">time</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="p">+</span> <span class="n">score</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">then</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">:=</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span> <span class="p">-</span>
<span class="n">time</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="p">+</span> <span class="n">score</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">m</span><span class="p">]);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
NOIP2004提高组合唱队形
2008-05-18T06:46:29+00:00
http://greenmooon55.com/noip2004-chrous
<p>题目很容易理解,可以去<a href="http://www.baidu.com/s?ie=gb2312&bs=noip2004%CC%E1%B8%DF&sr=&z=&cl=3&f=8&wd=noip2004%CC%E1%B8%DF+%BA%CF%B3%AA%B6%D3%D0%CE&ct=0">搜索</a>。在<a href="http://www.rqnoj.cn/Problem_Show.asp?PID=26">RQNOJ</a>中是第26题。</p>
<p>注意题中条件,身高不能相等,然后用求最长不上升序列的方法即可。</p>
<p>PS:很烦RQNOJ答对题就不能提交了。。据说只能用MJ。
<!-- more --></p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">hechang</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">a</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">1..100</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">1..100</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">sum</span><span class="p">,</span> <span class="n">temp</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">find</span><span class="p">:</span> <span class="kt">boolean</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'hechang.in'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">sum</span> <span class="p">:=</span> <span class="m">0</span><span class="p">;</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="k">read</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">left</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">left</span><span class="p">),</span> <span class="m">0</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">right</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">right</span><span class="p">),</span> <span class="m">0</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">2</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">find</span> <span class="p">:=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">i</span> <span class="p">-</span> <span class="m">1</span> <span class="k">do</span> <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p"><</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">and</span> <span class="p">(</span><span class="n">left</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">>=</span> <span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:=</span> <span class="n">left</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">find</span> <span class="p">:=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">find</span> <span class="k">then</span> <span class="k">inc</span><span class="p">(</span><span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="n">n</span> <span class="p">-</span> <span class="m">1</span> <span class="k">downto</span> <span class="m">1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">find</span> <span class="p">:=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="n">n</span> <span class="k">downto</span> <span class="n">i</span> <span class="p">+</span> <span class="m">1</span> <span class="k">do</span> <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p"><</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">and</span> <span class="p">(</span><span class="n">right</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">>=</span> <span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:=</span> <span class="n">right</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="n">find</span> <span class="p">:=</span> <span class="nb">true</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">if</span> <span class="n">find</span> <span class="k">then</span> <span class="k">inc</span><span class="p">(</span><span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">temp</span> <span class="p">:=</span> <span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">+</span> <span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">if</span> <span class="n">temp</span> <span class="p">></span> <span class="n">sum</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">sum</span> <span class="p">:=</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">n</span> <span class="p">-</span> <span class="n">sum</span> <span class="p">-</span> <span class="m">1</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">hechang</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">a</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">1..100</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">1..100</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">sum</span><span class="p">,</span> <span class="n">temp</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'chorus10.in'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">sum</span> <span class="p">:=</span> <span class="m">0</span><span class="p">;</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="k">read</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">left</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">left</span><span class="p">),</span> <span class="m">0</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">right</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">right</span><span class="p">),</span> <span class="m">0</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">i</span> <span class="p">-</span> <span class="m">1</span> <span class="k">do</span> <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p"><</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">and</span> <span class="p">(</span><span class="n">left</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">>=</span> <span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:=</span> <span class="n">left</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="n">n</span> <span class="k">downto</span> <span class="m">1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="n">n</span> <span class="k">downto</span> <span class="n">i</span> <span class="p">+</span> <span class="m">1</span> <span class="k">do</span> <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p"><</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">and</span> <span class="p">(</span><span class="n">right</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">>=</span> <span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:=</span> <span class="n">right</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">temp</span> <span class="p">:=</span> <span class="n">left</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">+</span> <span class="n">right</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">if</span> <span class="n">temp</span> <span class="p">></span> <span class="n">sum</span> <span class="k">then</span>
<span class="k">begin</span>
<span class="n">sum</span> <span class="p">:=</span> <span class="n">temp</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">n</span> <span class="p">-</span> <span class="n">sum</span> <span class="p">+</span> <span class="m">1</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
四川汶川地震
2008-05-18T05:38:38+00:00
http://greenmooon55.com/2008-wenchuan-earthquake
<p><img src="http://review.feedsky.com/review/feedsky/greenmoon55/~/img/171/cw.gif" alt="" /></p>
<p>一场里氏7.8级的特大地震5月12日14时28分在中国的四川省爆发。<a href="http://earthquake.usgs.gov/eqcenter/recenteqsww/Quakes/us2008ryan.php">美国联邦地质调查局的介绍</a>。我是当天晚上才知道的,从第二天开始关注新闻。</p>
<p>据<a href="http://news.sina.com.cn/c/2008-05-17/160715561075.shtml">新浪网报道</a>:截止昨日(18日)14时,死亡人数达28881人,受伤198347人;救灾工作重点将转向农村,目前无重大疫情报告。目前余震不断,可以从<a href="http://earthquake.usgs.gov/eqcenter/recenteqsww/Maps/10/105_30.php">这张图</a>看出(推荐)。还可以从这个网站看到<a href="http://earthquake.usgs.gov/eqcenter/recenteqsww/Quakes/quakes_all.php">最近7天的世界上2.5级以上所有地震</a>,为了看得更清楚些,可以看看<a href="http://earthquake.usgs.gov/eqcenter/recenteqsww/Quakes/quakes_big.php">5级以上的</a>,其中大部分都是这次的余震。</p>
<p>推荐使用<a href="http://www.williamlong.info/google/">Google Earth</a>查看最新情况:<a href="http://googlechinablog.com/2008/05/blog-post_13.html">http://googlechinablog.com/2008/05/blog-post_13.html</a>。也可以下载这个<a href="http://mw2.google.com/mw-earth-vectordb/china_earthquake/china_earthquake.kml"><strong>KML</strong>地标文件</a>,打开这个地标就可以看到台湾福卫二号的拍摄的四川汶川震区的清晰卫星图像(据<a href="http://www.williamlong.info/archives/1343.html">月光博客</a>),但是分辨率好像很低(或许是我网速慢没显示)。</p>
<p><a href="http://ditu.google.com/maps/ms?hl=zh-CN&ie=UTF8&oe=UTF8&msa=0&msid=105498083399349668294.00044d0490f73e7f5c173&mid=1210583203">谷歌</a>、<a href="http://maps.baidu.com/dzindex.html">百度</a>、<a href="http://ditu.live.com/?v=2&cid=8FA3D22DC63E1BF5!108&encType=1">Live的地图搜索</a>都推出了专题地图,很多网站都推出了寻亲专项搜索(<a href="http://www.google.cn/intl/zh-CN/qinren/cse.html">谷歌</a>、<a href="http://comment4.news.sina.com.cn/comment/quakehelp.html">新浪</a>、<a href="http://www.sogou.com/xunqin/">搜狗</a>、<a href="http://www.xunren110.org/">四川地震寻亲友网</a>),如果你的亲人在那里可以去试试。</p>
<p>2008年是我国多灾多难的一年,南方雪灾、CPI上涨、ZD都对我国影响不小。作为一个普通人,希望大家尽自己的一份力,积极捐款,哪怕只是一元钱。推荐阅读:<a href="http://genmicha.cn/survivor-me.htm">http://genmicha.cn/survivor-me.htm</a>。</p>
<p><strong>捐款:</strong></p>
<blockquote>
<p>中国移动的客户可以通过发送手机短信进行捐款:编辑短信1至30,发送至1069999301,即可向灾区捐款1至30元,可以重复捐赠。此次捐赠活动客户产生的通信费用,中国移动将全部捐赠给灾区用于救灾 <a href="http://www.chinamobile.com/focus/earthquake/">信息来源</a></p>
</blockquote>
<p>中国红十字会总会救灾专用账号和热线:
1、通过银行捐款
开户单位:中国红十字会总会
人民币开户行:中国工商银行北京分行东四南支行
人民币账号:0200001009014413252
外币开户行:中信银行酒仙桥支行
外币账号:7112111482600000209
2、通过邮局捐款
收款人:中国红十字会总会
地址:北京市东城区北新桥三条8号
邮政编码:100007
3、通过网上捐款
登陆中国红十字会总会网站:<a href="http://redcross.org.cn">http://redcross.org.cn</a>点击进入“网上捐赠”栏目,按照提示操作即可。 <a href="http://www.redcross.org.cn/news/20080513/8930.htm">信息来源</a></p>
<p>如果您想捐出支付宝或财付通中的钱,还可以通过<a href="http://market.alipay.com/alipay/sichuandizhen/index.html">支付宝捐助</a>、<a href="http://gongyi.qq.com/juanzeng/llj_dizhen.htm">腾讯捐助</a>。还有很多网站都推出了捐助专页。</p>
<p>现在时间过得很快,100多个小时已经过去了,幸存者生还的希望越来越渺茫。Bless All~~</p>
<p><a href="http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/171/r.html">为震区同胞祈福,祝福灾区的同胞们平安脱险</a></p>
Symonds: Engine blow is a worry
2008-05-01T09:41:51+00:00
http://greenmooon55.com/symonds-engine-blow-is-a-worry
<p>Wednesday, 30 April 2008 00:00
原文:<a href="http://www.itv-f1.com/News_Article.aspx?id=42478">http://www.itv-f1.com/News_Article.aspx?id=42478</a></p>
<p>Pat Symonds承认,尽管他有信心问题会得到解决,Fernando Alonso在西班牙大奖赛中的引擎故障使车队有些担忧下一站土耳其大奖赛。</p>
<p>Alonso本来可以在家乡取得很多分数并为车队留下印象深刻的一个周末,但是当Alonso的RS28引擎在第35圈爆缸_(let go放开, 释放, 发射)_时,这就被抢走了。</p>
<p>周一,这个雷诺从蒙扎2006年以来的_(outfit’s全套装备; 全套工具; 全部用品?)<em>第一次故障很快就在被查明,车队也向itv.com/f1证实这是由分电盘</em>(分电盘(Distributor) 点火系统高低压电的转接站,可将通往发火线圈的电路接通或切断,而后将产生的高电压配送到各缸火星塞。)_问题引起的。</p>
<p>Symonds在雷诺最新的播客_(podcast播客?)_上说到,爆缸和爆缸的原因都令人惊讶。</p>
<p>总工程师说:“我们在周一上午把引擎送回了Viry并将它拆解。在我们把引擎从车中取出前,我们对问题是什么有个好的想法。周一上午确认了问题在哪,这问题确实令我们惊讶。尽管这是引擎一直在极限上_(on the limit)<em>工作的一个区域,但比赛也在极限——这就是问题的愿意。但是这不是我们在这种引擎上以前出现故障的区域,所以这是我们有点惊讶。虽然我们知道故障是什么,我们对零件</em>(component零件, 组成整件部分的单件; 构成要素; 成分)_的失灵不能做出完全解释。”</p>
<p>Symonds承认车队还没有_(has yet to do sth.=has not yet done sth)<em>找到</em>(establish show (sth) to be true; prove 确定(某事物); 证实)<em>分电盘小故障</em>(glitch 小故障, 技术性的小毛病, 失灵; 低频干扰)_的原因,这自然使车队有些担忧。</p>
<p>当被问到故障是否在下一站比赛中令人担心时,他回答道:“是的。任何不理解_(lack of understanding)_都令人担忧。”</p>
<p>然而,他相信或许问题会被证实是一次性_(one-off)<em>的,他还表达了他对引擎工程师</em>(engine engineers)<em>解决这一问题</em>(resolve the issue)_的能力的信心。</p>
<p>他补充说:“我对Viry的同事们_(colleagues)<em>将会有一个答案相当有信心,我也认为我们将会找出这是一个例外</em>(exception)<em>。当你在一个一般不出现问题的区域内出现问题,这一般是由于</em>(due to)<em>漏网</em>(<a href="http://idioms.thefreedictionary.com/slipped+through+the+net">Idom: slipped through the net</a>)<em>的制造过程中</em>(manufacture 制造, 加工; 粗制滥造; 捏造; 制造)<em>的错误</em>(error)<em>或类似的问题。所以,当然我因我们不知道问题的原因而担忧,但是我猜想</em>(suspect 疑有, 察觉; 怀疑; 不信任; 猜想; 怀疑, 疑心; 猜疑)<em>我们的担忧将到达土耳其的时候减轻</em>(alleviate 减轻, 使缓和)_。”</p>
Friday the Thirteenth
2008-05-01T01:32:33+00:00
http://greenmooon55.com/friday-the-thirteenth
<p>翻译:<a href="http://www.nocow.cn/index.php/USACO/friday">http://www.nocow.cn/index.php/USACO/friday</a></p>
<p>最简单的方法就能AC,一个月一个月算,我也是这样算的。<a href="http://www.nocow.cn/index.php/USACO/friday">这里</a>提到可以按年算,想法不错。注意年份是1900+N-1。</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">{
ID: djgreen1
PROG: friday
LANG: PASCAL
}</span>
<span class="k">program</span> <span class="n">friday</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">sum</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..6</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">date</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">function</span> <span class="n">leap</span><span class="p">(</span><span class="n">year</span><span class="p">:</span> <span class="kt">longint</span><span class="p">):</span> <span class="kt">boolean</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="p">(</span><span class="n">year</span> <span class="k">mod</span> <span class="m">4</span> <span class="p">=</span> <span class="m">0</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">year</span> <span class="k">mod</span> <span class="m">100</span> <span class="p">></span> <span class="m">0</span><span class="p">)</span> <span class="k">then</span> <span class="n">leap</span> <span class="p">:=</span> <span class="nb">true</span>
<span class="k">else</span> <span class="k">if</span> <span class="n">year</span> <span class="k">mod</span> <span class="m">400</span> <span class="p">=</span> <span class="m">0</span> <span class="k">then</span> <span class="n">leap</span> <span class="p">:=</span> <span class="nb">true</span>
<span class="k">else</span> <span class="n">leap</span> <span class="p">:=</span> <span class="nb">false</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'friday.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="s">'friday.out'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="n">fillchar</span><span class="p">(</span><span class="n">sum</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">sum</span><span class="p">),</span> <span class="m">0</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="m">6</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">3</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="k">if</span> <span class="n">leap</span><span class="p">(</span><span class="m">1899</span> <span class="p">+</span> <span class="n">i</span><span class="p">)</span> <span class="k">then</span> <span class="k">inc</span><span class="p">(</span><span class="n">date</span><span class="p">);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">3</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">2</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">3</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">2</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">3</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">3</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">2</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">3</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">2</span><span class="p">;</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="k">mod</span> <span class="m">7</span><span class="p">;</span>
<span class="k">inc</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="n">date</span><span class="p">]);</span>
<span class="n">date</span> <span class="p">:=</span> <span class="n">date</span> <span class="p">+</span> <span class="m">3</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">write</span><span class="p">(</span><span class="n">sum</span><span class="p">[</span><span class="m">6</span><span class="p">]);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">0</span> <span class="k">to</span> <span class="m">5</span> <span class="k">do</span> <span class="k">write</span><span class="p">(</span><span class="s">' '</span><span class="p">,</span> <span class="n">sum</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="k">writeln</span><span class="p">;</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<!-- more -->
<p><strong>UPDATE @ 2010/3/9/15:05</strong>
C语言不能用mod,要用%。。这样判断闰年很简洁,网上搜来的。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
TASK: friday
*/</span>
<span class="cp">#include
#include
</span>
<span class="n">bool</span> <span class="nf">leapyear</span> <span class="p">(</span><span class="kt">int</span> <span class="n">year</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">return</span> <span class="p">((</span><span class="n">year</span><span class="o">%</span><span class="mi">4</span><span class="o">==</span><span class="mi">0</span> <span class="o">&&</span> <span class="n">year</span><span class="o">%</span><span class="mi">100</span><span class="o">></span><span class="mi">0</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="n">year</span><span class="o">%</span><span class="mi">400</span><span class="o">==</span><span class="mi">0</span><span class="p">));</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"friday.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"friday.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">sum</span><span class="p">[</span><span class="mi">8</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">},</span><span class="n">day</span><span class="p">;</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="n">day</span><span class="o">=</span><span class="mi">6</span><span class="p">;</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//1.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">3</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//2.13
</span> <span class="k">if</span> <span class="p">(</span><span class="n">leapyear</span><span class="p">(</span><span class="mi">1900</span><span class="o">+</span><span class="n">i</span><span class="p">))</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//3.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">3</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//4.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">2</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//5.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">3</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//6.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">2</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//7.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">3</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//8.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">3</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//9.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">2</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//10.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">3</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//11.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">2</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="n">sum</span><span class="p">[</span><span class="n">day</span><span class="p">]</span><span class="o">++</span><span class="p">;</span><span class="c1">//12.13
</span> <span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">+</span><span class="mi">3</span><span class="p">;</span>
<span class="n">day</span><span class="o">=</span><span class="n">day</span><span class="o">%</span><span class="mi">7</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%d %d %d %d %d %d %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">sum</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span><span class="n">sum</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">sum</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">sum</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span><span class="n">sum</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span><span class="n">sum</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span><span class="n">sum</span><span class="p">[</span><span class="mi">5</span><span class="p">]);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
Money Systems
2008-04-30T15:29:22+00:00
http://greenmooon55.com/money-systems
<p>翻译:<a href="http://www.nocow.cn/index.php/Translate:USACO/money">http://www.nocow.cn/index.php/Translate:USACO/money</a></p>
<p>题意很好理解,与背包类似。N种构成金额为M,则状态转移方程为f[n,m]=f[n-1,m]+f[<strong>n</strong>,m-value[n]]。若转化为数组则每个值只需要上方的和左侧某个值(不一定取得到,m-value[n]>=0),所以可以从左到右处理一维数组。由于数据比较大,还需使用<strong>INT64</strong>。详见程序。</p>
<!-- more -->
<p>My Program:</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">{
ID: djgreen1
PROG: money
LANG: PASCAL
}</span>
<span class="k">program</span> <span class="n">money</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">ans</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..10000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">int64</span><span class="p">;</span>
<span class="k">value</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..25</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'money.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="s">'money.out'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">m</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span> <span class="k">read</span><span class="p">(</span><span class="k">value</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="n">ans</span><span class="p">[</span><span class="m">0</span><span class="p">]</span> <span class="p">:=</span> <span class="m">1</span><span class="p">;</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">m</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">if</span> <span class="n">j</span> <span class="p">-</span> <span class="k">value</span><span class="p">[</span><span class="n">i</span><span class="p">]>=</span> <span class="m">0</span> <span class="k">then</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">:=</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">+</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span> <span class="p">-</span> <span class="k">value</span><span class="p">[</span><span class="n">i</span><span class="p">]];</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">m</span><span class="p">]);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<blockquote>
<p>USER: *** [djgreen1]
TASK: money
LANG: PASCAL</p>
</blockquote>
<p>Compiling…
Compile: OK</p>
<p>Executing…
Test 1: TEST OK [0.000 secs, 276 KB]
Test 2: TEST OK [0.000 secs, 276 KB]
Test 3: TEST OK [0.000 secs, 276 KB]
Test 4: TEST OK [0.000 secs, 276 KB]
Test 5: TEST OK [0.000 secs, 276 KB]
Test 6: TEST OK [0.011 secs, 276 KB]
Test 7: TEST OK [0.000 secs, 276 KB]
Test 8: TEST OK [0.011 secs, 276 KB]
Test 9: TEST OK [0.000 secs, 276 KB]
Test 10: TEST OK [0.011 secs, 276 KB]
Test 11: TEST OK [0.000 secs, 276 KB]
Test 12: TEST OK [0.000 secs, 280 KB]
Test 13: TEST OK [0.000 secs, 280 KB]</p>
<p>All tests OK.
YOUR PROGRAM (‘money’) WORKED FIRST TIME! That’s fantastic
– and a rare thing. Please accept these special automated
congratulations.</p>
<p>Here are the test data inputs:</p>
<p>——- test 1 ——-
1 1
1
——- test 2 ——-
3 10
1 2 5
——- test 3 ——-
10 100
1 2 3 4 5 6 7 8 9 10
——- test 4 ——-
25 1000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25
——- test 5 ——-
25 9999
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
25000
26
——- test 6 ——-
25 9999
346
130
982
1090
1656
7117
7595
6415
2948
1126
9004
4558
3571
2879
8492
1360
5412
6721
2463
5047
7119
1441
7190
3985
1214
——- test 7 ——-
25 999
7843
4639
1653
3876
5457
2152
2524
2412
7461
3564
4634
7717
5947
4056
1048
6123
1757
5964
1137
3094
671
5869
2719
631
3563
——- test 8 ——-
25 100
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
——- test 9 ——-
25 100
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
——- test 10 ——-
5 10000
5 8 13 21 34
——- test 11 ——-
17 500
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
——- test 12 ——-
8 10000
1 2 3 4 5 6 20 25
——- test 13 ——-
17 2000
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27</p>
<p>Keep up the good work!</p>
<p>Thanks for your submission!</p>
Broken Necklace
2008-04-27T14:21:27+00:00
http://greenmooon55.com/broken-necklace
<p>翻译: <a href="http://www.nocow.cn/index.php/Translate:USACO/beads">http://www.nocow.cn/index.php/Translate:USACO/beads</a></p>
<p>大概思路就是复制3遍,然后在中间那段一个一个找,如果找过头了就ans:=n。 :)</p>
<p>My program:</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">{
ID: djgreen1
PROG: beads
LANG: PASCAL
}</span>
<span class="k">program</span> <span class="n">beads</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">n</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">a</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">0..1050</span><span class="p">]</span> <span class="k">of</span> <span class="kt">char</span><span class="p">;</span>
<span class="n">ans</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">init</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">read</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span> <span class="p">+</span> <span class="n">n</span><span class="p">]</span> <span class="p">:=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span> <span class="p">+</span> <span class="n">n</span> <span class="p">*</span> <span class="m">2</span><span class="p">]</span> <span class="p">:=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">readln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">work</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">k</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">first</span><span class="p">,</span> <span class="n">second</span><span class="p">:</span> <span class="kt">char</span><span class="p">;</span>
<span class="k">begin</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="n">n</span> <span class="p">*</span> <span class="m">2</span> <span class="k">downto</span> <span class="n">n</span> <span class="p">+</span> <span class="m">1</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">j</span> <span class="p">:=</span> <span class="n">i</span> <span class="p">+</span> <span class="m">1</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">=</span> <span class="s">'w'</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">j</span> <span class="p"><=</span> <span class="n">i</span> <span class="p">+</span> <span class="n">n</span> <span class="p">*</span> <span class="m">2</span><span class="p">)</span> <span class="k">do</span> <span class="k">inc</span><span class="p">(</span><span class="n">j</span><span class="p">);</span>
<span class="n">first</span> <span class="p">:=</span> <span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">=</span> <span class="n">first</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">=</span> <span class="s">'w'</span><span class="p">)</span> <span class="k">do</span> <span class="k">inc</span><span class="p">(</span><span class="n">j</span><span class="p">);</span>
<span class="n">k</span> <span class="p">:=</span> <span class="n">i</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="p">=</span> <span class="s">'w'</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">k</span> <span class="p">></span> <span class="m">0</span><span class="p">)</span> <span class="k">do</span> <span class="n">dec</span><span class="p">(</span><span class="n">k</span><span class="p">);</span>
<span class="n">first</span> <span class="p">:=</span> <span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="p">=</span> <span class="n">first</span><span class="p">)</span> <span class="k">or</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="p">=</span> <span class="s">'w'</span><span class="p">)</span> <span class="k">do</span> <span class="n">dec</span><span class="p">(</span><span class="n">k</span><span class="p">);</span>
<span class="k">if</span> <span class="n">ans</span> <span class="p"><</span> <span class="n">j</span> <span class="p">-</span> <span class="n">k</span> <span class="p">-</span> <span class="m">1</span> <span class="k">then</span> <span class="n">ans</span> <span class="p">:=</span> <span class="n">j</span> <span class="p">-</span> <span class="n">k</span> <span class="p">-</span> <span class="m">1</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">ans</span> <span class="p">:=</span> <span class="m">0</span><span class="p">;</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'beads.in'</span><span class="p">);</span>
<span class="n">assign</span><span class="p">(</span><span class="n">output</span><span class="p">,</span> <span class="s">'beads.out'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">init</span><span class="p">;</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="n">work</span><span class="p">;</span>
<span class="k">if</span> <span class="n">ans</span> <span class="p">></span> <span class="n">n</span> <span class="k">then</span> <span class="n">ans</span> <span class="p">:=</span> <span class="n">n</span><span class="p">;</span>
<span class="n">rewrite</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">ans</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">output</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
<p>Update @ 2010/3/10 20:37 用C重写了,没优化什么就过了。</p>
<div class="language-c highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="cm">/*
ID: djgreen1
LANG: C
TASK: beads
*/</span>
<span class="cp">#include
</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">FILE</span> <span class="o">*</span><span class="n">in</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"beads.in"</span><span class="p">,</span><span class="s">"r"</span><span class="p">),</span><span class="o">*</span><span class="n">out</span><span class="o">=</span><span class="n">fopen</span><span class="p">(</span><span class="s">"beads.out"</span><span class="p">,</span><span class="s">"w"</span><span class="p">);</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">,</span><span class="n">i</span><span class="p">,</span><span class="n">breakpoint</span><span class="p">,</span><span class="n">length1</span><span class="p">,</span><span class="n">length2</span><span class="p">,</span><span class="n">num</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">point</span><span class="p">;</span>
<span class="kt">char</span> <span class="n">bead</span><span class="p">[</span><span class="mi">1051</span><span class="p">]</span><span class="o">=</span><span class="p">{</span><span class="mi">0</span><span class="p">},</span><span class="n">color</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="o">&</span><span class="n">n</span><span class="p">;);</span>
<span class="n">fscanf</span><span class="p">(</span><span class="n">in</span><span class="p">,</span><span class="s">"%s"</span><span class="p">,</span><span class="n">bead</span><span class="p">);</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="mi">2</span><span class="o">*</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">n</span><span class="p">];</span>
<span class="k">for</span><span class="p">(;</span><span class="n">i</span><span class="o"><</span><span class="mi">3</span><span class="o">*</span><span class="n">n</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">=</span><span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="n">n</span><span class="p">];</span>
<span class="k">for</span><span class="p">(</span><span class="n">breakpoint</span><span class="o">=</span><span class="n">n</span><span class="p">;</span><span class="n">breakpoint</span><span class="o"><=</span><span class="n">n</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span><span class="n">breakpoint</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">length1</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">point</span><span class="o">=</span><span class="n">breakpoint</span><span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">bead</span><span class="p">[</span><span class="n">point</span><span class="p">]</span><span class="o">==</span><span class="sc">'w'</span> <span class="o">&&</span> <span class="n">point</span><span class="o">>=</span><span class="mi">0</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">length1</span><span class="o">++</span><span class="p">;</span>
<span class="n">point</span><span class="o">--</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">color</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">bead</span><span class="p">[</span><span class="n">point</span><span class="p">];</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">point</span><span class="p">;</span><span class="n">i</span><span class="o">>=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o">--</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">==</span><span class="n">color</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">||</span> <span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">==</span><span class="sc">'w'</span><span class="p">)</span> <span class="n">length1</span><span class="o">++</span><span class="p">;</span>
<span class="k">else</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">length2</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span>
<span class="n">point</span><span class="o">=</span><span class="n">breakpoint</span><span class="p">;</span>
<span class="k">while</span> <span class="p">(</span><span class="n">bead</span><span class="p">[</span><span class="n">point</span><span class="p">]</span><span class="o">==</span><span class="sc">'w'</span> <span class="o">&&</span> <span class="n">point</span><span class="o"><=</span><span class="n">n</span><span class="o">*</span><span class="mi">3</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">length2</span><span class="o">++</span><span class="p">;</span>
<span class="n">point</span><span class="o">++</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">color</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">=</span><span class="n">bead</span><span class="p">[</span><span class="n">point</span><span class="p">];</span>
<span class="k">for</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">point</span><span class="p">;</span><span class="n">i</span><span class="o"><=</span><span class="n">n</span><span class="o">*</span><span class="mi">3</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">==</span><span class="n">color</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">||</span> <span class="n">bead</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">==</span><span class="sc">'w'</span><span class="p">)</span> <span class="n">length2</span><span class="o">++</span><span class="p">;</span>
<span class="k">else</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">length1</span><span class="o">+</span><span class="n">length2</span><span class="o">></span><span class="n">num</span><span class="p">)</span> <span class="n">num</span><span class="o">=</span><span class="n">length1</span><span class="o">+</span><span class="n">length2</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span><span class="o">></span><span class="n">n</span><span class="p">)</span> <span class="n">num</span><span class="o">=</span><span class="n">n</span><span class="p">;</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">out</span><span class="p">,</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="n">num</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">in</span><span class="p">);</span>
<span class="n">fclose</span><span class="p">(</span><span class="n">out</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
080420
2008-04-20T07:29:27+00:00
http://greenmooon55.com/080420
<p>好久没写东西了,转眼一个月又要过去了,现在事情真多。</p>
<p>昨天去查,Google又没<a href="http://www.google.com/search?&hl=zh-cn&q=site%3Agreenmoon55.com">收录</a>,<a href="http://wordpress.org.cn/thread-12328-1-1.html">去论坛问</a>也没什么答案。不经意间找偶爱偶家的“<a href="http://blog.2i2j.com/letter-t-graffiti/google-include-my-blog.html">google总算收录我的博客了</a>”,提到要有404页面,我就去找我的,结果用IE7、IE8都不显示,而FF正常。Google的机器人不是用一个文本浏览器吗?难道和IE一样不显示?记得春节时用IE7和其他模板能访问,我又换了一下模板,也不行。最后在WP官方论坛看到了一个<a href="http://wordpress.org/support/topic/139302">解决方案</a>:在404文件最上方添加:</p>
<blockquote>
<?php ob_start(); ?>
<?php header("HTTP/1.1 404 Not Found"); ?>
</blockquote>
<p>我只添加了第一句,2个都添加在我这里有问题,不过不知道第一句是什么意思,搜索了也没明白,以后学PHP再说吧。正常显示后,搜索的第一行字号太大,就这样吧。</p>
<p>刚才尝试登录FTP时提示530 Login authentication failed,应该是密码不正确,给KENSAI发消息了,等待解决。</p>
<p><a href="http://www.williamlong.info/archives/1311.html">ALEXA的算法更新了</a>,很多中文blog的排名都有所提高,我的排名终于出现了,是<a href="http://www.alexa.com/data/details/traffic_details/greenmoon55.com">7015947</a>。</p>
<p><del>下周会写IE8 Beta1和QQ拼音输入法的试用,QQ拼音输入法写了一部分,IE8 Beta1 上周运行出错,昨天才解决,却发现本blog首页显示不正常,详细内容以后再提。</del></p>
<p>_刚才谷歌拼音输入法打“对了”时居然出现的是“老了”,可惜没截图就被我把“老了”删了,看来不是自带的,但是打”dui”也找不到“老”啊。。。。_对了,以后不会输出美味书签的Daily Post了,想看的欢迎订阅Feedsky托管的<a href="http://feed.feedsky.com/greenmoon55">RSS</a>,上周我在Feedsky选每日输出美味书签时居然没想到美味书签就是del.icio.us。TW也推出<a href="http://www.theworld.cn">网页收藏夹</a>了,用作上传下载还可以,只是把收藏夹搬到了网上,希望以后能与TW菜单结合。不过TW这个的定位和del.icio.us不同,现在越来越觉得美味书签好用了。</p>
<p>真乱啊!就到这里吧。</p>
Facebook中文版本
2008-04-04T15:23:14+00:00
http://greenmooon55.com/facebook-translations-in-zh-cn
<p>早有<a href="http://www.melonlab.com/zh-cn-facebook-inspire-what/">传言</a>称<a href="http://www.facebook.com">Facebook</a>要退出简体中文版本,今天下午又在CB上看到<a href="http://www.cnbeta.com/articles/52459.htm">Facebook要靠志愿者翻译</a>,还说“一口气推出了22个新语言版本的网站。中文也位列其中”,找来的<a href="http://www.techcrunch.com/2008/03/31/facebook-gets-aggressive-on-translations-adding-22-more-languages/">英文原稿</a>是这样写的,只是开始翻译而已:</p>
<blockquote>
<p>They’re using their new user-powered <a href="http://www.techcrunch.com/2008/01/21/facebook-taps-users-to-create-translated-versions-of-site/">translation engine</a> to get Facebook into 22 more languages, on top of English, French, German and Spanish.</p>
</blockquote>
<p>目前网站的翻译只是刚刚开始,要想完成至少还得几个月。下面是统计数据:</p>
<blockquote>
<p>Total Translators: 122, Translations Submitted: 2,732, Untranslated Phrases: 17,620.</p>
</blockquote>
<p>我翻译了11条简单的 :D 。这个<a href="http://www.facebook.com/translations/">翻译</a>功能很多(注意下面的图片),不仅有简单的翻译功能、还有<a href="http://greenmoon55.com/facebook-translations-in-zh-cn/attachment/20080404223927796/">投票</a>、<a href="http://greenmoon55.com/facebook-translations-in-zh-cn/attachment/20080404232626140/">讨论</a>的功能,并且<a href="http://greenmoon55.com/facebook-translations-in-zh-cn/attachment/20080404230129171/">翻译时有建议</a>,总体来说感觉很方便。但是由于翻译的人不同,虽然有<a href="http://greenmoon55.com/facebook-translations-in-zh-cn/attachment/20080404224006718/">Style Guide</a>,还是会出现一词多译、标点符号不规范等问题。</p>
<p>虽然现在Facebook中的国人还很少,学校也不全(特别是高中),但以后应该能对国内这些SNS网站有冲击。我刚注册,初步感觉要比<a href="http://www.xiaonei.com">校内网</a>功能多,其实校内就是模仿Facebook的各个方面。</p>
<p>下面是本文的最重要部分:翻译页面的截图(点击可再次放大)</p>
<p>2008-07-26 11:14:16 被墙一段时间了,英文维基搜G/F/W现在都不会被墙。重新传一下图片</p>
<p>[gallery]</p>
WP升级到2.5
2008-03-30T12:18:34+00:00
http://greenmooon55.com/upgrading-to-wordpress-25
<p>昨天半夜(准确的说是今天),<a href="http://fanfou.com/statuses/SEz7bqCTIDk">我发现</a>WP2.5正式版<a href="http://wordpress.org/development/2008/03/wordpress-25-brecker/">放出来了</a>。刚才升级了,过程十分顺利。下面说一下(参考<a href="http://codex.wordpress.org/Upgrading_WordPress">http://codex.wordpress.org/Upgrading_WordPress</a>)。</p>
<ol>
<li>
<p>应该Deactive All Plugins,但是我忘了,结果没什么影响</p>
</li>
<li>
<p>备份数据库(用<a href="http://wordpress.org/extend/plugins/wp-dbmanager/">WP-DBManager</a>)和所有文件</p>
</li>
<li>
<p>删除原来的wp-includes和<code class="highlighter-rouge">wp-admin文件夹</code></p>
</li>
<li>
<p><code class="highlighter-rouge">上传新文件(不要覆盖wp-content文件夹,不用变)</code></p>
</li>
<li>
<p><code class="highlighter-rouge">到wp-admin/upgrade.php点几下按钮就行了</code></p>
</li>
</ol>
<p><code class="highlighter-rouge">我用的插件都没有兼容性问题。刚发现WP Grins好像不自动插入表情符号了。。 :(</code></p>
<p><code class="highlighter-rouge">感受:后台好看多了,写日志时编辑也快多了(比如插入链接),推荐升级,但事先一定做好备份。</code></p>
<p><code class="highlighter-rouge">下面是截图,用IE7不能插入。。只好用FF :D</code></p>
<p><code class="highlighter-rouge">[gallery]</code></p>
2008F1澳大利亚站-真乱啊
2008-03-16T09:50:12+00:00
http://greenmooon55.com/2008-f1-aus-gp
<p>好久没看F1了,昨天在QQ群里才知道本周就是澳大利亚站。看了排位的报道,对法拉利的速度感到失望,毕竟冬季测试时法拉利速度还是很快的。</p>
<p>看的是C5的直播,电视转播界面有新变化,比如在最下方显示暗的Classification(很多种)、显示车手照片、replay动画修改(觉得没以前的好),就是剩10几圈的时候突然什么都消失了(好像错误的提示了SC)。</p>
<p>各车队涂装也没什么大的改变,只是Honda的变的多一些,不像去年看雷诺的车那么不顺眼。</p>
<p>发车MAS就失误了,回去换前翼,结果下一圈又回去加油,真不知道是怎么想的,后来还退赛了。对于把DC撞出去,应该都是MAS的责任,车身还没超过DC就直接撞出去了。 :sad:</p>
<p>Kimi左侧软胎的白线很快就磨平了,第一圈趁乱超了不少,到第8,很不错。但是后来一直被Barrichello挡在后面。等了十多圈才尝试超车,下一圈就成功了,并很快拉开距离,两次安全车也帮了Kimi不少忙。不过Kimi第二次超科瓦莱宁时没刹住车(MAS刚退赛),马上回去加油换胎。回来超新人格洛克(Glock)时左后胎上草了,然后就失控了,不过没什么大碍。后来Glock过弯(好像是12号弯)时上草坪了,但是草坪不平,所以车就报废了。安全车有一次出动,不知怎么了,安全车回pit时,Kimi好像被超了,然后就被落下很远。引擎好像出问题了,声音不太对,后来又一次停在pit入口,第N次了。。。 :oops:</p>
<p>HAM真快啊,很像去年AUS的KIMI,一点没受安全车影响。</p>
<p>还有比较有趣的:</p>
<ol>
<li>
<p>Barrichello加油时棒棒糖人举牌早了,还没加完油呢!出去还是红灯,先罚停10s,赛后又宣布取消其成绩。</p>
</li>
<li>
<p>ALO和KOV的争斗:先是ALO乘其不备超过了KOV,KOV在倒数第二圈终于又反超了,不过在发车区直道时被ALO轻松超过,都没到第一弯,明显是KOV有问题。不知道怎么会这样超过去。找到原因了,按了Pit Lane 限速按钮。。。。。 Nothing is impossible :roll: :shock: <a href="http://www.eaf1.net/bbs/viewthread.php?tid=46894">http://www.eaf1.net/bbs/viewthread.php?tid=46894</a></p>
</li>
</ol>
<p>总结:乱得赶上去年加拿大了。难道法拉利还要像去年、前年那样后程发力?</p>
<p>推荐阅读:</p>
<blockquote>
<p>评论:墨尔本上演”大逃杀” 不怕慢就怕坚持不到底 <a href="http://sports.sina.com.cn/f1/2008-03-16/17113535835.shtml">http://sports.sina.com.cn/f1/2008-03-16/17113535835.shtml</a></p>
</blockquote>
<p>F1新季揭幕站仅七车完赛 汉密尔顿夺冠法拉利零分 <a href="http://sports.sina.com.cn/f1/2008-03-16/14093535652.shtml">http://sports.sina.com.cn/f1/2008-03-16/14093535652.shtml</a></p>
<p>Official Results <a href="http://www.formula1.com/results/season/2008/787/">http://www.formula1.com/results/season/2008/787/</a></p>
<p>下周是马来西亚雪邦(Sepang),F12006比赛时我最快好像是1:35。第一弯很险啊!</p>
<p>推荐:世界一级方程式锦标赛马来西亚站介绍及回顾[视频]:<a href="http://www.eaf1.net/bbs/viewthread.php?tid=37207">http://www.eaf1.net/bbs/viewthread.php?tid=37207</a></p>
NOIP2001普及组第一题
2008-03-16T07:54:50+00:00
http://greenmooon55.com/noip2001pj1
<p>题一 数的计算(20分)</p>
<p>问题描述</p>
<p>我们要求找出具有下列性质数的个数(包含输入的自然数n):</p>
<p>先输入一个自然数n(n<=1000),然后对此自然数按照如下方法进行处理:</p>
<p>1. 不作任何处理;</p>
<p>2. 在它的左边加上一个自然数,但 加上数后,继续按此规则进行处理,直到不能再加自然数为止.</p>
<p>样例: 输入: 6</p>
<p>满足条件的数为 6 (此部分不必输出)</p>
<p>16</p>
<p>26</p>
<p>126</p>
<p>36</p>
<p>136</p>
<p>输出: 6</p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">noippj20011</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">ans</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">1..1000</span><span class="p">]</span> <span class="k">of</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">n</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">readln</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">div</span> <span class="m">2</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:=</span> <span class="m">1</span><span class="p">;</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">i</span> <span class="k">div</span> <span class="m">2</span> <span class="k">do</span> <span class="k">inc</span><span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]);</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">ans</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="p">:=</span> <span class="m">1</span><span class="p">;</span>
<span class="k">for</span> <span class="n">j</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="n">n</span> <span class="k">div</span> <span class="m">2</span> <span class="k">do</span> <span class="k">inc</span><span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">n</span><span class="p">],</span> <span class="n">ans</span><span class="p">[</span><span class="n">j</span><span class="p">]);</span>
<span class="k">writeln</span><span class="p">(</span><span class="n">ans</span><span class="p">[</span><span class="n">n</span><span class="p">]);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
Qsort练习
2008-03-09T10:42:05+00:00
http://greenmooon55.com/qsort-practice
<p>好久不编了,连这种都有点不熟了。
PS:在这里发代码太费劲了。。 :evil:<!-- more --></p>
<div class="language-pascal highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">program</span> <span class="n">qsortpractice080309</span><span class="p">;</span>
<span class="k">type</span>
<span class="n">tbox</span> <span class="p">=</span> <span class="k">record</span>
<span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">var</span>
<span class="n">a</span><span class="p">:</span> <span class="k">array</span><span class="p">[</span><span class="m">1..10</span><span class="p">]</span> <span class="k">of</span> <span class="n">tbox</span><span class="p">;</span>
<span class="n">i</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="k">procedure</span> <span class="n">qsort</span><span class="p">(</span><span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">:</span> <span class="kt">longint</span><span class="p">);</span>
<span class="k">var</span>
<span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">:</span> <span class="kt">longint</span><span class="p">;</span>
<span class="n">n</span><span class="p">:</span> <span class="n">tbox</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">i</span> <span class="p">:=</span> <span class="n">left</span><span class="p">;</span>
<span class="n">j</span> <span class="p">:=</span> <span class="n">right</span><span class="p">;</span>
<span class="n">n</span> <span class="p">:=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">while</span> <span class="n">i</span> <span class="p"><</span> <span class="n">j</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="p"><</span> <span class="n">j</span><span class="p">)</span> <span class="k">and</span> <span class="p">((</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">].</span><span class="n">x</span> <span class="p">></span> <span class="n">n</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="k">or</span> <span class="p">((</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">].</span><span class="n">x</span> <span class="p">=</span> <span class="n">n</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">].</span><span class="n">y</span> <span class="p">>=</span> <span class="n">n</span><span class="p">.</span><span class="n">y</span><span class="p">)))</span> <span class="k">do</span> <span class="n">dec</span><span class="p">(</span><span class="n">j</span><span class="p">);</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:=</span> <span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">];</span>
<span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="p"><</span> <span class="n">j</span><span class="p">)</span> <span class="k">and</span> <span class="p">((</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="p"><</span> <span class="n">n</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="k">or</span> <span class="p">((</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span> <span class="p">=</span> <span class="n">n</span><span class="p">.</span><span class="n">x</span><span class="p">)</span> <span class="k">and</span> <span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span> <span class="p"><=</span> <span class="n">n</span><span class="p">.</span><span class="n">y</span><span class="p">)))</span> <span class="k">do</span> <span class="k">inc</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
<span class="n">a</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="p">:=</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="p">:=</span> <span class="n">n</span><span class="p">;</span>
<span class="k">if</span> <span class="n">i</span> <span class="p"><</span> <span class="n">right</span> <span class="k">then</span> <span class="n">qsort</span><span class="p">(</span><span class="n">i</span> <span class="p">+</span> <span class="m">1</span><span class="p">,</span> <span class="n">right</span><span class="p">);</span>
<span class="k">if</span> <span class="n">i</span> <span class="p">></span> <span class="n">left</span> <span class="k">then</span> <span class="n">qsort</span><span class="p">(</span><span class="n">left</span><span class="p">,</span> <span class="n">i</span> <span class="p">-</span> <span class="m">1</span><span class="p">);</span>
<span class="k">end</span><span class="p">;</span>
<span class="k">begin</span>
<span class="n">assign</span><span class="p">(</span><span class="n">input</span><span class="p">,</span> <span class="s">'qsort.in'</span><span class="p">);</span>
<span class="n">reset</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="m">10</span> <span class="k">do</span>
<span class="k">begin</span>
<span class="k">read</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">);</span>
<span class="n">readln</span><span class="p">;</span>
<span class="k">end</span><span class="p">;</span>
<span class="n">qsort</span><span class="p">(</span><span class="m">1</span><span class="p">,</span> <span class="m">10</span><span class="p">);</span>
<span class="k">for</span> <span class="n">i</span> <span class="p">:=</span> <span class="m">1</span> <span class="k">to</span> <span class="m">10</span> <span class="k">do</span> <span class="k">write</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">,</span> <span class="s">' '</span><span class="p">,</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">,</span> <span class="s">' '</span><span class="p">);</span>
<span class="n">close</span><span class="p">(</span><span class="n">input</span><span class="p">);</span>
<span class="k">end</span><span class="p">.</span>
</code></pre></div></div>
Delphi Formatter
2008-03-01T15:51:44+00:00
http://greenmooon55.com/delphi-formatter
<p>Introduction</p>
<blockquote>
<p>Delfor is a customizable source code formatter. It can improve the indentation, spacing, capitalization and the use of blank lines of Delphi 5.0 source code. To do so the source code is parsed and lots of special constructs are tested. At default, the style of the Borland source code is followed closely, since this is the most widely accepted style. But formatting of Pascal code is much a matter of taste and debate. Therefore, some alternative rules are included.</p>
</blockquote>
<p>DelFor is available as Delphi 2, Delphi 3, Delphi 4 or Delphi 5 expert. It can optionally process the whole currently opened project.</p>
<p>用途:</p>
<blockquote>
<p>写完代码之后复制到网页上就变样了?这是编码的问题,如果你常用Tab则很可能发生。这个工具可以把Tab字符转换为空格,这样复制后就和复制前是一样的。 :cool:</p>
</blockquote>
<p>这个工具还能美化语句,比如在”=”前后加空格,还支持批量转换,很实用。</p>
<p>界面展示:</p>
<p>下载:</p>
<p>如果你在阅读器中看到的文章显示不全,无法下载,请点击<a href="http://greenmoon55.com/delphi-formatter/">http://greenmoon55.com/delphi-formatter/</a> 查看完整版本。</p>
Yaris雅力士彩绘设计网络大赛火热揭幕
2008-03-01T11:34:03+00:00
http://greenmooon55.com/yaris-feedsky-ad
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/03/20080301183624453.png"></a><img src="http://review.feedsky.com/review/feedsky/greenmoon55/~/img/150/review.gif" alt="" /></p>
<p>介绍:</p>
<blockquote>
<p>广州丰田汽车有限公司即将在2008年推出丰田的全球三大战略车型之一:Yaris,中文名:雅力士。雅力士是为体现现代都市人时尚、个性和智慧而诞生的。为了让所有渴望展现自己个性和创意智慧的人们有一个充分发挥自我的舞台,广州丰田特举办此次<a href="http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/150/r.html">“智‘绘’我本色——Yaris雅力士彩绘设计网络大赛”</a>,并送出四部雅力士作为大赛的大奖!</p>
</blockquote>
<blockquote>
<ul>
<li>本次大赛为大家开放四个风格各异的地带供大家挥洒个性,它们分别是:
<strong>“炫动风潮”sporty</strong>——针对爱运动、爱大自然,还要极具运动感以及爱炫的超强表现力的你。
<strong>“都市魅影”urban</strong>——在大都市中来来去去,每个人都想与众不同,你的都市感觉是否够魅力、够锐利就赶快来参加。
<strong>“潮爆至上”fashion</strong>——只要你认为自己是个十足的潮人,你把爱车看作是最精锐的时尚战车,并认为你的作品能掀起时尚的浪潮,就请过来试一试。
<strong>“典雅风情”elegant</strong>——绅士还是淑女,只要你有本事让你的爱车和你一点一处都精致细腻,就让我们领略一下你的无限风情。相关链接:<a href="http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/150/r.html">智‘绘’我本色活动</a></li>
</ul>
</blockquote>
<p>个人测试:</p>
<blockquote>
<p>进入<a href="http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/150/r.html">http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/150/r.html</a> 后点击页面左侧的“<a href="http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/150/r.html">智‘绘’我本色</a>”即可进入活动主页,点击参加比赛就可以了。 :smile: 可以在线涂鸦,也可以线下完成。在线涂鸦功能不少,使用十分简便,右下角还有一些现成的元素,左上角可以看到多角度的实时预览,左下角还有Undo和Redo,可以随时撤销刚才的操作。看图吧: :mrgreen:</p>
</blockquote>
<p>(点击即可看大图!! 更多帮助:<a href="http://www.yarischina.com/painter/help/help.htm">www.yarischina.com/painter/help/help.htm</a> :roll: )</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/03/20080301183624453.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/03/20080301183624453.thumbnail.png" alt="20080301183624453.png" /></a></p>
<p>参赛帮助:</p>
<blockquote>
<p>第一步:注册成为yaris会员;
第二步:选择参赛方式,在线创作作品和提交线下作品;
在线作品创作
1:选择作品所属风格;
2:进行涂鸦创作;
3:保存作品,下次继续创作;
4:完成作品,填写作品相关信息,补充个人相关资料;
5:提交参加比赛;</p>
</blockquote>
<p>提交线下完成作品:
1:上传作品,选择作品风格;填写作品相关信息;
2:保存作品;
3:参加投稿;</p>
<p>奖励:</p>
<blockquote>
<p>一等奖4名:每人一部Yaris的十年使用权, 获奖者十年使用期满后可凭优惠价格购买。还有几百名参与者可获得其他奖励(如:车模等)</p>
</blockquote>
<p>我挑了几个不错的作品:</p>
<blockquote>
<p>奥运福娃(侵权?):</p>
</blockquote>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/03/20080301191948734.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/03/20080301191948734.png" alt="20080301191948734.png" /></a></p>
<p>花开富贵:</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/03/20080301192138578.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/03/20080301192138578.png" alt="20080301192138578.png" /></a></p>
<p>心动了吗?点击<a href="http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/150/r.html">http://review.feedsky.com/review/feedsky/greenmoon55/~/txt/150/r.html</a> 看看吧!或许你就是最幸运的。</p>
<p>感受:</p>
<p>这样的活动能够吸引很多人积极设计,从中能找到很多好作品,提高了品牌知名度,如果能真正在车上,还会实现会吸引很多人购买。这个创意不错。 :lol: </p>
Feedsky无法访问
2008-02-24T01:54:58+00:00
http://greenmooon55.com/unable-to-visit-feedsky
<p><a href="http://www.feedsky.com">Feedsky</a>首页无法访问,但是能ping通。</p>
<blockquote>
<p>Pinging www.feedsky.com [61.4.177.13] with 32 bytes of data:</p>
</blockquote>
<p>Reply from 61.4.177.13: bytes=32 time=43ms TTL=51
Reply from 61.4.177.13: bytes=32 time=44ms TTL=51
Reply from 61.4.177.13: bytes=32 time=44ms TTL=50
Reply from 61.4.177.13: bytes=32 time=43ms TTL=51</p>
<p>Ping statistics for 61.4.177.13:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 43ms, Maximum = 44ms, Average = 43ms</p>
<p>导致很多blog访问慢(在首页放了<a href="http://www.feedsky.com">Feedsky</a>的订阅图标),比如我的用<a href="http://www.microsoft.com/china/windows/products/winfamily/ie/default.mspx">IE7</a>就卡在那了。还是用自己的图片保险。</p>
<p>PS:Feedsky的订阅页(如:<a href="http://feed.feedsky.com/greenmoon55">http://feed.feedsky.com/greenmoon55</a>)可以正常访问。</p>
Disable Menu 0.3.1 Zh-CN Locale Released
2008-02-22T06:24:24+00:00
http://greenmooon55.com/disable-menu-031-zh-cn-locale-released
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/02/20080222142048562.png"></a>介绍:</p>
<p>(好像还没更新)
作者网站:<a href="http://www.genoetigt.de/site/projects/disablemenu">http://www.genoetigt.de/site/projects/disablemenu</a>
官方插件站:<a href="https://addons.mozilla.org/zh-CN/firefox/addon/3300">https://addons.mozilla.org/zh-CN/firefox/addon/3300</a></p>
<blockquote>
<p>来源:<a href="http://www.babelzilla.org/forum/index.php?showtopic=3932">http://www.babelzilla.org/forum/index.php?showtopic=3932</a>
<strong>disable menu - Ver. 0.3.1</strong>, Updated: 15/02/08 18:26
<strong>Creator: **Tobias Hommel
**Ext. Version: **0.3.1
**Extension is compatible to:</strong>
**Firefox: **1.5 - 3.0b3
**Included locales: **de-DE en-US nl-NL pl-PL pt-BR
**Description: **enables disabling the main menu.</p>
</blockquote>
<p>翻译说明:</p>
<ul>
<li>
<p>插件用途为隐藏主菜单,基本不需要配置</p>
</li>
<li>
<p>有的地方可能翻译不准确,尤其是“插件历史”,最近比较忙。<strong>欢迎指正</strong></p>
</li>
</ul>
<p>截图:</p>
<blockquote>
<p>设置:</p>
</blockquote>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/02/20080222135024937.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/02/20080222135024937.thumbnail.png" alt="20080222135024937.png" /></a></p>
<p>效果:</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/02/20080222142048562.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/02/20080222142048562.thumbnail.png" alt="20080222142048562.png" /></a></p>
<p>下载:</p>
<p>此版本仅包含中文(zh-CN)和英文(en-US)的语言文件,安装即可使用。</p>
<p>disablemenu-031-fx.xpi(15kB)</p>
<p>请到官方下载。 :)</p>
元宵节快乐
2008-02-21T04:43:44+00:00
http://greenmooon55.com/happy-2008-lantern-festival
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/02/20080221130759531.png"></a>元宵节快乐!过了今天就算过完年了。</p>
<p>把主题换成了<a href="http://www.underone.com/2008/01/30/theme-g7v2-final/">Underone G7 V2</a>,也改了一点。添了一些插件,还生成了<a href="http://greenmoon55.com/achieves/">Achieves</a>页面,<strike>但是还有问题,搜索页面、tags页面都和首页不一样</strike>。</p>
<p>推荐<a href="http://www.google.cn/rebang/msg">谷歌的元宵节短信</a>,验证码很快就收到了。这篇文章是用<a href="http://www.zoundryraven.com/">Zoundry Raven</a>生成的,<a href="http://greenmoon55.com/tag/windows-live-writer/">以前用Windows Live Writer</a>时间有问题。<a href="http://www.zoundryraven.com/">Zoundry Raven</a>功能很多,只是觉得选Tag比较麻烦。</p>
<p>Update @ 13:29: 不想用<a href="http://www.zoundryraven.com/">Zoundry Raven</a>了。。</p>
<p>发个图(右下角截图有问题。。):</p>
<p><a href="http://greenmoon55.com/wp-content/uploads/2008/02/200802211307595311.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/02/200802211307595311.thumbnail.png" alt="200802211307595311.png" /></a><a href="http://greenmoon55.com/wp-content/uploads/2008/02/20080221130759531.png"></a></p>
终于又能上网了
2008-02-16T05:26:40+00:00
http://greenmooon55.com/adsl-problem-solved
<p>四五天前突然电话和网络都不能用了,第二天一早就把电话修好了,但是ADSL Link灯还是不亮。后来又修了半天,把电话也修坏了,然后又修电话。。。。昨天又让我退钱,说修不好了。晕,邻居都没问题怎么就我有问题?今天终于修好了,是网通机器的问题。 :lol:</p>
<p>好几天没上网了,<a href="http://www.google.com/reader">Google Reader</a>中未读项目已经有将近700条了。正好今晚有<a href="http://www.racingf1leaguebyinternet.com/Paginas/Overall_standings.htm">F1比赛</a>,有<a href="http://www.google.com/search?hl=en&q=Nordschleife">北环Nordschliefe</a>(<a href="http://www.youtube.com/results?search_query=Nordschleife">Youtube</a>),太难了,突然发现“Cancelled”。 :(</p>
<p>刚才进<a href="https://mail.google.com">Gmail</a>,发现26封垃圾邮件。N年没这么多垃圾邮件了。5555555</p>
<p>Update @22:44:刚要进入<a href="http://www.google.com/search?hl=en&q=Nordschleife">北环Nordschliefe</a>RACE模式,结果在WARMUP中掉线了,再进去就是Game Closed. :( 不过KYALAMI,South Africa 30% RACE得第二,被第一套2圈。</p>
金山词霸2008个人版Beta试用
2008-02-08T02:26:16+00:00
http://greenmooon55.com/trying-out-kingsoft-powerword-2008-beta
<p>好多年没用金山词霸了。主要特点:无广告,取词速度比<a href="http://www.lingoes.cn">Lingoes</a>快(有时<a href="http://www.lingoes.cn">Lingoes</a>很慢),英英、英汉词典不太丰富,专业词典倒很多,有MSN式的隐藏菜单栏,甚至隐藏图标都一样。默认是鼠标直接取词,很烦,我改成CTRL+鼠标了。有各种颜色的皮肤,有升级模块,还支持代理。如果有<a href="http://www.lingoes.cn/zh/dictionary/index.html">Lingoes的词典</a>很多人都会用它。</p>
<p><a href="http://sl.iciba.com/cb08/">点此申请测试</a></p>
<p>用<a href="http://www.debugmode.com/wink/">Wink</a>做了界面演示(请看<a href="http://greenmoon55.com/?p=21">全文</a>),有点快,如果看不清就暂停一下吧。<a href="http://greenmoon55.com/wp-content/uploads/2008/02/powerword2008beta.swf">点此</a>在新窗口中观看,更清楚。</p>
<p>Update1 @ February10, 2008 – 12:50: 发现在<a href="http://www.mozillaonline.com/">FF</a>中flash遮住了sidebar,就用more分开了。</p>
<!-- more -->
雅虎全能搜索已经收录本blog
2008-02-07T12:56:33+00:00
http://greenmooon55.com/yahoo-cn-search-adds-this-blog
<p>雅虎全能搜索已经收录本blog(14个),链接是这个:<a href="http://www.yahoo.cn/s?p=greenmoon55&pid=hp&v=web">http://www.yahoo.cn/s?p=greenmoon55&pid=hp&v=web</a>,而向百度、Google提交都没收录,或许是用雅虎统计的原因吧。</p>
<p>是用<a href="http://indexed.webmasterhome.cn/?domain=greenmoon55.com">http://indexed.webmasterhome.cn/?domain=greenmoon55.com</a>搜到的,还看到百度、搜狗各有一个反向链接。</p>
<p>另外还找到一篇很实用的文章:<a href="http://www.helloxudan.net/2007/08/23/wordpress-excerpt-and-rss-full-text-solution.html">Wordpress首页摘要输出而RSS全文输出的解决方案</a>,一会试验一下 :D</p>
春节快乐
2008-02-06T12:34:03+00:00
http://greenmooon55.com/happy-2008-spring-festival
<p>下午看了会<a href="http://you.video.sina.com.cn/v/08chunwan.html">新浪博客的春晚</a>,还凑合,要是CCTV能这么办就好多了。今年的春晚好像还是没什么意思:(。PPLIVE的直播速度真慢,50K左右。我去找了节目单,不过有N多种。。:(</p>
<p>和<a href="http://bbs.ioage.com/en">TW英文论坛</a>上的一个越南同龄人聊了好久了,他什么都想知道。。。</p>
<p>感觉今年鞭炮似乎有点少。</p>
1小时前写的超级大乐透随机选号程序
2008-02-03T16:31:40+00:00
http://greenmooon55.com/superlotto-random-number-generator
<p>Google Code <a href="http://code.google.com/p/superlottorandomnumbergenerator/">http://code.google.com/p/superlottorandomnumbergenerator/</a></p>
<p>请下载<a href="http://greenmoon55.com/wp-content/uploads/2008/07/superlottov11.exe">superlottov1.1exe</a>。</p>
<p>Screenshot
<a href="http://greenmoon55.com/wp-content/uploads/2008/07/20080725202007812.png"><img src="http://greenmoon55.com/wp-content/uploads/2008/07/20080725202007812.png" alt="Screenshot" /></a></p>
<p>Changelog</p>
<blockquote>
<p>V1.1 08-07-25 19:12 <a href="http://greenmoon55.com/wp-content/uploads/2008/07/superlottov11.exe">superlottov1.1exe</a> <a href="http://greenmoon55.com/wp-content/uploads/2008/07/superlottov11.pas">superlottov1.1pas</a>
重写全部代码
修复前区后区范围问题
加上blog链接</p>
</blockquote>
<p>V1.0 08-02-04 <a href="http://greenmoon55.com/wp-content/uploads/2008/02/superlottov10.exe">exe</a> <a href="http://greenmoon55.com/wp-content/uploads/2008/02/superlottov10.pas">pas</a>
第一版</p>