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 scpczc at 2007-06-05 20:59:05 on Problem 1282
#include "stdio.h"
#include <iostream>
using namespace std;

void init();
void doit();//主函数
void getV();//输入
int get(long a,long b);//获取最大公约数
bool go(int x,int y,int targe);//遍历

int n,m;//
int aa[200][200];//输入
bool cc[200][200];//

long	bb[200];//
long	count;
int		do_x;


int main()
{
	getV();
	doit();
	return 0;
}

void getV()
{
	int i,j;
	cin>>n>>m;	
	for (i = 0 ;i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			cin>>aa[i][j];
		}
	}
}

void doit()
{
	int i;
	long j;
	for (i = 0; i < n; i++)
	{
		do_x = 1;
		count = 0;
		init();
		if(go(i,do_x,i))
		{
			bb[i] = count;
		}
		else
		{
			cout<<"No one knows.\n";
			return;
		}
	}
	j = bb[0];
	for (i = 1;i < n;i++)
	{
		j = j*bb[i]/get(j,bb[i]);
		if( j > 1000000000)
		{
			cout<<"No one knows.\n";
			return;
		}
	}
	cout<<j;
}

int get(long a,long b)
{
	if(b == 0)
	{
		return a;
	}
	else
		return get(b,a%b);
}


bool go(int x,int y,int targe)
{
	if(cc[x][y])
	{	
		if (x == targe)
		{
			return true;
		}
		return false;
	}
	count++;
	cc[x][y] = true;
	do_x = (do_x-1+m)%m;
	if(go(aa[x][y]-1,do_x,targe))
		return true;
	else
		return false;
}



void init()
{
	int i,j;
	for (i=0;i<n;i++)
	{
		for (j =0;j<m;j++)
		{
			cc[i][j] = false;
		}
	}
}



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