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

这个题有点错,PE,space-separated,为什么注释掉就过,不注释PE

Posted by makerofu at 2012-04-17 20:34:13 on Problem 1124
#include <stdio.h>
#include <memory.h>
int rows,cols;
unsigned int map[20][20];
unsigned int steps[20][20];
unsigned int times[20][20];
double factor[20][20];

struct location{
	int x,y;
} site[20], queue[410];

int xOffset[4] = {-1,1,0,0};
int yOffset[4] = {0,0,-1,1};

int siteValid(int x,int y)
{
	if(x>=0 && x<rows && y>=0 && y<cols)
		return steps[x][y];
	else return 500;
}

void loadFactors(int x,int y, double load)
{
	factor[x][y] += load * times[x][y];
	int point = steps[x][y];
	if(point <=1) return;
	point --;
	int i;
	for(i=0;i<4;i++)
		if(siteValid(x+xOffset[i],y+yOffset[i]) == point)
			loadFactors(x+xOffset[i],y+yOffset[i],load);
}

int main()
{
	int i,j;
	char temp[22];
	char c;
	scanf("%d %d",&cols,&rows);
//	scanf("%c",&c);
	for(i=0;i<rows;i++)
	{
		scanf("%s",temp);
	//	printf("%s",temp);
		for(j=0;j<cols;j++)
		{
		
			if(temp[j]=='.')map[i][j] = 0;
			else {
				map[i][j] = (temp[j]-='@');
				if(temp[j] != 'X'-'@')
				{
					site[--temp[j]].x = i;
					site[temp[j]].y = j;
				}
			}
		}
		//scanf("%c",&c);
		//printf("%d",i);
	}

//	printf("%c",c);
	memset(factor,0,sizeof(factor));
	char c1,c2;
	int load;
	double loadper;

	while(1)
	{
		scanf("%s",temp);
		scanf("%d",&load);
		c1 = temp[0];
		c2 = temp[1];
		//scanf("%c %c %d\n",&c1,&c2,&load);
		//scanf("%c",&c);
		//scanf("%c",&c1);
	//	scanf("%c",&c2);
		//scanf("%d",&load);
	//	printf("%c %c %d\n",c1,c2,load);
		if(c1 == 'X' && c2 == 'X') break;
		memset(steps,255,sizeof(steps));
		memset(times,0,sizeof(times));
		c1 -= 'A';
		c2 -= 'A';
		queue[0].x = site[c1].x;
		queue[0].y = site[c1].y;
		steps[queue[0].x][queue[0].y] = 0;
		times[queue[0].x][queue[0].y] = 1;
		int dx = site[c2].x;
		int dy = site[c2].y;
		map[dx][dy]=0;
		int x0,y0,x1,y1;
		unsigned int bb;
		unsigned int aa;
		int first=0,last=0;
		while(first <= last)
		{
			//if(steps[dx][dy] < 410) break;
			x0 = queue[first].x;
			y0 = queue[first].y;
			if(x0 == dx && y0 == dy) break;
			bb = steps[x0][y0];
			aa = times[x0][y0];
			bb++;
			for(i=0;i<4;i++)
			{
				x1 = x0+xOffset[i];
				y1 = y0+yOffset[i];
				int valid = 500;
				if(x1 >= 0 && x1 < rows && y1 >= 0 && y1 <cols)
					valid = map[x1][y1];
				if(valid == 0 && steps[x1][y1] > bb)
				{
					steps[x1][y1]=bb;
					last++;
					queue[last].x=x1;
					queue[last].y=y1;
				}
				if(bb == steps[x1][y1])
					times[x1][y1]+=aa;
			}
			first++;
		}
	/*	first = last = 0;
		while(first <= last)
		{
			x0 = queue[first].x;
			y0 = queue[first].y;
			bb = times[x0][y0];
			int temStep = steps[x0][y0];
			temStep++;
			for(i=0;i<4;i++){
				x1 = x0+xOffset[i];
				y1 = y0+yOffset[i];
				if(siteValid(x1,y1) == temStep)
				{
					if(times[x1][y1] == 0)
					{
						last++;
						queue[last].x=x1;
						queue[last].y=y1;
					}
					times[x1][y1]+=bb;
				}
			}
			first++;
		}*/
		map[dx][dy] = (++c2);
		loadper =((double)(load))/times[dx][dy];
		loadFactors(dx,dy,loadper);
	}
	for(i=0;i<rows;i++){
		for(j=0;j<cols;j++)
		{
			if(map[i][j] != 0) factor[i][j] = 0;
		//	if(j!=0) printf(" ");
			"   "
			"   "
			printf("%7.2lf",factor[i][j]);
		}
		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