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

大家帮忙看看啊!!救命啊!

Posted by AlbertTry at 2009-12-11 16:25:11 on Problem 1020
这道题为什么总是WA啊?检查了一下午,网上的数据都过了,还是WA。快要崩溃了。
有谁还有测试数据没啊?我实在找不出哪里错了
救命啊!
救命啊!
#include<iostream>
using namespace std;
int cake[11] , hang[50] , cs , size , n ;
bool ok;
void checkPut()
{
	if(n==0)	{ok=true;exit;}
	int i=0 , j=0  , pos , w=0 , h=0 , tp=0, minh=1024;
	for(i=0;i<size;++i)	if(hang[i]<minh) { minh=hang[i], pos=i;	}	// 找到hang[i]最小的那一列。
	while(hang[pos+w]==minh && (pos+w)<size) ++w;					// 求连续的的最小hang[i]的列数。
	h = size-minh ;
	tp = h<w ? h : w ;	// tp是下个位置可以放进去的最大的cake的边长。
	for( i=tp; i>0; --i)
		if( cake[i]>0)
		{
			--cake[i];
			--n;
			for(j=pos;j<pos+i;++j)	hang[j] += i;
			checkPut();		//DFS
			++cake[i];
			++n;
			for(j=pos;j<pos+i;++j)	hang[j] -= i;
		}
}
int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%d",&cs);
	while(cs--)
	{
		memset(cake,0,sizeof(cake));
		memset(hang,0,sizeof(hang));
		scanf("%d%d",&size, &n);
		int i ,t ,sum=0;
		for(i=0;i<n;++i)
		{
			scanf("%d",&t);
			++cake[t];
			sum += (t*t);
		}
		ok =false;
		if( size*size==sum )
		{	
			checkPut();
			if( ok )	
				printf("KHOOOOB!\n");
		}
		else	printf("HUTUTU!\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