用了暴力解法,果断超时,上网一搜,哇!!!

发现了解题神法:

这有详细解释:http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=11661&messageid=1&deep=0

想不懂的去看看吧!

直接贴代码;