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

1065 帮我看看哪错了。谢啦

Posted by a7060108 at 2007-11-02 19:19:25 on Problem 1065
我的思路是对len排序(递减),然后从stick[0]往下找,la表示最少能组成几列。先把stick[0]存在a[0],la=1,如果下一个比它小就替换它。否则放在a[1]。这样的话,a[]是递增的。搜索每个stick[i],如果它比a[]中的小,就替换最小的那个比它大的中。如果比a[]大的话就加到a[]中,然后la加1。算出来的过不了。然后先对weight排序,算出来的过了。。然后两种都算了,取较大的一个居然过了。。。。照理来说应该是取较小的一个阿.
或者可能是我的实现出错了。不过我看了半天没看出来。帮帮忙吧。谢谢啦!
#include<iostream>
using namespace std;

struct info
{
	int len,weight; 	
}stick[5010];

void judge(int m)
{
	int i,a[5010],la=1,j;
	a[0]=stick[0].weight;
	for(i=1;i<m;i++)
	{
		for(j=0;j<la;j++)
			if(stick[i].weight<=a[j]){ a[j]=stick[i].weight;break;}
			if(j==la) { a[j]=stick[i].weight;la++;}
	}
	cout<<la<<endl;
}

int main()
{
	int i=0,j,n,m,k,temp;
	cin>>n;
	while(i<n)
	{
		i++;
		cin>>m;
		for(j=0;j<m;j++)
			cin>>stick[j].len>>stick[j].weight;
		for(j=0;j<m-1;j++)
			for(k=0;k<m-1-j;k++)
				if(stick[k].len<stick[k+1].len)
				{
					temp=stick[k].len;
					stick[k].len=stick[k+1].len;
					stick[k+1].len=temp;
					temp=stick[k].weight;
					stick[k].weight=stick[k+1].weight;
					stick[k+1].weight=temp;
				}
		judge(m);
	}
	return 0;
}


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