Escape

The students of the HEU are maneuvering for their military training. 
The red army and the blue army are at war today. The blue army finds that Little A is the spy of the red army, so Little A has to escape from the headquarters of the blue army to that of the red army. The battle field is a rectangle of size m*n, and the headquarters of the blue army and the red army are placed at (0, 0) and (m, n), respectively, which means that Little A will go from (0, 0) to (m, n). The picture below denotes the shape of the battle field and the notation of directions that we will use later. 



The blue army is eager to revenge, so it tries its best to kill Little A during his escape. The blue army places many castles, which will shoot to a fixed direction periodically. It costs Little A one unit of energy per second, whether he moves or not. If he uses up all his energy or gets shot at sometime, then he fails. Little A can move north, south, east or west, one unit per second. Note he may stay at times in order not to be shot. 
To simplify the problem, let’s assume that Little A cannot stop in the middle of a second. He will neither get shot nor block the bullet during his move, which means that a bullet can only kill Little A at positions with integer coordinates. Consider the example below. The bullet moves from (0, 3) to (0, 0) at the speed of 3 units per second, and Little A moves from (0, 0) to (0, 1) at the speed of 1 unit per second. Then Little A is not killed. But if the bullet moves 2 units per second in the above example, Little A will be killed at (0, 1). 
Now, please tell Little A whether he can escape. 

Input

For every test case, the first line has four integers, m, n, k and d (2<=m, n<=100, 0<=k<=100, m+ n<=d<=1000). m and n are the size of the battle ground, k is the number of castles and d is the units of energy Little A initially has. The next k lines describe the castles each. Each line contains a character c and four integers, t, v, x and y. Here c is ‘N’, ‘S’, ‘E’ or ‘W’ giving the direction to which the castle shoots, t is the period, v is the velocity of the bullets shot (i.e. units passed per second), and (x, y) is the location of the castle. Here we suppose that if a castle is shot by other castles, it will block others’ shots but will NOT be destroyed. And two bullets will pass each other without affecting their directions and velocities. 
All castles begin to shoot when Little A starts to escape. 
Proceed to the end of file. 

Output

If Little A can escape, print the minimum time required in seconds on a single line. Otherwise print “Bad luck!” without quotes.

Sample Input

4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 2 1 2 4
4 4 3 10
N 1 1 1 1
W 1 1 3 2
W 1 1 2 4

Sample Output

9
Bad luck!
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;

int n,m,k,d,flag,num,tmp;
int dir[5][2]= {{0,1},{1,0},{0,-1},{-1,0},{0,0}};//五种状态
bool vis[110][110][1010];//标记

struct node1
{
    char c;
    int t,v;
} map[110][110];

struct node2
{
    int x,y;
    int step;
};

void bfs()
{
    node2 now,next;
    queue<node2>Q;
    now.x=0;
    now.y=0;
    now.step=0;
    Q.push(now);
    vis[0][0][0]=true;
    while(!Q.empty())
    {
        now=Q.front();
        Q.pop();
        if(now.step>d)//如果超出就结束本次循环
            break;
        if(now.x==n&&now.y==m)//判断是否达到目标
        {
            cout<<now.step<<endl;
            return;
        }
        for(int i=0; i<5; i++)
        {
            next.x=now.x+dir[i][0];
            next.y=now.y+dir[i][1];
            next.step=now.step+1;
            if(next.x<0||next.x>n||next.y<0||next.y>m)//判断是否出界
                continue;
            if(!map[next.x][next.y].t&&!vis[next.x][next.y][next.step]&&next.step<=d)//判断是否有四个方向的炮弹能射杀自己
            {
                flag=1;
                for(int j=next.x-1; j>=0; j--)
                {
                    if(map[j][next.y].t&&map[j][next.y].c=='S')
                    {
                        num=next.x-j;
                        if(num%map[j][next.y].v) break;
                        tmp=next.step-num/map[j][next.y].v;
                        if(tmp<0) break;
                        if(tmp%map[j][next.y].t==0)
                        {
                            flag=0;
                            break;
                        }
                    }
                    if(map[j][next.y].t)
                        break;
                }
                if(!flag)
                    continue;
                for(int j=next.x+1; j<=n; j++)
                {
                    if(map[j][next.y].t&&map[j][next.y].c=='N')
                    {
                        num=j-next.x;
                        if(num%map[j][next.y].v) break;
                        tmp=next.step-num/map[j][next.y].v;
                        if(tmp<0) break;
                        if(tmp%map[j][next.y].t==0)
                        {
                            flag=0;
                            break;
                        }
                    }
                    if(map[j][next.y].t)
                        break;
                }
                if(!flag)
                    continue;
                for(int j=next.y-1; j>=0; j--)
                {
                    if(map[next.x][j].t&&map[next.x][j].c=='E')
                    {
                        num=next.y-j;
                        if(num%map[next.x][j].v) break;
                        tmp=next.step-num/map[next.x][j].v;
                        if(tmp<0) break;
                        if(tmp%map[next.x][j].t==0)
                        {
                            flag=0;
                            break;
                        }
                    }
                    if(map[next.x][j].t)
                        break;
                }
                if(!flag)
                    continue;
                for(int j=next.y+1; j<=m; j++)
                {
                    if(map[next.x][j].t&&map[next.x][j].c=='W')
                    {
                        num=j-next.y;
                        if(num%map[next.x][j].v) break;
                        tmp=next.step-num/map[next.x][j].v;
                        if(tmp<0) break;
                        if(tmp%map[next.x][j].t==0)
                        {
                            flag=0;
                            break;
                        }
                    }
                    if(map[next.x][j].t)
                        break;
                }
                if(!flag)
                    continue;
                vis[next.x][next.y][next.step]=true;
                Q.push(next);
            }
        }
    }
    cout<<"Bad luck!"<<endl;
    return;
}

