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:这个问题是在让我震惊!!! 附上 WA 和 AC 的代码。

Posted by AlbertTry at 2009-12-12 15:19:05 on Problem 1020 and last updated at 2009-12-12 15:20:19
In Reply To:这个问题是在让我震惊!!! Posted by:AlbertTry at 2009-12-12 15:14:11
下面两个代码,一个AC,一个WA。只有pos[64]的名称不一样。大家告诉我为什么啊!!!
如果有人知道为什么麻烦告诉我啊,QQ:782700268   Email: liu_bright@foxmail.com
Source Code

Problem: 1020  User: AlbertTry 
Memory: 164K  Time: 32MS 
Language: C++  Result: Accepted 

Source Code 
#include <iostream>
using namespace std;
int cake[11] , pos[64] , cs , m , n ;
bool check()
{
	int i , j  , lie , w=0 , h , tp, minh=41;
	if(n==0)	return true;
	for(i=0;i<m;++i)	
		if(pos[i]<minh) // 找到pos[i]最小的那一列。
		{ 
			minh=pos[i], lie=i;	
		}	
	while(pos[lie+w]==minh && lie+w<m ) ++w;
	h = m-minh ;
	tp = h<w ? h : w ;	// tp是下个位置可以放进去的最大的cake的边长。
	for( i=tp; i>0; i--)
	{
		if( cake[i] )
		{
			--cake[i];
			--n;
			for(j=0;j<i;++j)	pos[lie+j] += i;
			if( check() )	return true;
			++cake[i];
			++n;
			for(j=0;j<i;++j)	pos[lie+j] -= i;

		}
	}
	return false;
}
int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%d",&cs);
	while(cs--)
	{
		scanf("%d %d",&m, &n);
		int i ,t ,sum=0;
		memset(cake,0,sizeof(cake));
		memset(pos,0,sizeof(pos));
		for(i=0;i<n;++i)
		{
			scanf("%d",&t);
			++cake[t];
			sum += (t*t);
		}
		if( m*m==sum && check() )
			printf("KHOOOOB!\n");
		else
			printf("HUTUTU!\n");
	}
	return 0;
}
/////////////////////////////////////////////////////////////////////
Source Code

Problem: 1020  User: AlbertTry 
Memory: N/A  Time: N/A 
Language: C++  Result: Wrong Answer 

Source Code 
#include <iostream>
using namespace std;
int cake[11] , aaa[64] , cs , m , n ;
bool check()
{
	int i , j  , lie , w=0 , h , tp, minh=41;
	if(n==0)	return true;
	for(i=0;i<m;++i)	
		if(aaa[i]<minh) // 找到hang[i]最小的那一列。
		{ 
			minh=aaa[i], lie=i;	
		}	
	while(aaa[lie+w]==minh && lie+w<m ) ++w;
	h = m-minh ;
	tp = h<w ? h : w ;	// tp是下个位置可以放进去的最大的cake的边长。
	for( i=tp; i>0; i--)
	{
		if( cake[i] )
		{
			--cake[i];
			--n;
			for(j=0;j<i;++j)	aaa[lie+j] += i;
			if( check() )	return true;
			++cake[i];
			++n;
			for(j=0;j<i;++j)	aaa[lie+j] -= i;

		}
	}
	return false;
}
int main()
{
	//freopen("in.txt","r",stdin);
	scanf("%d",&cs);
	while(cs--)
	{
		scanf("%d %d",&m, &n);
		int i ,t ,sum=0;
		memset(cake,0,sizeof(cake));
		memset(aaa,0,sizeof(aaa));
		for(i=0;i<n;++i)
		{
			scanf("%d",&t);
			++cake[t];
			sum += (t*t);
		}
		if( m*m==sum && check() )
			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