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

再网上找了很多测试数据都过了,可在poj上就是过不了,哪位大牛帮忙测试一下啊,感激不尽

Posted by petercai at 2009-10-31 13:40:13 on Problem 1176
#include<iostream>
#include<string.h>
using namespace std;
int N;
int a[16];
int one[16]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
char *bincode[16]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
int indextable[16];
bool check(char *lamp,int*on,int *off)
{
	int i=0;
	while(on[i]!=-1)
	{
		if(lamp[on[i]-1]=='0')	return false;
		i++;
	}
	i=0;
	while(off[i]!=-1)
	{
		if(lamp[off[i]-1]=='1')	return false;
		i++;
	}
	return true;
}

int main()
{
	int sum=0;
	cin>>N;
	int C;
	cin>>C;
	int i,j;
	char *lamp[16];
	for(i=0;i<16;i++)
		if(C-one[i]>=0&&(C-one[i])%2==0)	a[i]++;
	for(i=0;i<16;i++)
		lamp[i]=new char[N+1];
	for(i=0;i<16;i++)
	{
		for(j=0;j<N;j++)
			lamp[i][j]='1';
		lamp[i][N+1]='\0';
	}
	for(i=0;i<16;i++)
	{
		if(a[i]==1)
		{
			sum++;
			if(bincode[i][0]=='1')
			{
				for(j=0;j<N;j++)
				if(lamp[i][j]=='1')	lamp[i][j]='0';
				else lamp[i][j]='1';
			}
			if(bincode[i][1]=='1')
			{
				for(j=0;j<N;j+=2)
				if(lamp[i][j]=='1')	lamp[i][j]='0';
				else lamp[i][j]='1';
			}
			if(bincode[i][2]=='1')
			{
				for(j=1;j<N;j+=2)
				if(lamp[i][j]=='1')	lamp[i][j]='0';
				else lamp[i][j]='1';
			}
			if(bincode[i][3]=='1')
			{
				for(j=0;j<N;j+=3)
				if(lamp[i][j]=='1')	lamp[i][j]='0';
				else lamp[i][j]='1';
			}
		}	
	}

	for(i=0;i<16;i++)
	{
		int min=i;
		bool change=0;
		for(j=i+1;j<16;j++)
		{
			if(strcmp(lamp[j],lamp[min])<0)	{min=j;change=1;}
		}
		if(change==1)
		{
			char *temp=new char[N+1];
			strcpy(temp,lamp[i]);
			strcpy(lamp[i],lamp[min]);
			strcpy(lamp[min],temp);
		}
	}
	//	for(i=0;i<16;i++)
	//	cout<<lamp[i]<<endl;
	
	int on[5];
	int off[5];
	i=0;
	cin>>on[0];
	while(on[i]!=-1)
	{
		i++;
		cin>>on[i];
	}
	i=0;
	cin>>off[i];
	while(off[i]!=-1)
	{
		i++;
		cin>>off[i];
	}
	if(check(lamp[0],on,off))
	cout<<lamp[0]<<endl;
	for(i=1;i<sum;i++)
	{
		if((!strcmp(lamp[i],lamp[i-1]))||(!check(lamp[i],on,off)))	continue;
		cout<<lamp[i]<<endl;
	}
	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