| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 509 人关注过本帖
标题:zoj 1019 时间超限。。。。。。
只看楼主 加入收藏
巴克
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:199
注 册:2012-2-8
结帖率:100%
收藏
 问题点数:0 回复次数:2 
zoj 1019 时间超限。。。。。。
先上题目:

Illusive Chase

--------------------------------------------------------------------------------

Time Limit: 2 Seconds      Memory Limit: 65536 KB

--------------------------------------------------------------------------------

Tom the robocat is presented in a Robotics Exhibition for an enthusiastic audience of youngsters, placed around an m * n field. Tom which is turned off initially is placed in some arbitrary point in the field by a volunteer from the audience. At time zero of the show, Tom is turned on by a remote control. Poor Tom is shown a holographic illusion of Jerry in a short distance such that a direct path between them is either vertical or horizontal. There may be obstacles in the field, but the illusion is always placed such that in the direct path between Tom and the illusion, there would be no obstacles. Tom tries to reach Jerry, but as soon as he gets there, the illusion changes its place and the chase goes on. Let's call each chase in one direction (up, down, left, and right), a chase trip. Each trip starts from where the last illusion was deemed and ends where the next illusion is deemed out. After a number of chase trips, the holographic illusion no more shows up, and poor Tom wonders what to do next. At this time, he is signaled that for sure, if he returns to where he started the chase, a real Jerry is sleeping and he can catch it.

To simplify the problem, we can consider the field as a grid of squares. Some of the squares are occupied with obstacles. At any instant, Tom is in some unoccupied square of the grid and so is Jerry, such that the direct path between them is either horizontal or vertical. It's assumed that each time Tom is shown an illusion; he can reach it by moving only in one of the four directions, without bumping into an obstacle. Tom moves into an adjacent square of the grid by taking one and only one step.

The problem is that Tom's logging mechanism is a bit fuzzy, thus the number of steps he has taken in each chase trip is logged as an interval of integers, e.g. 2 to 5 steps to the left. Now is your turn to send a program to Tom's memory to help him go back. But to ease your task in this contest, your program should only count all possible places that he might have started the chase from.


Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains two integers m and n, which are the number of rows and columns of the grid respectively (1 <= m, n <= 100). Next, there are m lines, each containing n integers which are either 0 or 1, indicating whether the corresponding cell of the grid is empty (0) or occupied by an obstacle (1). After description of the field, there is a sequence of lines, each corresponding to a chase trip of Tom (in order). Each line contains two positive integers which together specify the range of steps Tom has taken (inclusive), followed by a single upper-case character indicating the direction of the chase trip, which is one of the four cases of R (for right), L (for left), U (for up), and D (for down). (Note that these directions are relative to the field and are not directions to which Tom turns). This part of the test case is terminated by a line containing exactly two zeros.


Output

For each test case, there should be a single line, containing an integer indicating the number of cells that Tom might have started the chase from.


Sample Input

2
6 6
0 0 0 0 0 0
0 0 0 1 1 0
0 1 0 0 0 0
0 0 0 1 0 0
0 0 0 1 0 1
0 0 0 0 0 1
1 2 R
1 2 D
1 1 R
0 0
3 4
0 0 0 0
0 0 0 0
0 0 0 0
1 2 R
3 7 U
0 0


Sample Output

10
0
搜索更多相关主题的帖子: volunteer 1019 audience presented Memory 
2012-07-16 22:55
巴克
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:199
注 册:2012-2-8
收藏
得分:0 
二楼上代码:
程序代码:
#include<stdio.h>

typedef struct step
{
    int x,y;
    char direction;
}step;

step steps[10000];
int maps[101][101];
int m,n,flag;
int work(int x,int y,int mark)
{
    int i,j,xn,yn;
    char p;

    if(x<1||x>m||y<1||y>n||maps[x][y])return 0;
    if( mark == flag) return 1;
    xn = x; yn = y;
    for(i=steps[mark].x;i<=steps[mark].y;i++)
    {

        p=steps[mark].direction;
        if(p=='U')
        {
            xn=x-i;
            if(xn<1)    return 0;
            for(j=xn;j<=x;j++)
                if(maps[j][y])
                return 0;
        }
        if(p=='D')
        {
            xn=x+i;
            if(xn>m) return 0;
            for(j=x;j<=xn;j++)
                if(maps[j][y])
                return 0;
        }
        if(p=='R')
        {
            yn=y+i;
            if(yn>n)return 0;
            for(j=y;j<=yn;j++)
                if(maps[x][j])
                return 0;
        }
        if(p=='L')
        {
            yn=y-i;
            if(yn<1)    return 0;
            for(j=yn;j<=y;j++)
                if(maps[x][j])
                return 0;
        }
        if(work(xn,yn,mark+1)==1)
        return 1;
    }
    return 0;
}
int main()
{
    int k,t;
    int i,j,tx,ty;
    int count=0;
    char ch;
    scanf("%d",&k);
    while(k--)
    {
        t=0;count=0;flag=0;
        scanf("%d%d",&m,&n);
        for(i=1;i<=m;i++)
            for(j=1;j<=n;j++)
            scanf("%d",&maps[i][j]);
        while(1)
        {
            scanf("%d%d",&tx,&ty);
            if(tx==0 || ty==0)break;
            steps[t].x = tx;
            steps[t].y = ty;
            scanf("%c",&ch);
            steps[t].direction = ch;
            t++;
            flag++;
        }

        for(i=1;i<=m;i++)
            for(j=1;j<=n;j++)
                count += work(i,j,0);

        printf("%d\n",count);
    }

    return 0;

}


求大神指点一二。。
2012-07-16 22:56
巴克
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:93
专家分:199
注 册:2012-2-8
收藏
得分:0 
我晕。。。原来这样就行了
 scanf("%c",&ch);--->scanf(" %c",&ch);
2012-07-17 08:50
快速回复:zoj 1019 时间超限。。。。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040711 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved