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了N次 可是试了discuss中所有数据都没问题 大牛路过帮忙看下··

Posted by frannie at 2009-05-12 22:01:54 on Problem 1014
不胜感激啊·····

#include <iostream>
using namespace std;

int marbles[6];

void check(int ave)
{
	int i,j;
	int temp = 0;
	for(i = 5; i >= 0; i--)
	{
		if(marbles[i] == 0)
			continue;
		temp += marbles[i] * (i+1);   
		if(temp == ave)
			break;
		else if(temp > ave)   //主要处理大于平均值的情况
		{
			temp -= marbles[i] * (i+1);
			if(marbles[i] == 1)       //只有一个值的话就不用处理了
				continue;
			else
			{
				for(j = marbles[i] - 1; j >= 0; j--)
				{
                                        //每次减少一个,测试是否满足条件
					temp += j * (i+1);
					if(temp == ave)
						break;
					if(temp > ave)
						temp -= j * (i+1);
				}
			}
		}
		else
			continue;
	}
	if(temp == ave)
		cout<<"Can be divided."<<endl<<endl;
	else
		cout<<"Can't be divided."<<endl<<endl;
}
int main()
{
	int i,j,count = 0;
	int sum;
	while(1)
	{
		count++;
		sum = 0;
		j = 0;
		for(i=0; i<6; i++)
		{
			cin>>marbles[i];	 
			sum += marbles[i] * (i+1);
			if(marbles[i] == 0)
				j++;
		}
		if(j == 6)
			break;
		cout<<"Collection #"<<count<<":"<<endl;
		if(sum%2 == 0)
			check(sum/2);
		else
			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