zoukankan      html  css  js  c++  java
  • 二维前缀处理

    给一张图和若干障碍,给出若干个点,给出若干类型的飞船,求有多少种降落方案。

    典型的二维前缀处理:不解释

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<math.h>
    using namespace std;
    int r,c,p,q;
    bool map[1100][1100];
    int f[1100][1100],ans;
    int main()
    {
        freopen("alien.in","r",stdin);
        freopen("alien.out","w",stdout);
        scanf("%d%d%d%d",&r,&c,&p,&q);
        for(int x,y,i=1;i<=p;i++)
        {
            scanf("%d%d",&x,&y);
            map[x][y]=true;        
        }
        for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++)    
            f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]+map[i][j];
        for(int k=1,A,B;k<=q;k++)
        {
            scanf("%d%d",&A,&B);ans=0;
            for(int i=0;i<=r;i++)
            for(int j=0;j<=c;j++)
            {
                if(i+A<=r&&j+B<=c&&f[i+A][j+B]-f[i][j+B]-f[i+A][j]+f[i][j] ==0)    ans++;
                if(A!=B)if(i+B<=r&&j+A<=c&&f[i+B][j+A]-f[i][j+A]-f[i+B][j]+f[i][j] ==0)    ans++;
            }
            printf("%d
    ",ans);
        }
        return 0;
    } 
  • 相关阅读:
    phpdocumentor生成代码注释文档(linux)
    phpstorm扩展
    es教程
    康威定律
    k8s
    tidb调研
    netty 在线教程
    McQueenRPC源码阅读
    DIY一些基于netty的开源框架
    性能测试
  • 原文地址:https://www.cnblogs.com/CLGYPYJ/p/7237878.html
Copyright © 2011-2022 走看看