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

为什么老是包WA?请教牛人

Posted by pkwang at 2006-10-02 01:54:07 on Problem 1120
#include <iostream.h>
#include <math.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
ifstream fin("input.txt");

struct worm
{
	int x;
	int y;
};

int main()
{
	int i,n;
	cin>>n;
	for(i = 1;i <= n;i ++)
	{
		int simDay;
		cin>>simDay;
		int rules[16];
		int j;
		for(j = 0;j <= 15;j ++)
			cin>>rules[j];
		int curSqure[20][20];
		int nextSqure[20][20];
		int u,v;
		for(u = 0;u < 20;u ++)
			for(v = 0;v < 20;v ++)
				cin>>curSqure[u][v];
		int curDay;
		for(curDay = 1;curDay <= simDay;curDay ++)
		{
			for(u = 0;u < 20;u ++)
				for(v = 0;v < 20; v++)
				{
					int sum = curSqure[u][v];
					if(u+1 >= 0 && u+1 <= 19)
						sum += curSqure[u+1][v];
					if(u-1 >= 0 && u-1 <= 19)
						sum += curSqure[u-1][v];
					if(v+1 >= 0 && v+1 <= 19)
						sum += curSqure[u][v+1];
					if(v-1 >= 0 && v-1 <= 19)
						sum += curSqure[u][v-1];
					if(rules[sum] >= 0)
						nextSqure[u][v] = curSqure[u][v] + rules[sum];
					else
						nextSqure[u][v] = curSqure[u][v] - abs(rules[sum]);
					if(nextSqure[u][v] > 3)
						nextSqure[u][v] = 3;
					if(nextSqure[u][v] < 0)
						nextSqure[u][v] = 0;
				}
			for(u = 0;u < 20;u ++)
				for(v = 0;v < 20; v++)
					curSqure[u][v] = nextSqure[u][v];
		}
		int w,t;
		for(w = 0;w < 20; w++)
		{
			for(t = 0;t < 20;t ++)
			{
				if(curSqure[w][t] == 0)
					cout<<".";
				if(curSqure[w][t] == 1)
					cout<<"!";
				if(curSqure[w][t] == 2)
					cout<<"X";
				if(curSqure[w][t] == 3)
					cout<<"#";
				if(t != 19)
					cout<<" ";
			}
			cout<<endl;
		}
		if(i != n)
			cout<<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