This problem is in Contest(s) below:
Contest 1241:ACM训练题(一)
Contest 1267:ACM训练题(一)大二