csp----寻宝!大冒险!

题目描述: 

 

 

AC代码如下: 

/*思路:
把A变成小块 因为B是A里的一部分
通过把A变成小块 去寻找B这样速度更快
如果A=B,B=A,说明找到了。
*/

#include <iostream>
#include <cstring>
#include <algorithm>
#include <utility>
#define x first
#define y second

using namespace std;

const int N = 1010,INF = 1e8;
typedef pair<int, int> PII;
PII shu[N];
int bao[60][60];

int main()
{
    int n,L,S;
    scanf("%d %d %d", &n,&L,&S);
    int tc = 0;
    for(int i=0;i<n;i++)
    {
        cin >> shu[i].x >> shu[i].y;
    }
    for (int i = S; i>=0; i -- )
    {
        for (int j = 0; j < S+1; j ++ )
        {
            cin >> bao[i][j];
            tc += bao[i][j];
        }
    }
    int res = 0;
    for(int i=0;i<n;i++)
    {
        //以sx,sy为初始坐标去找
        int sx = shu[i].x,sy = shu[i].y;
        //不能越界,切勿越了A的上下左右边界
        if(sx+S>L || sy+S>L) continue;
        int cnt = 0;
        for (int j = 0; j < n; j ++ )
        {
            //以sx,sy为藏宝图左下角(0,0)为原点去找跟B匹配的
            int x = shu[j].x,y = shu[j].y;
            if(x-sx<=S && x>=sx && y>=sy && y-sy<=S)
            {
                //这里只需要去找此坐标下宝藏图的位置有无1的存在
                if(!bao[x-sx][y-sy]) cnt = -INF; //INF是一个很大的负数,因为cnt最大不会超过1个亿
                else cnt ++;
            }
        }
        //如果对应坐标下全是1且位置相同 说明数目也相同
        if(cnt == tc) res++;
    }
    cout << res;
    return 0;
}

思路和注释都在代码中,欢迎不会的小伙伴留言~ 

  • 28
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值