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

why?

Posted by mountainhigh at 2011-05-18 08:58:58 on Problem 2392
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int f[40010];
struct len
{
	int h_i,a_i,c_i;
}stick[410];
bool cmp(len t1,len t2)
{
	return t2.a_i>=t1.a_i;
}
void zeropack(int x,int h)
{
	int i,a;
	a=stick[x].a_i;
	for(i=a;i>=h;i--)
		if(f[i]<f[i-h]+h)
			f[i]=f[i-h]+h;
}
void multiplepack(int x)
{
	int i,j,a,h,c;
	a=stick[x].a_i;
	h=stick[x].h_i;
	c=stick[x].c_i;
	if(c*h>=a)
	{
		for(i=h;i<=a;i++)
			if(f[i]<f[i-h]+h)
				f[i]=f[i-h]+h;
	}
	else 
	{
		if(c==1)
		{
			for(i=a;i>=h;i--)
			if(f[i]<f[i-h]+h)
				f[i]=f[i-h]+h;
		}
		else
		{
			int k=1;
			while(k<c)
			{
				zeropack(x,k*stick[x].h_i);
				c=c-k;
				k=k*2;
			}
			zeropack(x,c*stick[x].h_i);
		}
	}
}
int main()
{
	int i,j,k;
	memset(f,0,sizeof(f));
	cin>>k;
	for(i=0;i<k;i++)
	cin>>stick[i].h_i>>stick[i].a_i>>stick[i].c_i;
	sort(stick,stick+k,cmp);
	for(i=0;i<k;i++)
	{
		multiplepack(i);
	}
	//这样的输出格式就对
	int now=0;
	for(i=0;i<=stick[k-1].a_i;i++)
	if(f[i]>now)now=f[i];
	printf("%d\n",now);
	//而这样的输出就错
	/*
	for(i=stick[k-1].a_i;i>0;i--)
	{
		if(f[i]!=0)
		{
		    cout<<f[i]<<endl;
			break;
		}
	}
	if(i==0)cout<<0<<endl;*/
	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