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

无语了,测试数据也都过了,为什么还WA呢?真理难寻呀

Posted by mountainhigh at 2011-04-29 09:55:46 on Problem 1014 and last updated at 2011-04-29 10:13:10
#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
int co[9],num;
bool flag[120010],cnt[120010];
void package(int i)
{
	int p,q;
	if(co[i]==1)
	{
		for(p=num;p>=i;p--)
	        if(!flag[p]&&flag[p-i])flag[p]=true;
	}
	else if(co[i]!=1&&i*co[i]>=num)  
	{
			for(p=i;p<=num;p++)
		        if(flag[p-i]&&(!flag[p])) flag[p]=true;
	}
	else if(co[i]!=1&&i*co[i]<num)
	{
		memset(cnt,0,sizeof(cnt));
		for(p=i;p<=num;p++)
		{
			if(!flag[p]&&flag[p-i]&&cnt[p-i]<co[i])
			{
				flag[p]=true;
				cnt[p]=cnt[p-i]+1;
			}
		}
	}
}
int main()
{
	int i,j,ti=1;
	while(scanf("%d%d%d%d%d%d",&co[1],&co[2],&co[3],&co[4],&co[5],&co[6])==6)
	{
		if(!(co[1]+co[2]+co[3]+co[4]+co[5]+co[6]))break;
		num=co[1]+2*co[2]+3*co[3]+4*co[4]+5*co[5]+6*co[6];
		if(num%2!=0)
		{
			cout<<"Collection #"<<ti++<<':'<<endl;
			cout<<"Can't be divided."<<endl<<endl;
		}
		else
		{
			num=num/2;
			memset(flag,false,sizeof(flag));
			flag[0]=true;
			for(i=1;i<=6;i++)
			    if(co[i]!=0)
			       package(i);
		    if(flag[num])
		    {
			    cout<<"Collection #"<<ti++<<':'<<endl;
			    cout<<"Can be divided."<<endl<<endl;
		    }
			else
			{
				cout<<"Collection #"<<ti++<<':'<<endl;
			    cout<<"Can't be divided."<<endl<<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