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啊,郁闷

Posted by Maiden at 2007-10-19 21:43:42 on Problem 1048
#include <stdio.h>
#include <memory.h>

#define MaxG 202
#define MaxS 28

char diagram[MaxG][MaxG];
char input[MaxS];
struct PORTS
{
	int x,y;
}port,dx[4];
int l,n;
int i,j;
int GetData()
{
	char ch;
	l=0;
	j=0;
	if (scanf("%c",&ch)==EOF) return 0;
	memset(diagram,0,sizeof(diagram));
	while (ch!=10)
	{
		diagram[l][j]=ch;
		j++;
		scanf("%c",&ch);
	}
	diagram[l][j]=0;
	while (1)
	{
		scanf("%c",&ch);
		if (ch=='*')
		{
			scanf("%c",&ch);
			break;
		}
		l++;
		j=0;
		while (ch!=10)
		{
			diagram[l][j]=ch;
			j++;
			scanf("%c",&ch);
		}
		diagram[l][j]=0;
	}
	for (i=0;i<=l;i++)
	{
		for (j=0;diagram[i][j];j++)
		{
			if (diagram[i][j]=='?')
			{
				port.x=i;
				port.y=j;
			}
		}
	}
	return 1;
}
int orient(int x, int y, int pd)
{
	int d;
	if (x-1>=0 && pd!=3 && diagram[x-1][y]=='|') d=0;
	else if (y+1<=MaxG-1 && pd!=2 && diagram[x][y+1]=='-') d=1;
	else if (x+1<=MaxG-1 && pd!=0 && diagram[x+1][y]=='|') d=3;
	else d=2;
	return d;
}
int output(int x, int y, int d)
{
	char ch;
	int rst,rst1,rst2;
	do
	{
		x=x+dx[d].x;
		y=y+dx[d].y;
		ch=diagram[x][y];
		if (ch=='+') d=orient(x, y, d);
	}while (ch=='-' || ch=='|' || ch=='+');

	if (ch=='o') 
	{
		rst=output(x, y, d);
		return 1-rst;
	}
	else if (ch=='>') 
	{
		rst1=output(x-1, y-2, d);
		rst2=output(x+1, y-2, d);
		return rst1 | rst2;
	}
	else if (ch==')') 
	{
		rst1=output(x-1, y-2, d);
		rst2=output(x+1, y-2, d);
		return rst1 & rst2;
	}
	else if (ch>='A' && ch<='Z') return (input[ch-'A']-'0');
	return -1;
}
int main()
{
	dx[0].x=-1;	dx[0].y=0;
	dx[1].x=0;	dx[1].y=1;
	dx[3].x=1;	dx[3].y=0;
	dx[2].x=0;	dx[2].y=-1;
	while (GetData())
	{
		memset(input,0,sizeof(input));
		scanf("%s",&input);
		while (input[0]!='*')
		{
			printf("%d\n",output(port.x,port.y,orient(port.x,port.y,-1)));
			memset(input,0,sizeof(input));
			scanf("%s",&input);
		}
		printf("\n");
	}
	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