Hopscotch

来源:互联网 发布:程序员累吗 编辑:程序博客网 时间:2024/05/22 08:09

Hopscotch

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 14   Accepted Submission(s) : 11
Problem Description
The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to the x and y axes.

They then adroitly hop onto any digit in the grid and hop forward, backward, right, or left (never diagonally) to another digit in the grid. They hop again (same rules) to a digit (potentially a digit already visited).
With a total of five intra-grid hops, their hops create a six-digit integer (which might have leading zeroes like 000201).
Determine the count of the number of distinct integers that can be created in this manner.

Input
* Lines 1..5: The grid, five integers per line
 
Output
* Line 1: The number of distinct integers that can be constructed
 
Sample Input
1 1 1 1 11 1 1 1 11 1 1 1 11 1 1 2 11 1 1 1 1

Sample Output
15
题意:能组成多少个不用的数
#include <stdio.h>#include <stdlib.h>int map[6][6];int dir[4][2]= {-1,0,1,0,0,-1,0,1};int total=0;int a[6];int b[1000000];void creat(){    int i,j;    for(i=0; i<5; i++)        for(j=0; j<5; j++)            scanf("%d",&map[i][j]);}void sql(int row,int col,int n){    int i,erow,ecol;    if(n==6)    {        int i;        int sum=0;        for(i=0; i<6; i++)        {            sum*=10;            sum+=a[i];        }        if(!b[sum])        {            total++;            b[sum]=1;        }        return ;    }    a[n]=map[row][col];    for(i=0; i<4; i++)    {        erow=row+dir[i][0];        ecol=col+dir[i][1];        if(erow>=0&&erow<5&&ecol>=0&&ecol<5)        {            sql(erow,ecol,n+1);        }    }}int main(){    //memset(b,0,sizeof(b));    creat();    int i,j;    for(i=0; i<5; i++)        for(j=0; j<5; j++)            sql(i,j,0);    printf("%d",total);    return 0;}


0 0
原创粉丝点击