Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
其实很水的,直接排个序就可以O(n)解决了。原因:a1<=a2<=a3<=a4<=a5<=.....an; 对于a1,从序列an开始递减查找,找到第一个aj+a1<=S的话,那么ans+=j-1,跳出。 对于a2,则只要从序列aj开始递减查找就可以了。 ...... 当j>i的情况下,按照上面的方式查找,每次ans+=j-i即可。 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator