HNU13383:The Big Painting

Problem description

Samuel W. E. R. Craft is an artist with a growing reputation. Unfortunately, the paintings he sells do not provide him enough money for his daily expenses plus the new supplies he needs. He had a brilliant idea yesterday when he ran out of blank canvas:
"Why don’t I create a gigantic new painting, made of all the unsellable paintings I have, stitched together?". After a full day of work, his masterpiece was complete.

That’s when he received an unexpected phone call: a client saw a photograph of one of his paintings and is willing to buy it now! He had forgotten to tell the art gallery to remove his old works from the catalog! He would usually welcome a call like this, but
how is he going to find his old work in the huge figure in front of him?

Given a black-and-white representation of his original painting and a black-and-white representation of his masterpiece, can you help S.W.E.R.C. identify in how many locations his painting might be?

Input

Output

A single integer representing the number of possible locations where his painting might be.

Sample Input
4 4 10 10
oxxo
xoox
xoox
oxxo
xxxxxxoxxo
oxxoooxoox
xooxxxxoox
xooxxxoxxo
oxxoxxxxxx
ooooxxxxxx
xxxoxxoxxo
oooxooxoox
oooxooxoox
xxxoxxoxxo
Sample Output
4
Problem Source

HNU Contest

题意:

给出两个图,问大图中包含几个小图

思路:

用数字保存是一种方法,本以为超类型肯定不行的,没有想到居然也能AC,不知道是数据水还是数据保存方面的一些玄机?

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define ls 2*i
#define rs 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define ULL unsigned long long
#define N 2005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define rank rank1
const int mod = 1000000007;

int h1,h2,w1,w2,ans;
char s1[N][N],s2[N][N];
const ULL t1 = 7;
const ULL t2 = 11;
ULL sum,a[N][N],b[N][N];

void solve()//把大图用数字表示的同时找出与小图相等的位置
{
    int i,j,k;
    ULL x=1;
    for(i = 0; i<w1; i++) x*=t1;
    for(i = 0; i<h2; i++)
    {
        ULL s = 0;
        for(j = 0; j<w1; j++) s = s*t1+s2[i][j];
        a[i][w1-1] = s;
        for(j = w1; j<w2; j++)
            a[i][j] = a[i][j-1]*t1-s2[i][j-w1]*x+s2[i][j];
    }
    x = 1;
    for(i = 0; i<h1; i++) x*=t2;
    for(i = w1-1; i<w2; i++)
    {
        ULL s = 0;
        for(j = 0; j<h1; j++) s = s*t2+a[j][i];
        b[h1-1][i] = s;
        if(s==sum) ans++;
        for(j = h1; j<h2; j++)
        {
            b[j][i] = b[j-1][i]*t2-a[j-h1][i]*x+a[j][i];
            if(b[j][i]==sum) ans++;
        }
    }
}

int main()
{
    int i,j,k;
    while(~scanf("%d%d%d%d",&h1,&w1,&h2,&w2))
    {
        for(i = 0; i<h1; i++) scanf("%s",s1[i]);
        for(i = 0; i<h2; i++) scanf("%s",s2[i]);
        sum = 0;
        for(i = 0; i<h1; i++)//把小图用数字表示
        {
            ULL s = 0;
            for(j = 0; j<w1; j++)
            {
                s = s*t1+s1[i][j];
            }
            sum = sum*t2+s;
        }
        ans = 0;
        solve();
        printf("%d\n",ans);
    }

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-14 23:43:01

HNU13383:The Big Painting的相关文章

HDU - 4810 Wall Painting(组合数学)

Description Ms.Fang loves painting very much. She paints GFW(Great Funny Wall) every day. Every day before painting, she produces a wonderful color of pigments by mixing water and some bags of pigments. On the K-th day, she will select K specific bag

Cube painting UVA 253

说说:一看到给立方体染色,开始还有点小害怕.毕竟高中数学里染色问题从来都不会简单.这道题的意思就是给立方体的六个面染色,然后判断两个染了色的立方体是否一样.其实仔细一想,立方体无非三对面,若开始确定两对面.如下面图Figure 1所示:假设1,2,6,5这四个面先确定(这只有唯一一种情况)之后,再放3,4,的时候无非两种情况.但这两种情况是不一样的,这也许就是题目所说的reflection.开始的想法是找出三对面,然后比较是否相等即可,不过实在想不出怎样来排除reflection的情况.所以只能

Codeforces Round #256 (Div. 2) C. Painting Fence(分治贪心)

题目链接:http://codeforces.com/problemset/problem/448/C ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Line Painting

Line Painting Time limit: 2.0 secondMemory limit: 64 MB The segment of numerical axis from 0 to 109 is painted into white color. After that some parts of this segment are painted into black, then some into white again and so on. In total there have b

Codeforces Gym 100342C Problem C. Painting Cottages 转化题意

Problem C. Painting CottagesTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the settl

DataGridView重绘painting简单实例

private void dataGridViewX1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex>=0) { Rectangle newRect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - 1, e.CellBounds.

Painting and Drawing[MSDN/Windows GDI]

https://msdn.microsoft.com/en-us/library/dd162759(v=vs.85).aspx Painting and Drawing This overview describes how the system manages output to the screen and explains what applications must do to draw in a window. In particular, this overview describe

[ACM] ZOJ 3725 Painting Storages (DP计数+组合)

Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with e

ural 1019 Line Painting(线段树)

题目链接:ural 1019 Line Painting 题目大意:一个0~1e9的区间,初始都是白的,现进行N次操作,每次将一段区间图上一中颜色.最后问说连续最长的白色区间. 解题思路:线段树区间合并,每个节点即维护一个区间,很经典.注意坐标需要离散化,但是还是要将0和1e9放进去. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn