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 forceil at 2007-04-05 16:19:43 on Problem 1702
#include <iostream.h>
#include <stdlib.h>
#include <memory.h>
int left=0;
int temp[21];
int Data[21];
void Go(int i,int mod);
int main(int argc, char *argv[])
{
	int Times=0;
	cin>>Times;
	while(Times-->0)
	{
	cin>>left;
	memset(temp,0,sizeof(temp));
	memset(Data,0,sizeof(Data));

	int i=0;
	if(left%3==1)
	{
		left/=3;
		Data[0]=1;
		Go(i+1,left%3);
	}
	else if(left%3==2)
	{
		left/=3;
		temp[0]=1;
		Go(i+1,left%3+1);
	}
	else
	{
		left/=3;
		Go(i+1,left%3);
	}
	int max=1;
	for(i=0;i<20;i++)
	{
		if(temp[i]!=0)
		temp[i]=max;
		if(Data[i]!=0)
		Data[i]=max;
		max*=3;
	}
	max=0;
	for(i=0;i<20;i++)
	{
		if(temp[i]!=0)
		{
		if(max==1)
		cout<<",";
		cout<<temp[i];
		max=1;
		}
	}
	if(max!=1)
	cout<<"empty";
	cout<<" ";
	max=0;
	for(i=0;i<20;i++)
	{
		if(Data[i]!=0)
		{
		if(max==1)
		cout<<",";
		cout<<Data[i];
		max=1;
		}
	}
	if(max==0)
	cout<<"empty";
	cout<<endl;
	}

  return EXIT_SUCCESS;
}
void Go(int i,int mod)
{
	if(left==0)
	{
	if(mod==1)
	Data[i]=1;
	if(mod==2)
	{
		Data[i+1]=1;
		temp[i]=1;
	}
	return ;
	}
	if(mod==1)
	{
		Data[i]=1;
		left/=3;
		Go(i+1,left%3);
	}
	else if(mod==2)
	{
		temp[i]=1;
		left/=3;
		Go(i+1,left%3+1);
	}
	else
	{
		left/=3;
		Go(i+1,left%3);
	}
	
}

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