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

哪位大牛帮我看下代码错哪啊~~ DEBUG了好久没改出来~~

Posted by 3080434005 at 2009-03-10 02:11:33 on Problem 1176
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int press;
int n;
vector<string> m1;
void dfs(int a[], int b[], int c[], int botten)
{
	int i;
	string str;
	if(botten == press)
	{
		for(i = 0; i < n; i ++)
		{
			if(b[i] == 1 && a[i] != 1)
				return;
			if(c[i] == 0 && a[i] != 0)
				return;
			 str.insert(i, 1, a[i]);
		}
       for(i = 0; i < m1.size(); i ++) 
		   if( m1[i] == str)
			    return;
	      m1.push_back(str);
       for(i = 0; i < n; i ++)
		   printf("%d", a[i]);
	   putchar(10);
	   return;
	}
    for(i = 1; i <= 4; i ++)
	{  
		int j;
        if(i == 1)
		{
           for(j = 0; j < n; j ++)
			   a[j] = 1 - a[j];
		   dfs(a, b, c, botten + 1);
		   for(j = 0; j < n; j ++)
			   a[j] = 1 - a[j];
		}
		else if(i == 2)
		{
			for(j = 0; j < n; j ++)
			  if(j % 2 == 0)
				  a[j] = 1 - a[j];
           dfs(a, b, c, botten + 1);
		   for(j = 0; j < n; j ++)
			  if(j % 2 == 0)
				  a[j] = 1 - a[j];
		}
		else if(i == 3)
		{
			for(j = 0; j < n; j ++)
			  if(j % 2 == 1)
				  a[j] = 1 - a[j];
           dfs(a, b, c, botten + 1);
		   for(j = 0; j < n; j ++)
			  if(j % 2 == 1)
				  a[j] = 1 - a[j];
		}
		else if(i == 4)
		{
			for(j = 0; j < n; j ++)
			  if(j % 3 == 0)
				  a[j] = 1 - a[j];
           dfs(a, b, c, botten + 1);
		   for(j = 0; j < n; j ++)
			  if(j % 3 == 0)
				  a[j] = 1 - a[j];
		}
	   
	}
}
int main()
{
   while(1 == scanf("%d", &n) )
   {
	   int l[1000];
	   int on[1000], off[1000];
	   m1.clear();
	   memset(on, 0, sizeof(on) );
	   int i;
	   for(i = 0; i < n; i ++)
	   {
		   l[i] = 1;
		   off[i] = 1;
	   }
	   scanf("%d", &press);
	   int temp;
       while(scanf("%d", &temp ) && temp != -1)
		      on[temp - 1] = 1;
	   while(scanf("%d", &temp)  && temp != -1)
		     off[temp - 1] = 0;
	   dfs(l, on, off, 0);
   }
   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