﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-The Sun Also Rises-随笔分类-Algorithm</title><link>http://www.cppblog.com/FreePeter/category/6058.html</link><description>Algorithm, Mathematica, 计算机科学, C++, photography, Linux的讨论空间</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 15:40:22 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 15:40:22 GMT</pubDate><ttl>60</ttl><item><title>[Retrospect] Andrew Stankevich's Contest</title><link>http://www.cppblog.com/FreePeter/archive/2008/05/01/48607.html</link><dc:creator>FreePeter</dc:creator><author>FreePeter</author><pubDate>Thu, 01 May 2008 12:45:00 GMT</pubDate><guid>http://www.cppblog.com/FreePeter/archive/2008/05/01/48607.html</guid><wfw:comment>http://www.cppblog.com/FreePeter/comments/48607.html</wfw:comment><comments>http://www.cppblog.com/FreePeter/archive/2008/05/01/48607.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/FreePeter/comments/commentRss/48607.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/FreePeter/services/trackbacks/48607.html</trackback:ping><description><![CDATA[                  Retrospect only, some algorithms may be wrong...<br id="cyo30">
Warning : 剧透慎入...<br id="cyo31">
<br id="cyo32">
<strong id="cyo33">Andrew Stankevich's Contest #1</strong><br id="cyo34" style="font-weight: bold;">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2313" id="cyo35">Chinese Girls' Amusement</a><br id="cyo36">
推结论直接算<br id="cyo37">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2314" id="cyo38">Reactor Cooling</a><br id="cyo39">
有上下界的环形流<br id="cyo310">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2315" id="cyo311">New Year Bonus Grant</a><br id="cyo312">
经典的树形DP<br id="cyo313">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2316" id="cyo314">Matrix Multiplication</a><br id="cyo315">
化简一下推结论<br id="cyo316">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2317" id="cyo317">Nice Patterns Strike Back</a>&nbsp; (Recommend)<br id="cyo318">
状态压缩DP后用matrix来优化，或者用上次monthly时LK的方法。<br id="cyo319">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2318" id="cyo320">Get Out!</a> (Recommend)<br id="cyo321">
可以用那个生成环的基的DFS,类似japan那道题。<br id="cyo322">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2319" id="cyo323">Beautiful People</a><br id="cyo324">
最长虾米序列，8过稍微有个细节要想<br id="cyo325">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2320" id="cyo326">Cracking' RSA</a> (Recommend)<br id="cyo327">
求bool方程组的解数。。。也就是求下自由变量个数<br id="cyo328">
<br id="cyo329">
<br id="cyo330">
<strong id="cyo331">Andrew Stankevich's Contest #2<br id="cyo332">
</strong><a  href="http://acm.zju.edu.cn/show_problem.php?pid=2337" id="cyo333">Non Absorbing DFA</a><br id="cyo334">
记得是个很正常的DP。<br id="cyo335">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2338" id="cyo336">The Towers of Hanoi Revisited</a><br id="cyo337">
经典的n个塔的hanoi，记得要DP...<br id="cyo338">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2339" id="cyo339">Hyperhuffman</a><br id="cyo340">
就是huffman问题吧，已经排好序，可以O(n)的。<br id="cyo341">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2340" id="cyo342">Little Jumper</a> (Recommend)<br id="cyo343">
不错的物理题<br id="cyo344">
首先可以想象成两只青蛙一起从两边跳。<br id="cyo345">
主要问题就是计算给定一个v后的青蛙可达区间。<br id="cyo346">
取到最值只有3种情况：从上面擦过，从下面擦过，45度起跳（如果可以）<br id="cyo347">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2341" id="cyo348">Quantization Problem</a><br id="cyo349">
又是一个正常的DP...<br id="cyo350">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2342" id="cyo351">Roads</a><br id="cyo352">
经典问题了。<br id="cyo353">
生成树上的权值必定是减少，其他边上的权值必定增大，设其分别为ai, bj<br id="cyo354">
然后对任意一条不在生成树上的边，加入到生成树上形成一个环，然后这条边的权值应当&gt;=环上所有边的权值。<br id="cyo355">
然后我们可以列出一堆形如ai + bj &gt;= 一个正数的不等式。。。然后。。。km算法的标顶~~~<br id="cyo356">
详情可以看km算法的证明~~~<br id="cyo357">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2343" id="cyo358">Robbers</a><br id="cyo359">
首先令k[i] = m * x[i] / y，取下整，然后可能k[i]的和不到m，要增加一些k[i]，当然是，每次找增大后delta最小的~~~<br id="cyo360">
主要是，似乎可以用heap优化为O(nlogn)。。。<br id="cyo361">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2344" id="cyo362">Toral Tickets</a> (Recommended)<br id="cyo363">
比较神奇的Polya<br id="cyo364">
<br id="cyo365">
<strong id="cyo366">Andrew Stankevich's Contest #3<br id="cyo367">
</strong><a  href="http://acm.zju.edu.cn/show_problem.php?pid=2361" id="cyo368">Areas</a> (Recommended)<br id="cyo369">
我的做法是基于半平面交的，对每条直线，枚举使用它左边的半平面还是右边的半平面，最后如果是一个有限平面则返回。。。<br id="cyo370">注意搜索过程中当半平面被切空后就可以return，由于最后只有O(n^2)块，所以复杂度是O(n^4)的（使用O(n^2)的半平面交）<br id="cyo371">SGU上时限很宽，ZJU上这么做时间有点紧（我0.95s AC的-_-bbbbbbb）<br id="cyo372">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2362" id="cyo373">Beloved Sons</a><br id="cyo374">
按偏爱程度从大到小找增广路跑max_match就可以了。。。<br id="cyo375">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2363" id="cyo376">Strange Counter</a><br id="cyo377">
构造<br id="cyo378">
维护这么一个性质两个2之间至少有一个0。。。然后。。。讨论。。。<br id="cyo379">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2364" id="cyo380">Data Transmission</a> (In List)<br id="cyo381">
据说是预流 + 使劲优化...(by Lunarmony)<br id="cyo382">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2365" id="cyo383">Strong Defence</a><br id="cyo384">
嗯，首先颜色数不会超过任何一条路的长度是把。。。所以颜色数至多就是最短路的长度。<br id="cyo385">
然后我们跑dijstra的时候把边着上颜色就是了。。。<br id="cyo386">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2366" id="cyo387">Weird Dissimilarity</a><br id="cyo388">
经典的DP<br id="cyo389">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2367" id="cyo390">PL/Cool</a><br id="cyo391">
据说是模拟(from oibh)。。。<br id="cyo392">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2368" id="cyo393">Royal Federation</a> (In List)<br id="cyo394">
据说是构造, not AC yet.<br id="cyo395">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2369" id="cyo396">Two Cylinders</a><br id="cyo397">
写出积分式后romberg.<br id="cyo398">
<br id="cyo399">
<strong id="cyo3100">Andrew Stankevich's Contest #4<br id="cyo3101">
</strong><a  href="http://acm.zju.edu.cn/show_problem.php?pid=2559" id="cyo3102">The Smart Bomb</a><br id="cyo3103">
简单的推一下。<br id="cyo3104">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2560" id="cyo3105">I Just Called ...</a><br id="cyo3106">
模拟，要用Trie树。<br id="cyo3107">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2561" id="cyo3108">Order-Preserving Codes</a><br id="cyo3109">
模仿huffman那样，只是每次merge相邻的。<br id="cyo3110">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2562" id="cyo3111">More Divisors</a><br id="cyo3112">
经典的DP, f[i][j]用前i个素数得到j个约数的最小数。。。<br id="cyo3113">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2563" id="cyo3114">Long Dominoes</a><br id="cyo3115">
状态压缩DP<br id="cyo3116">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2564" id="cyo3117">The Magic Wheel</a><br id="cyo3118">
应该选择第一个点，然后寻找下一层的两个方向最近的都试一下就行了。O(N)<br id="cyo3119">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2565" id="cyo3120">Cracking SSH</a><br id="cyo3121">
DP...<br id="cyo3122">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2566" id="cyo3123">Periodic Tilings</a><br id="cyo3124">
好像某年final有类似的题。应该有结论的说。<br id="cyo3125">
Not AC yet<br id="cyo3126">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2567" id="cyo3127">Trade</a> (In List)<br id="cyo3128">
Not AC yet, 可以看看<br id="cyo3129">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2568" id="cyo3130">Counting Triangulations</a> (Recommended)<br id="cyo3131">
一道还算不错的DP题，8过题目描述好像有点不清我记得。<br id="cyo3132">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2569" id="cyo3133">Unfair Contest</a><br id="cyo3134">
搜索+模拟<br id="cyo3135">
<br id="cyo3136">
<br id="cyo3137">
<strong id="cyo3138">Andrew Stankevich's Contest #5</strong><br id="cyo3139" style="font-weight: bold;">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2587" id="cyo3140">Unique Attack</a> (Recommended)<br id="cyo3141">
判断最小割是否唯一的题，就是用两种方法构造是否一样。<br id="cyo3142">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2588" id="cyo3143">Burning Bridges</a><br id="cyo3144">
ms是很经典的用桥来作的题<br id="cyo3145">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2589" id="cyo3146">Circles</a><br id="cyo3147">
经典的平面图欧拉公式题<br id="cyo3148">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2590" id="cyo3149">Linear Programming Dual</a><br id="cyo3150">
好象是线性规划，Not AC yet<br id="cyo3151">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2591" id="cyo3152">DVD</a> (In List)<br id="cyo3153">
相当容易写错的DP题。<br id="cyo3154">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2592" id="cyo3155">Think Positive</a><br id="cyo3156">
记得可以O(n)扫描的。<br id="cyo3157">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2593" id="cyo3158">Ranking</a><br id="cyo3159">
麻烦的模拟题。<br id="cyo3160">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2594" id="cyo3161">Driving Straight</a><br id="cyo3162">
也是很经典的思路了，先DP(或曰BFS)。然后走一遍，在满足有解的前提下尽量往那个方向走。<br id="cyo3163">
<br id="cyo3164">
<strong id="cyo3165">Andrew Stankevich's Contest #6<br id="cyo3166">
</strong><a  href="http://acm.zju.edu.cn/show_problem.php?pid=2595" id="cyo3167">Ackerman's Function</a> (Recommended)<br id="cyo3168">
可以认为是找规律<br id="cyo3169">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2596" id="cyo3170">The Minimal Angle</a><br id="cyo3171">
记得要O(n)，取平均数还是什么都可以。<br id="cyo3172">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2597" id="cyo3173">Yellow Code</a><br id="cyo3174">
我记得还是比较容易YY一个构造的。。。<br id="cyo3175">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2598" id="cyo3176">Yet Another Digit</a><br id="cyo3177">
DP吧。<br id="cyo3178">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2599" id="cyo3179">Graduated Lexicographical Ordering</a> (In List)<br id="cyo3180">
类似于vietnam的那道题。。。相当麻烦。。。建议实现下。。。<br id="cyo3181">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2600" id="cyo3182">GSM</a><br id="cyo3183">
高精度开方题。或者打表～<br id="cyo3184">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2601" id="cyo3185">Warehouse Keeper</a> (In List)<br id="cyo3186">
KM,8过我记得容易T?<br id="cyo3187">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2602" id="cyo3188">Don't Go Left</a><br id="cyo3189">
记得又是一个状态机的BFS题<br id="cyo3190">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2603" id="cyo3191">Railroad Sort</a><br id="cyo3192">
很有意思的构造，大体思路是每经过一个station，留住后一半，放行前一半。。。n个正好给2^n个数排序。<br id="cyo3193">
<br id="cyo3194">
<strong id="cyo3195">Andrew Stankevich's Contest #7</strong><br id="cyo3196" style="font-weight: bold;">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2604" id="cyo3197">Little Brackets</a><br id="cyo3198">
经典的dp, NOI陨石的秘密简化版。。。<br id="cyo3199">
f[n][k] = n对括号，&lt;=k层<br id="cyo3200">
f[n][k] = sigma(f[m][k] * f[n - m - 1][k - 1])，输出f[n][k] - f[n][k - 1]<br id="cyo3201">
就是每次添加一整个括号块。<br id="cyo3202">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2605" id="cyo3203">Under Control</a> (In List)<br id="cyo3204">
转换坐标离散化吧<br id="cyo3205">
类似思路有道超级复杂版<a  href="http://acm.pku.edu.cn/JudgeOnline/problem?id=3248" id="cyo3206">Soldier</a><br id="cyo3207">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2606" id="cyo3208">Holidays</a> (In List)<br id="cyo3209">Not AC Yet<br id="cyo3210">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2607" id="cyo3211">Laboratory</a><br id="cyo3212">
记得列出式子调整下就行了。时限吓人的～<br id="cyo3213">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2608" id="cyo3214">Maps</a><br id="cyo3215">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2609" id="cyo3216">Crazy Painter</a><br id="cyo3217">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2610" id="cyo3218">Puzzle</a><br id="cyo3219">
没记错的话BFS一下吧。。。<br id="cyo3220">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2611" id="cyo3221">Quest</a><br id="cyo3222">
经典的状态压缩BFS，输方案有点麻烦。。。<br id="cyo3223">
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2612" id="cyo3224">Stable Sets</a><br id="cyo3225">
<br id="cyo3226">
<br id="cyo3227">
<br id="cyo3228">
<br id="cyo3229" style="font-weight: bold;"><img src ="http://www.cppblog.com/FreePeter/aggbug/48607.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/FreePeter/" target="_blank">FreePeter</a> 2008-05-01 20:45 <a href="http://www.cppblog.com/FreePeter/archive/2008/05/01/48607.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[Solution] Japan 2007</title><link>http://www.cppblog.com/FreePeter/archive/2008/05/01/48606.html</link><dc:creator>FreePeter</dc:creator><author>FreePeter</author><pubDate>Thu, 01 May 2008 12:25:00 GMT</pubDate><guid>http://www.cppblog.com/FreePeter/archive/2008/05/01/48606.html</guid><wfw:comment>http://www.cppblog.com/FreePeter/comments/48606.html</wfw:comment><comments>http://www.cppblog.com/FreePeter/archive/2008/05/01/48606.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/FreePeter/comments/commentRss/48606.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/FreePeter/services/trackbacks/48606.html</trackback:ping><description><![CDATA[            [Solution] Tokyo 2007<br id="vzoi0"><br id="vzoi1">And Then There Was One<br id="vzoi2">经典题，递推。<br id="vzoi3"><br id="vzoi4">Prime Gap<br id="vzoi5">简单题<br id="vzoi6"><br id="vzoi7">Minimal Backgammon<br id="vzoi8">DP<br id="vzoi9"><br id="vzoi10">Lowest Pyramid<br id="vzoi11">比较麻烦的题目，大体做法是枚举一个点，根据距离相等可以枚举另一个点（这些点很少了），然后确定下最后一个点，check.<br id="vzoi12"><br id="vzoi13">Geometric Map<br id="vzoi14">比较麻烦的预处理 + dijstra <br id="vzoi15"><br id="vzoi16">Slim Span<br id="vzoi17">经典问题了，按边大小排序，每次加一条边，如果形成环去掉环上最小的边。check<br id="vzoi18"><br id="vzoi19">The Morning after Halloween<br id="vzoi20">BFS，最后用A*过掉的。用max(当前位置到目标位置)估价<br id="vzoi21"><br id="vzoi22">Bug Hunt<br id="vzoi23">简单模拟<br id="vzoi24"><br id="vzoi25">Most Distant Point from the Sea<br id="vzoi26">可以用二分＋半平面交。<br id="vzoi27">但也可以想象所有边朝里面挤压，这样最后要么是两条边压到一起，要么三条边压成一个点。O(n^3)枚举。<br id="vzoi28"><br id="vzoi29">The Teacher's Side of Math<br id="vzoi30">注意到p,q都是质数，所以答案是0必须是所有其他项系数全为0，这样就可以解方程了。<br id="vzoi31">用long double + 最大主元法可以过。<br id="vzoi32"><br id="vzoi33">      <img src ="http://www.cppblog.com/FreePeter/aggbug/48606.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/FreePeter/" target="_blank">FreePeter</a> 2008-05-01 20:25 <a href="http://www.cppblog.com/FreePeter/archive/2008/05/01/48606.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[Solution] SWERC 2007 Southwestern Europe</title><link>http://www.cppblog.com/FreePeter/archive/2008/05/01/48605.html</link><dc:creator>FreePeter</dc:creator><author>FreePeter</author><pubDate>Thu, 01 May 2008 12:24:00 GMT</pubDate><guid>http://www.cppblog.com/FreePeter/archive/2008/05/01/48605.html</guid><wfw:comment>http://www.cppblog.com/FreePeter/comments/48605.html</wfw:comment><comments>http://www.cppblog.com/FreePeter/archive/2008/05/01/48605.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/FreePeter/comments/commentRss/48605.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/FreePeter/services/trackbacks/48605.html</trackback:ping><description><![CDATA[            [Solution] SWERC 2007 Southwestern Europe<br id="s_1y0">比较简单，有些题读题比较郁闷。<br id="s_1y1"><br id="s_1y2"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3981" id="s_1y3" class="g">BEATBIT</a><br id="s_1y4">两DFA是否同构，bfs or 判断树是否同构都可以（因为保证了可以终止所以没有环存在）<br id="s_1y5"><br id="s_1y6"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3982" id="s_1y7" class="g">Prester John</a><br id="s_1y8">题意没说清，走路的方式类似于NFA, BFS就行了。<br id="s_1y9">不过可以出个数据让所有程序T...<br id="s_1y10"><br id="s_1y11"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3983" id="s_1y12" class="g">Robotruck</a><br id="s_1y13">O(N*C)的DP<br id="s_1y14"><br id="s_1y15"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3984" id="s_1y16" class="g">Jumping Hero</a><br id="s_1y17">BFS，最多300 * 300 * 5000 * 5种状态，当然实际上远远不到。<br id="s_1y18"><br id="s_1y19"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3985" id="s_1y20" class="g">Board Game</a><br id="s_1y21">Bellman-Ford<br id="s_1y22"><br id="s_1y23"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3986" id="s_1y24" class="g">The Bridges of Kolsberg</a><br id="s_1y25">经典DP<br id="s_1y26"><br id="s_1y27"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3987" id="s_1y28" class="g">The Finest Chef</a><br id="s_1y29">最优权匹配<br id="s_1y30"><br id="s_1y31"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3988" id="s_1y32" class="g">IP-TV</a><br id="s_1y33">MST<br id="s_1y34"><br id="s_1y35"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3989" id="s_1y36" class="g">Ladies' Choice</a><br id="s_1y37">稳定婚姻<br id="s_1y38"><img src ="http://www.cppblog.com/FreePeter/aggbug/48605.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/FreePeter/" target="_blank">FreePeter</a> 2008-05-01 20:24 <a href="http://www.cppblog.com/FreePeter/archive/2008/05/01/48605.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[Solution] Dhaka 2007</title><link>http://www.cppblog.com/FreePeter/archive/2008/05/01/48604.html</link><dc:creator>FreePeter</dc:creator><author>FreePeter</author><pubDate>Thu, 01 May 2008 12:22:00 GMT</pubDate><guid>http://www.cppblog.com/FreePeter/archive/2008/05/01/48604.html</guid><wfw:comment>http://www.cppblog.com/FreePeter/comments/48604.html</wfw:comment><comments>http://www.cppblog.com/FreePeter/archive/2008/05/01/48604.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/FreePeter/comments/commentRss/48604.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/FreePeter/services/trackbacks/48604.html</trackback:ping><description><![CDATA[<p class="MsoNormal"><span lang="EN-US">[Solution] Dhaka 2007<br>
<br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4055">Bachelor
Arithmetic</a><br>
</span><span style="font-family: 宋体;">秒杀题</span><span lang="EN-US"><br>
<br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4056">Nested
Squares</a><br>
</span><span style="font-family: 宋体;">模拟题</span><span lang="EN-US"><br>
<br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4057">The
Dumb Grocer</a><br>
</span><span style="font-family: 宋体;">首先要有</span><span lang="EN-US">1</span><span style="font-family: 宋体;">是吧。。。然后我们按照</span><span lang="EN-US">1</span><span style="font-family: 宋体;">的个数来分类，我们来计算恰有</span><span lang="EN-US">k</span><span style="font-family: 宋体;">个</span><span lang="EN-US">1</span><span style="font-family: 宋体;">的方案数。</span><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">我们在</span><span lang="EN-US">k</span><span style="font-family: 宋体;">个</span><span lang="EN-US">1</span><span style="font-family: 宋体;">的基础上加入新的数，显然第一个数只能是</span><span lang="EN-US">k+1<br>
</span><span style="font-family: 宋体;">然后加入的数只能是</span><span lang="EN-US">k + 1
or 2 * (k + 1)<br>
</span><span style="font-family: 宋体;">如法炮制。。。发现非</span><span lang="EN-US">1</span><span style="font-family: 宋体;">的数都具有</span><span lang="EN-US">(k + 1) * t</span><span style="font-family: 宋体;">的形式。。。设其依次为</span><span lang="EN-US">(k + 1) * ti<br>
</span><span style="font-family: 宋体;">则</span><span lang="EN-US">{ti}</span><span style="font-family: 宋体;">这些数也满足题目的性质。。。共有</span><span lang="EN-US">f((n - k) / (k + 1))</span><span style="font-family: 宋体;">种方案。</span><span lang="EN-US"><br>
<br>
</span><span style="font-family: 宋体;">设</span><span lang="EN-US">f(n)</span><span style="font-family: 宋体;">是要求的函数，则</span><span lang="EN-US">f(n) = sigma(f((n - k) / (k
+ 1)), (k + 1) | (n + 1) , k&gt;=<st1:chmetcnv tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="1" unitname="F" w:st="on">1<br>
</st1:chmetcnv>f(0) = 1<br>
</span><span style="font-family: 宋体;">这样直接做会</span><span lang="EN-US">T...<br>
</span><span style="font-family: 宋体;">我们令</span><span lang="EN-US">g(n) = f(n
- 1)<br>
</span><span style="font-family: 宋体;">则</span><span lang="EN-US">g(n) = f(n -
1) = sigma(f((n - k - 1) / (k + 1))) = sigma(f(n / (k + 1) - 1)) = sigma(g(n /
(k + 1)), (k + 1) | n, k &gt;= 1<br>
</span><span style="font-family: 宋体;">设</span><span lang="EN-US">n = p1^a1 *
p2^a2 * ... * pr*ar<br>
</span><span style="font-family: 宋体;">令</span><span lang="EN-US">h(p1, p2,..,
pr, a1, a2...ar) = g(n)<br>
= h(p1,p2, ...pr, b1, b2, ...br), <br>
0&lt;=bi &lt;= ai, bi</span><span style="font-family: 宋体;">不全</span><span lang="EN-US">=ai<br>
</span><span style="font-family: 宋体;">注意对于一个确定的</span><span lang="EN-US">n</span><span style="font-family: 宋体;">，</span><span lang="EN-US">h()</span><span style="font-family: 宋体;">中的</span><span lang="EN-US">p1, p2...pr</span><span style="font-family: 宋体;">在计算过程中始终不变。。。所以。。。<strong>计算结果与</strong></span><strong><span lang="EN-US">pi</span></strong><strong><span style="font-family: 宋体;">无关</span><span lang="EN-US">,</span></strong><strong><span style="font-family: 宋体;">只与</span><span lang="EN-US">ai</span></strong><strong><span style="font-family: 宋体;">有关</span></strong><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">这样状态数就大大减少了。。。直接因式分解后</span><span lang="EN-US">dp</span><span style="font-family: 宋体;">就行了。。。</span><span lang="EN-US"><br>
<br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4058">ACM
Puzzles</a><br>
</span><span style="font-family: 宋体;">状态压缩</span><span lang="EN-US">dp</span></p>
<p class="MsoNormal"><span lang="EN-US"><br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4059">Inspector's
Dilemma</a></span><span style="font-family: 宋体;">、</span><span lang="EN-US"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4060">The
Bells are Ringing</a></span><span style="font-family: 宋体;">、</span> <span lang="EN-US"><a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4061">Photographic
Tour</a><br>
</span><span style="font-family: 宋体;">这三题好像当时没写</span><span lang="EN-US">summary</span><span style="font-family: 宋体;">。。。所以我们假设比较简单～～～</span></p>
<p class="MsoNormal"><span lang="EN-US"><br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4062">You
are around me ...</a><br>
</span><span style="font-family: 宋体;">首先旋转坐标，变成平行与</span><span lang="EN-US">xy</span><span style="font-family: 宋体;">轴的椭圆，然后坐标伸缩。。。变成圆。。。最近点对。。。贴模板。。。</span><span lang="EN-US"><br>
<a  href="http://acm.zju.edu.cn/show_problem.php?pid=2107">ZJU2107 Quoit Design</a>
</span><span style="font-family: 宋体;">一道测最近点对的题。</span></p>
<p class="MsoNormal"><span lang="EN-US"><br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4063">Infinite
Matrix</a><br>
</span><span style="font-family: 宋体;">显然，对于固定的</span><span lang="EN-US">j, Ri,
j</span><span style="font-family: 宋体;">是一个关于</span><span lang="EN-US">i</span><span style="font-family: 宋体;">的多项式。</span><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">注意到数列</span><span lang="EN-US">Ri, j</span><span style="font-family: 宋体;">的差分序列</span><span lang="EN-US">R(i + 1, j) - R(i, j)</span><span style="font-family: 宋体;">是可以求出来的（利用</span><span lang="EN-US">Mj, k &lt;= 10</span><span style="font-family: 宋体;">的条件，可以在</span><span lang="EN-US">O(10*n^2)</span><span style="font-family: 宋体;">的时间内算出）</span><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">然后有了差分序列求通项就是</span><span lang="EN-US">O(n^2)</span><span style="font-family: 宋体;">的事情。</span><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">然后记</span><span lang="EN-US">S(p, j)(n)
= Sigma(i^p * R(i, j)) i &lt;= n<br>
</span><span style="font-family: 宋体;">继续利用差分序列之类的方法求这个，最后再求一个</span><span lang="EN-US">Sum_S(p, j)<br>
</span><span style="font-family: 宋体;">预处理复杂度大致是</span><span lang="EN-US">O(10*n^3)</span><span style="font-family: 宋体;">的。</span><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">后面的就好办了，对每个询问，把</span><span lang="EN-US">(i + 1)^p</span><span style="font-family: 宋体;">二项式展开，最多</span><span lang="EN-US">10</span><span style="font-family: 宋体;">项，然后利用公式直接计算。</span><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">处理询问复杂度</span><span lang="EN-US">O(p*q*n)<br>
POJ3529 <a  href="http://acm.pku.edu.cn/JudgeOnline/problem?id=3529">Matrix
Analysis</a></span><span style="font-family: 宋体;">，类似的思想，更简单～</span><span lang="EN-US"><br>
<br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4064">Magnetic
Train Tracks</a><br>
</span><span style="font-family: 宋体;">给定</span><span lang="EN-US">n</span><span style="font-family: 宋体;">个点，求可以构成多少个锐角三角形。</span><span lang="EN-US"><br>
n &lt;= 1200<br>
</span><span style="font-family: 宋体;">话说求锐角三角形不太好算是吧。。。补集转换，我们来求钝角</span><span lang="EN-US">/</span><span style="font-family: 宋体;">直角三角形</span><span lang="EN-US">
&lt;=&gt; </span><span style="font-family: 宋体;">求钝角</span><span lang="EN-US">/</span><span style="font-family: 宋体;">直角个数。。。</span><span lang="EN-US"><br>
</span><span style="font-family: 宋体;">后面的事情就简单了，是对每个点，将其他点按照极角排序</span><span lang="EN-US"> + </span><span style="font-family: 宋体;">扫描。</span><span lang="EN-US"><br>
<a  href="http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3295">Dhaka
2005 Counting Triangles</a> </span><span style="font-family: 宋体;">也是一道补集转换的题～（转化成求三点共线的个数）</span><span lang="EN-US"><br>
<a  href="http://acm.pku.edu.cn/JudgeOnline/problem?id=2280">Shanghai 2004
Amphiphilic Carbon Molecules</a> </span><span style="font-family: 宋体;">也是一道极角排序</span><span lang="EN-US">+</span><span style="font-family: 宋体;">扫描的题。</span><span lang="EN-US"><br>
<!--[if !supportLineBreakNewLine]--><br>
<!--[endif]--></span></p><img src ="http://www.cppblog.com/FreePeter/aggbug/48604.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/FreePeter/" target="_blank">FreePeter</a> 2008-05-01 20:22 <a href="http://www.cppblog.com/FreePeter/archive/2008/05/01/48604.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>TCO Round1, [500], CHOMP Game...</title><link>http://www.cppblog.com/FreePeter/archive/2008/02/17/Chomp_Game.html</link><dc:creator>FreePeter</dc:creator><author>FreePeter</author><pubDate>Sat, 16 Feb 2008 20:15:00 GMT</pubDate><guid>http://www.cppblog.com/FreePeter/archive/2008/02/17/Chomp_Game.html</guid><wfw:comment>http://www.cppblog.com/FreePeter/comments/42825.html</wfw:comment><comments>http://www.cppblog.com/FreePeter/archive/2008/02/17/Chomp_Game.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/FreePeter/comments/commentRss/42825.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/FreePeter/services/trackbacks/42825.html</trackback:ping><description><![CDATA[500分的题。。。<br>由于之前看到过chomp game，(《Game Theory》的练习里有)，然后开始试图推公式之类的。。。在wiki上找到rectangle情况先手必胜的证明：
<br>
<p>Who wins?</p>
<p>Chomp belongs to the category of impartial 2-player perfect information games.</p>
<p>It turns out that for any rectangular starting position bigger than 1 &#215; 1 the 1st player can win. This can be shown using a strategy-stealing argument:
assume that the 2nd player has a winning strategy against any initial
1st player move. Suppose then, that the 1st player takes only the
bottom right hand square. By our assumption, the 2nd player has a
response to this which will force victory. But if such a winning
response exists, the 1st player could have played it as his first move
and thus forced victory. The 2nd player therefore cannot have a winning
strategy.</p>
<p>Computers can easily calculate winning moves for this game on two-dimensional boards of reasonable size.</p>
<br>很优美的证明。。。只可惜不能提供任何strategy...-_-bbbbbbbb<br>最后终于悟出来这题规定棋盘3*n, n&lt;=100,所以就100*100*100的dp就行了。。-_-bbbbbbbbbb<br><br><br>p.s. <a title="wiki : chomp game" href="http://en.wikipedia.org/wiki/Chomp">wiki : Chomp Game</a><br><br><br>p.s. 确实觉得一知半解是一个很容易出错的情况...因为如果完全不知道思维也就没有任何限制了,曾经看到过么...感觉会有点紧张(想要赶紧搞掉的那种感觉) &amp; 试图用记忆中的套路去做...但有时候可能没有关系(例如这个game, 先手必胜的证明并不能提供任何先手如何operate的信息...,如果继续往这个上面想就直接挂了...-_-bbbbbbb)<br>还有就是有可能会出现类似于"当时为什么不仔细推清楚"之类的念头...这个seems容易解决...<br><br>感觉如果是完全陌生的题想法通常容易比较open, 如果感觉这个模型熟悉一般都会试图往熟悉的模型上套...大多数情况下这样确实可以节省时间...但是如果失去了open的思维 + 熟悉的模型无法解决就orz了...<br><br><br> <img src ="http://www.cppblog.com/FreePeter/aggbug/42825.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/FreePeter/" target="_blank">FreePeter</a> 2008-02-17 04:15 <a href="http://www.cppblog.com/FreePeter/archive/2008/02/17/Chomp_Game.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>