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

水过

Posted by sophlen at 2011-03-24 08:10:35 on Problem 3752
#include <cstdlib>
#include <iostream>

using namespace std;
int m,t,a[100][100];
int x,y,n,co;
void l1();
void l2();
void h1();
void h2();

void h1()
{
     for(;y<t;y++)
     {
             if(a[x][y]!=-1) break;
             a[x][y]=n;
             n++;
             n=n%26;
             co++;
             
     }if(co>=m*t) return;
     y--;x++;
     l1();
}
void h2()
{
     for(;y>=0;y--)
     {
             if(a[x][y]!=-1) break;
             a[x][y]=n;
             n++;
             n=n%26;
             co++;
             
     }if(co>=m*t) return;
     y++;x--;
     l2();
}
void l1()
{
     for(;x<m;x++)
     {
             if(a[x][y]!=-1) break;
             a[x][y]=n;
             n++;
             n=n%26;
             co++;
             
     }if(co>=m*t) return;
     x--;y--;
     h2();
}
void l2()
{
     for(;x>=0;x--)
     {
             if(a[x][y]!=-1) break;
             a[x][y]=n;
             n++;
             n=n%26;
             co++;
             
     }if(co>=m*t) return;
     x++;y++;
     h1();
}
int main(int argc, char *argv[])
{
    while( cin>>m>>t)
    {
           for(int i=0;i<100;i++)
                   for(int j=0;j<100;j++)
                           a[i][j]=-1;
           x=0;y=0;n=0;co=0;
           h1();
           for(int i=0;i<m;i++)
           {
                   for(int j=0;j<t;j++)
                           cout<<"   "<<char(a[i][j]+'A'); 
                   cout<<endl;
           }
    }
    return EXIT_SUCCESS;
}

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