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: 这神奇的机制,我也是醉了。下附三份代码,请君感受神奇的RE判定

Posted by lyhxh at 2016-02-07 10:49:29 on Problem 2960
In Reply To: 这神奇的机制,我也是醉了。下附三份代码,请君感受神奇的RE判定 Posted by:fzfzfz at 2015-01-12 11:47:39
其实是在dfs里开的数组过大,导致爆栈了,至于你的dfs深度或许和搜索顺序有关
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 105
#define M 10100
using namespace std;
int S,s[N];
int sg[M];
int SG(int x)
{
	int i;
	if(sg[x]+1)return sg[x];
	bool vis[M]={0};
	for(i=1;i<=S&&s[i]<=x;i++)vis[SG(x-s[i])]=true;
	for(i=0;vis[i];i++);
	return sg[x]=i;
}
int n,m;
int main()
{
//	freopen("test.in","r",stdin);
	int i,k,g;
	while(scanf("%d",&S),S)// 数据组数A
	{
		for(i=1;i<=S;i++)scanf("%d",&s[i]); 
		sort(s+1,s+S+1);
			// s : 每次可以取的石子数量集合
		memset(sg,-1,sizeof(sg)),sg[0]=0;
		for(int i=1;i<=10000;i++)SG(i);
		for(scanf("%d",&g);g--;) // 数据组数B
		{
			for(k=0,scanf("%d",&n);n--;) // n堆石子
			{
				scanf("%d",&m); // 该堆石子的个数
				k^=sg[m];
			}
			if(k)putchar('W');
			else putchar('L');
		}
		 puts("");
	}
	return 0;
}
只要改成这样就可以了,还有一个需要注意的地方,数组开大是一个好习惯,但你的数组过大导致常数比较大有可能tle,所以我给你该小了…

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