int main()
{
    int t,v,x,y;
    char str[5];
    while(cin>>n>>m>>k>>d)
    {
        memset(map,0,sizeof(map));
        memset(vis,false,sizeof(vis));
        for(int i=0; i<k; i++)
        {
            cin>>str>>t>>v>>x>>y;
            map[x][y].v=v;
            map[x][y].t=t;
            map[x][y].c=str[0];
        }
        bfs();
    }
    return 0;
}

 

### SQL 中的转义字符(Escape Character)使用 在 SQL 语句中,某些字符串组合具有特殊含义,例如关键字(如 `SELECT`、`FROM`、`WHERE` 等),或者用于标识符的特殊符号(如保留字)。当开发者希望将这些保留字或特殊字符用作表名、列名等标识符时,必须使用特定的转义机制,以避免语法错误或冲突。 在 SQL 中,转义字符通常用于标识符的包裹,而不是用于字符串内的特殊字符(如通配符 `%` 或 `_` 的转义)。常见的 SQL 数据库系统(如 MySQL、PostgreSQL、Flink SQL)支持使用反勾号(`` ` ``)来包围标识符,以确保 SQL 解析器将其视为普通标识符而不是关键字。例如: ```sql CREATE TABLE `interval` (`begin` INT, `end` INT); ``` 此语句中,`interval`、`begin` 和 `end` 都是 SQL 中的保留字,若未使用反勾号包裹,将导致语法错误[^1]。 此外,某些 SQL 实现(如 SQL Server)使用双引号(`" "`) 或方括号(`[ ]`)进行标识符转义,而 PostgreSQL 支持使用双引号包裹标识符。因此,具体的转义方式取决于数据库系统。 对于 Flink SQL,官方文档明确指出,虽然部分 SQL 功能尚未实现,但一些字符串组合已被保留为关键字,用于未来扩展。如果需要将这些保留字用作字段名,应使用反勾号将其括起来,如: ```sql SELECT `value`, `count` FROM my_table; ``` 该方式可确保 SQL 解析器正确识别这些标识符,而非将其视为关键字[^4]。 除了关键字问题,SQL 中的字符串匹配(如 `LIKE` 子句)也可能需要使用转义字符。例如,若希望匹配包含 `%` 或 `_` 字符的值,可以使用 `ESCAPE` 关键字指定转义字符: ```sql SELECT * FROM users WHERE name LIKE 'A\_B%' ESCAPE '\'; ``` 在此语句中,反斜杠 `\` 被定义为转义字符,表示其后紧跟的 `_` 和 `%` 被视为普通字符,而非通配符。 ### 使用反勾号的注意事项 - 反勾号(`` ` ``)仅适用于标识符(如表名、列名)的转义,不适用于字符串内容。 - 不同数据库系统支持的转义方式可能不同,例如 SQL Server 使用双引号或方括号,而 PostgreSQL 使用双引号。 - 在编写跨数据库兼容的 SQL 语句时,应确保使用目标数据库支持的转义方式。 - 使用保留字作为标识符时,即使数据库未强制要求,也建议始终使用反勾号包裹,以增强代码可读性和可维护性。 ### 示例:使用反勾号避免关键字冲突 ```sql CREATE TABLE `user` ( `id` INT PRIMARY KEY, `order` INT, `value` VARCHAR(255) ); ``` 在此示例中,`order` 和 `value` 是某些 SQL 系统中的保留字,使用反勾号可避免语法错误[^3]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值