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

Re:水过,,附代码留念

Posted by dxacm at 2010-06-06 10:25:02 on Problem 3752
In Reply To:水过,,附代码留念 Posted by:dut317410027 at 2010-05-23 19:15:57
你的代码 5 2 是错的。居然能过。我的代码 没有错误,居然过不了。难道是内定的?

=========================================================



#include <iostream>
#include <cstring>
#include <iomanip>

using namespace std;

const int sx[4] = {1, 0, -1, 0};
const int sy[4] = {0, 1, 0, -1};


class Snake {
public:
    Snake(int width, int height) {
        totalcount = width * height;
        this->width = width + 2;
        this->height = height + 2;
        matrix = new char[this->width * this->height];
        memset(matrix, '0', sizeof(this->width * this->height));
        set(1, 0, 'P');
        set(width + 1, 1, 'P');
        set(0, height, 'P');
        set(width, height + 1, 'P');
    }
    ~Snake() {
        delete [] matrix;
    }
    void output() {
        for (int y = 1; y < height - 1; y++) {
            for (int x = 1; x < width - 1; x++) {
                cout << setw(4) << get(x, y);
            }
            cout << endl;
        }
    }
    void fill() {
        currentx = 1;
        currenty = 1;
        int done = 0;
        postion = -1;
        idx = 0;
        while (done < totalcount) {
            set(currentx, currenty, nextLetter());
            done++;
            nextPos();
        }

    }
private:
    char* matrix;
    int width;
    int height;
    int currentx;
    int currenty;
    int totalcount;
    int postion;
    int idx;
    char get(int x, int y) {
        return matrix[x + y * width];
    }
    void set(int x, int y, char c) {
        matrix[x + y * width] = c;
    }
    char nextLetter() {
        const static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        postion++;
        postion %= 26;
        return table[postion];
    }

    void nextPos() {

        if (get(currentx + sx[idx], currenty + sy[idx]) != 0) {
            idx++;
            idx %= 4;
        }
        currentx += sx[idx];
        currenty += sy[idx];
    }

};

int main() {
    int m, n;
    while (cin >> m >> n) {
        Snake s(n, m);
        s.fill();
        s.output();
    }

    return 0;
}








==========================================================

> #include <stdio.h>
> #include <stdlib.h>
> int a[10000][10000];
> int main()
> {
>     int n,m,i,j,flag,k;
>     while (scanf("%d%d",&n,&m)!=EOF)
>     {
>         k=65;
>         if (n%2==0)
>         {
>             flag=n/2;
>             for (i=0;i<flag;i++)
>             {
>                 for (j=i;j<m-i;j++)
>                 {
>                     a[i][j]=k;
>                     k++;
>                     if (k==91)
>                     {
>                         k=65;
>                     }
>                 }
>                 for (j=i+1;j<n-i-1;j++)
>                 {
>                     a[j][m-i-1]=k;
>                     k++;
>                     if (k==91)
>                     {
>                         k=65;
>                     }
> 
>                 }
>                 for (j=m-i-1;j>=i;j--)
>                 {
>                     a[n-1-i][j]=k;
>                     k++;
>                     if (k==91)
>                     {
>                         k=65;
>                     }
>                 }
>                 for (j=n-i-2;j>=i+1;j--)
>                 {
>                     a[j][i]=k;
>                     k++;
>                     if (k==91)
>                     {
>                         k=65;
>                     }
>                 }
>             }
>             for (i=0;i<n;i++)
>             {
>                 for (j=0;j<m;j++)
>                 {
>                     printf("   %c",a[i][j]);
>                 }
>                 printf("\n");
>             }
>         }
>         else
>         {
>             flag=n/2+1;
> 
>             for (i=0;i<flag;i++)
>             {
>                 for (j=i;j<m-i;j++)
>                 {
>                     a[i][j]=k;
>                     k++;
>                     if (k==91)
>                     {
>                         k=65;
>                     }
>                 }
>                 for (j=i+1;j<n-i-1;j++)
>                 {
>                     a[j][m-i-1]=k;
>                     k++;
>                     if (k==91)
>                     {
>                         k=65;
>                     }
> 
>                 }
> 
>                 if (i!=flag-1)
>                     for (j=m-i-1;j>=i;j--)
>                     {
>                         a[n-1-i][j]=k;
>                         k++;
>                         if (k==91)
>                         {
>                             k=65;
>                         }
>                     }
>                 for (j=n-i-2;j>=i+1;j--)
>                 {
>                     a[j][i]=k;
>                     k++;
>                     if (k==91)
>                     {
>                         k=65;
>                     }
>                 }
>             }
>             for (i=0;i<n;i++)
>             {
>                 for (j=0;j<m;j++)
>                 {
>                     printf("   %c",a[i][j]);
>                 }
>                 printf("\n");
>             }
>         }
>     }
>     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