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 justtext at 2010-03-23 22:19:37 on Problem 1088
#include<iostream>
#include<algorithm>
using namespace std;
struct arr{
	int x,y,z;     //存相应高度的值,和行数,列数
} array[10010];

bool cmp(const arr& a,const arr& b)
{
	return a.z>b.z;
}

int solve(int b,int c,int d,int e,int f)   //对四个方位进行判断 读出最接近当前高度 的数
{
	int ii,check[4],sum,sign=1;
	check[0]=c;
	check[1]=d;
	check[2]=e;
	check[3]=f;
	sort(check,check+4);
	for(ii=3;ii>=0;ii--)
	{
		if(check[ii]<b) //判断与当前高度的关系 如果都比当前高度大 则输出 -1
		{
			sign=0;
			sum=check[ii];
			break;
		}
	}
	if(sign) return -1;
	else return sum;
}

int main()
{
	int a[105][105];
	int i,j,k=0,l=0,r,c,m,s,max,flag=0,count=0;
	cin>>r>>c;
	for(i=0;i<r+2;i++) //初始化二维数组为-1
	{
		for(j=0;j<c+2;j++)
			a[i][j]=-1;
	}
	for(i=1;i<r+1;i++) //输入值 并保存坐标和值
	{
		for(j=1;j<c+1;j++)
		{
			cin>>a[i][j];
			array[k].z=a[i][j];
			array[k].x=i;
			array[k].y=j;
			k++;
		}
	}
	sort(array,array+k,cmp); //对高度从大到小进行排序
	s=array[count].z;
	while(1)
	{
		l=0;
		for(m=0;m<k;m++)
		{
			if(s==array[m].z)
			{
				s=solve(array[m].z,a[array[m].x+1][array[m].y],a[array[m].x-1][array[m].y],a[array[m].x][array[m].y+1],a[array[m].x][array[m].y-1]);
				l++;  //每成功输出一个s长度加1
				if(s==-1) break;
			}
		}
		s=array[++count].z;
		if(l>max) max=l;
		if(max>=array[count+1].z) flag=1; //如果当前下滑距离大于或等于接下去一个高度 跳出
		if(flag) break;
	}
	cout<<max<<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