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 SeaFrog at 2005-07-15 16:01:06 on Problem 1088
#include<iostream.h>
#include<string.h>
using namespace std;

//ifstream fin("1088.in");
//ofstream fout("1088.out");

int n, m, num;
int high[10001];
int x[10001], y[10001];
int dist[102][102];
int ans;

int max(int a, int b, int c, int d)    {
     if (a >= b && a >= c && a >= d) return a;
     if (b >= a && b >= c && b >= d) return b;
     if (c >= a && c >= b && c >= d) return c;
     if (d >= a && d >= b && d >= c) return d;
};
     
void sort()     {
     int f, g, swap;

     for (f = 1; f < num; f ++)
         for (g = f + 1; g <= num; g ++)
             if (high[f] < high[g])  {
                         swap = high[f]; high[f] = high[g]; high[g] = swap;
                         swap = x[f]; x[f] = x[g]; x[g] = swap;
                         swap = y[f]; y[f] = y[g]; y[g] = swap;
             };

};

void init()     {
     num = n * m;

     int f, g, h = 0;

     for (f = 1; f <= n; f ++)
         for (g = 1; g <= m; g ++)      {
             h ++;

             x[h] = f; y[h] = g;

             cin >> high[h];

         };

     memset(dist, sizeof(dist), 0);
     ans = 0;

};

void work()     {
     sort();

     int i, j, k;

     for (i = 1; i <= num; i ++)        {
         dist[x[i]][y[i]] = max(dist[x[i] - 1][y[i]] + 1, dist[x[i] + 1][y[i]] + 1, dist[x[i]][y[i] - 1] + 1, dist[x[i]][y[i] + 1] + 1);

         if (dist[x[i]][y[i]] > ans) ans = dist[x[i]][y[i]];
     };

};

void print()    {
     cout << ans << endl;
};

int main()      {
    while (cin >> n >> m)       {
        init();
        work();
        print();
    };
    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