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)...N是输入的牛长度的数目...sort(len, len + n); int res = 0; int pos = n - 1; int current = 0; while(pos > current) { if(len[pos] + len[current] <= s) { res += pos - current; ++current; } else --pos; } printf("%d", res); Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator