POJ 1840 Eqs

 Eqs
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 10598 Accepted: 5137
Description

Consider equations having the following form:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
The coefficients are given integers from the interval [-50,50].
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.

Determine how many solutions satisfy the given equation.
Input

The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.
Output

The output will contain on the first line the number of the solutions for the given equation.
Sample Input

37 29 41 43 47
Sample Output

654
Source

Romania OI 2002


题目大意就是给出一个n * m的矩阵,矩阵中只有一些*或者0n <= 1000, m <= 1000然后有t (t <= 100)个询问,每次询问给出一个p * q的矩阵p,q是提前固定的数值。问这些询问中能是大矩阵的子矩阵的有几个

由于p , q都小于50,而且矩阵中只有两个字符不由得让我们联想到了,把每一行给hash成一个long long 的二进制数首先,我们把大矩阵每个位置为点的q长度的串hash成二进制数都存起来每次询问的时候,把小矩阵每一行给hash了然后在大矩阵中枚举位置,进行匹配


代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#define MAXN 111111
#define MAXM 555555
#define INF 100000011
#define lch(x) x<<1
#define rch(x) x<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define eps 1e-7
using namespace std;
long long h[1111][1111];
int n, m, t, p, q;
char mp[1111][1111], tmp[66];
long long a[66];
bool ok()
{
    for(int i = 0; i + p - 1 < n; i++)
        for(int j = q - 1; j < m; j++)
        {
            int flag = 1;
            for(int k = 0; k < p; k++)
                if(h[i + k][j] != a[k])
                {
                    flag = 0;
                    break;
                }
            if(flag) return true;
        }
    return false;
}
int main()
{
    int cas = 0;
    while(scanf("%d %d %d %d %d", &n, &m, &t, &p, &q) != EOF)
    {
        if(!n && !m && !t && !q && !p) break;
        for(int i = 0; i < n; i++) scanf("%s", mp[i]);
        memset(h, 0, sizeof(h));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < q; j++)
            {
                if(mp[i][j] == '*') h[i][q - 1] |= (1LL << j);
            }
        for(int i = 0; i < n; i++)
            for(int j = q; j < m; j++)
            {
                if(mp[i][j - q] == '*') h[i][j] = h[i][j - 1] - 1LL;
                else h[i][j] = h[i][j - 1];
                h[i][j] >>= 1LL;
                if(mp[i][j] == '*') h[i][j] |= (1LL << (q - 1));
            }
        int cnt = 0;
        while(t--)
        {
            for(int i = 0; i < p; i++)
            {
                scanf("%s", tmp);
                a[i] = 0;
                for(int j = 0; j < q; j++)
                    if(tmp[j] == '*') a[i] |= (1LL << j);
            }
            if(ok()) cnt++;
        }
        printf("Case %d: %d\n", ++cas, cnt);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值