Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

没有AC的兄弟们估计多半都是这个错误(见内)

Posted by Ontheline at 2009-02-24 11:19:35 on Problem 1065
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator