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

1928没头没脑就AC了

Posted by 15914304086 at 2012-02-08 01:26:31 on Problem 1928
题目的要求很简单,
每次寻找最多花生的点摘取,
每个点都不会有相同数目的花生,
看见那么多人过了,我没头没脑地想,48Ms一次AC了。
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int tian[50][50],a,b;

void findout(int shu,int&x,int&y)
{
	for (x=0;x<a;x++)
	{
		for (y=0;y<b;y++)
			if (tian[x][y]==shu)
				break;
		if (y!=b)
			break;
	}
}//寻找某个数目花生对应的横纵座标


int main()
{
	int n,i,j,k,zhiyin[2500],x,y,*p,guozi,route,x1,y1;
	cin>>n;
	while (n--)
	{
		cin>>a>>b>>k;
		for (i=0;i<a;i++)
			for (j=0;j<b;j++)
			{
				cin>>tian[i][j];
				zhiyin[i*b+j]=tian[i][j];
			}
		sort(zhiyin,zhiyin+a*b);
		p=zhiyin+a*b-1;
		findout(*p,y,x);
		if (k>2*(y+1)+1)//第一次取花生成功
		{	
			k-=y+2;
			guozi=*p;
			while(1)
			{
				if (p!=zhiyin)
					p--;
				else
					break;
				if (*p==0)
					break;
				findout(*p,y1,x1);
				route=abs(x-x1)+abs(y-y1)+1;
				if (k>=route+y1+1)//判断unit时加上回来的步数
				{
					k-=route;//减的时候不用加上回来的步数
					guozi+=*p;
					x=x1;
					y=y1;
				}
				else
					break;
			}
			cout<<guozi<<endl;
		}
		else
			if (k==(2*y+1)+1)//只能取到第一次花生
				cout<<guozi<<endl;
			else
				cout<<'0'<<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