B - Gremlins attack!

博客讲述美国小镇出现小精灵,它们怕光会躲在熄灯房屋并可水平垂直移动,到达镇边界就会逃脱。给出小镇初始小精灵位置和房屋熄灯历史,需找出熄灯后小精灵能逃脱的房屋编号。还给出输入输出格式及示例。

There’s an emergency in a county-level American town. Gremlins have scattered around the town and thus the rest of the world is in danger, as, at least, one of them seems to have left the town. Special intelligence services are currently restoring the course of events and trying to identify the earliest moment when it could happen.

The town is represented in the form of a square checkered board of size N×N. Each cell represents a single house. Gremlins are, typically, afraid of bright light and therefore tend to hide in darkness. Furthermore, as people go to bed, the lights in the houses are going out. Gremlins can move horizontally and vertically from one house, where the light is off, to another. As soon as they reach the house which is on the border of the town, they escape from the town.

You have reliable data about which houses gremlins occupied in the beginning, as well as the history of turning the lights off in the houses. You need to display number of the house in history, from which after turning the light off, at least, one gremlin could escape from the town. If gremlins can escape from the town immediately, type 0. The numbering of houses in history starts with one.

Input
In the first line, three integers are entered, separated by spaces, 1<N<=500, 1<=M<=N2, 1<=K<=N2, where N determines the size of the city, M is the number of houses in which gremlins are located at the beginning, K is the size of the history of turning off lights in the houses.

Then there are M lines, each of which contains a pair of numbers 0<=xi,yi<N, specifying the coordinates of the houses where gremlins are located at the beginning. After that, there follow K lines, each of which contains a pair of numbers 0<=xj,yj<N, specifying the coordinates of the houses in which the light is turned off.

Output
The single number from 0 to K, which sets the number of the house, in which after turning off the light, at least, one gremlin had the opportunity to escape from the town.

Examples
Input
3 1 3
1 1
0 0
0 1
0 2
Output
2
Input
5 2 5
0 1
4 1
0 0
1 1
2 2
3 3
4 4
Output
0
Input
4 2 3
1 1
1 2
2 0
3 1
1 3
Output
3
Input
5 2 6
1 1
3 3
1 2
1 3
2 3
3 0
3 1
2 1
Output
6
Input
7 6 7
1 4
1 1
2 3
3 1
4 4
5 2
0 4
2 4
3 4
1 0
2 1
5 1
5 0
Output
1
Note
The input data guarantee that the escape could have been made.

ans数值存点是否能达到出口,ma数组存点是否为已经灭灯的点

#include <bits/stdc++.h>
using namespace std;
const int N = 505;
map<pair<int, int>, int> q;
pair<int, int> a[N * N];
pair<int, int> t;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int ans[N][N];
int n, ff = 0;
int ma[N][N];
void dfs(int x, int y) 
{
    if (x == 0 || y == 0 || x == n - 1 || y == n - 1 || ans[x][y])                                        
    {
        for (int j = 0; j < 4; j++) 
        {
            if (x + dx[j] >= 0 && x + dx[j] < n && y + dy[j] >= 0 && y + dy[j] < n) 
            {
                if (ans[x + dx[j]][y + dy[j]] == 0) 
                {
                    ans[x + dx[j]][y + dy[j]] = 1;
                    t.first = x + dx[j];
                    t.second = y + dy[j];
                    if (q[t]) 
                    {
                        ff = 1;
                        return;
                    }
                    if (ma[x + dx[j]][y + dy[j]] == 1)
                        dfs(x + dx[j], y + dy[j]);
                }
            }
        }
    }
}
int main() 
{
    ios::sync_with_stdio(false);
    int m, k, x, y, w, i, j;
    cin >> n >> m >> k;
    int flag = 1;
    memset(ans, 0, sizeof(ans));
    memset(ma, 0, sizeof(ma));
    for (i = 0; i < m; i++) 
    {
        cin >> x >> y;
        if (x == 0 || y == 0 || x == n - 1 || y == n - 1) 
        {
            flag = 0;
        }
        a[i].first = x;
        a[i].second = y;
        q[a[i]] = 1;
    }
    if (flag == 0) w = 0;
    for (i = 1; i <= k; i++) 
    {
        cin >> x >> y;
        if (flag) 
        {
            ma[x][y] = 1;
            dfs(x, y);
            if (ff) 
            {
                flag = 0;
                w = i;
            }
        }
    }
    cout << w << '\n';
}
先展示下效果 https://pan.quark.cn/s/5061241daffd 在使用Apache HttpClient库发起HTTP请求的过程中,有可能遇到`HttpClient`返回`response`为`null`的现象,这通常暗示着请求未能成功执行或部分资源未能得到妥善处理。 在本文中,我们将详细研究该问题的成因以及应对策略。 我们需要掌握`HttpClient`的运作机制。 `HttpClient`是一个功能强大的Java库,用于发送HTTP请求并接收响应。 它提供了丰富的API,能够处理多种HTTP方法(例如GET、POST等),支持重试机制、连接池管理以及自定义请求头等特性。 然而,一旦`response`对象为`null`,可能涉及以下几种情形:1. **连接故障**:网络连接未成功建立或在请求期间中断。 需要检查网络配置,确保服务器地址准确且可访问。 2. **超时配置**:若请求超时,`HttpClient`可能不会返回`response`。 应检查连接和读取超时设置,并根据实际需求进行适当调整。 3. **服务器故障**:服务器可能返回了错误状态码(如500内部服务器错误),`HttpClient`无法解析该响应。 建议查看服务器日志以获取更多详细信息。 4. **资源管理**:在某些情况下,如果请求的响应实体未被正确关闭,可能导致连接被提前释放,进而使后续的`response`对象为`null`。 在使用`HttpClient 3.x`版本时,必须手动调用`HttpMethod.releaseConnection()`来释放连接。 而在`HttpClient 4.x`及以上版本中,推荐采用`EntityUtils.consumeQuietly(respons...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值