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

Re:一组比较BT的数据!

Posted by dooder_daodao at 2010-07-14 17:53:39 on Problem 1011
In Reply To:一组比较BT的数据! Posted by:winboycool at 2007-04-22 00:07:27
我的代码16MS AC 了,
可是为什么跑不动这组数据``````
求正解
#include<stdio.h>
#include<stdlib.h>
#define M 65
int stick[M];
bool mark[M];
int cmp(const void *a,const void *b)
{
	return *(int *)b-*(int *)a;
}
bool f(int k,int left,int l,int n)
{
	int i,pre,cur;
	if(n==1)
		return 1;
	if(left==0){
		n--;
		left=l;
	}
	pre=0;
	for(i=0;i<k;i++){
		if(mark[i])
			continue;
		if(stick[i]>left)
			continue;
		if(stick[i]==pre)
			continue;
		pre=stick[i];
		mark[i]=1;
		if(f(k,left-stick[i],l,n))
			return 1;
		mark[i]=0;
		if(stick[i]==left||left==l)
			break;
	}
	return 0;
}
int main()
{
	int n,sum,i,len;
	while(scanf("%d",&n),n){
		sum=0;
		for(i=0;i<n;i++){
			scanf("%d",stick+i);
			mark[i]=0;
			sum+=stick[i];
		}
		qsort(stick,n,sizeof(int),cmp);	
		for(i=stick[0];i<sum;i++){
			if(sum%i)
				continue;
			if(f(n,i,i,sum/i))
				break;
		}
		printf("%d\n",i);
	}		  
	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