Finish Poj 3982

http://www.cnblogs.com/mobileliker/p/4095683.html