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 |
没有AC的兄弟们估计多半都是这个错误(见内)1.首先给大家一组测试用例: 7 9 48 29 2 26 42 9 35 4 25 45 16 26 21 AC的代码答案是3 我开始错误的代码是4. 2.分析:错误来自于对关键字排序,当两根Stick的第一关键字相等的时候必须按照第二关键字的升序排列,至于你如何安排自己的关键字无所谓, 错误代码: int cmp(const void* a1,const void* a2) { return (((sticks*)a1)->length-((sticks*)a2)->length);//只考虑了第一关键字 } 正确代码如下: int cmp(sticks a,sticks b) { if (a.length==b.length) { return a.weight<b.weight; } else { return a.length<b.length; } } 希望对各位有所帮助,最近身体不舒服,希望大家刷题之余多多锻炼身体:) Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator