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

竟然1A了,代码……

Posted by ly50247 at 2009-07-25 22:14:16 on Problem 1416
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <queue>
using namespace std;

int l, r;
int rn[8];
int value[8];
int final[8];
int rk = 0;
int maxn = 0;

int maxnn = 0;
void dfs(int k, int in)
{
	if (k > l)
		return;
	if (in == rk)
	{
		if (maxn < k)
		{
			maxnn = 0;
			maxn = k;
			memcpy(final, value, sizeof(final));
		}
		else if(maxn == k)
		{
			maxnn++;
		}
	}
	for (int i=in; i < rk; i++)
	{
		for (int j=1; j <= value[i-1] * 10; j+=value[i-1] * 10-1)
		{
			value[i] = j;
			dfs(k+rn[i]*j, i+1);
			value[i] = 0;
		}
	}
	
}
	
	
int main()
{
	while (scanf("%d%d", &l, &r), l||r)
	{
		int suml = 0;
		int t = r;
		rk = 0;
		while (t > 0)
		{
			rn[rk++] = t%10;
			suml += rn[rk-1];
			t /= 10;
		}
		if (suml > l)
		{
			printf("error\n");
			continue;
		}
		maxn = 0;
		value[0] = 1;


		dfs(rn[0], 1);
		

		if (maxnn > 0)
			printf("rejected\n");
		else
		{
			printf("%d ", maxn);
			for (int i=rk-1; i >=0; i--)
			{
				printf("%d", rn[i]);
				if (final[i] == 1)
					printf(" ");
			}
			printf("\n");
		}
	}
	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