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

我下了去年Preliminary Contest1928题的数据,我提交的程序完全符合此题,却在题库上wrong~~~求高手指点

Posted by lagrange at 2005-10-12 19:35:34
我的程序  用c

#include <stdio.h>

int m,n,k,t;
int vx,vy;
int xx[50][50];

void input()
{
    int i,j;
    scanf("%d%d%d\n",&m,&n,&k);
    for(i=0;i<m;i++)
      for(j=0;j<n;j++)
        scanf("%d",&xx[i][j]);
    k--;k--;
    printf("%ld",solve());
}

void most()
{
    int i,j;
    int tt=-1;
    for(i=0;i<m;i++)
      for(j=0;j<n;j++)
        if(xx[i][j]>tt)
        {
            tt=xx[i][j];
            vx=i;vy=j;
        }
}

int dis(x,y)
{
    return fabs(x-vx)+fabs(y-vy);
}

long solve()
{
    int i,j;
    long pn=0;
    int px,py,temp;
    most();
    if(xx[vx][vy]==0)
          return pn;
    if(k-vx-vx-1<0)
      return pn;
    px=vx;py=vy;
    k-=vx;
    pn+=xx[px][py];k--;
    xx[px][py]=0;
    for(;;)
    {
        most();
        if(xx[vx][vy]==0)
          return pn;
        temp=k-dis(px,py)-vx-1;
        if(temp<0)
          return pn;
        k-=dis(px,py);
        px=vx;py=vy;
        pn+=xx[px][py];k--;
        xx[px][py]=0;

    }
}

main()
{
    int i,j;
//	freopen("peanuts.in","r",stdin);
//	freopen("peanuts.txt","w",stdout);

    scanf("%d",&t);
    for(i=0;i<t;i++){
      input();
      if(i!=t-1)
       printf("\n");
      }
}

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