hnu 13191 Folded Map

Folded Map
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB
Total submit users: 5, Accepted users: 4
Problem 13191 : No special judgement
Problem description

Freddy’s garden became so large that he needs a map to keep evidence of which vegetables are planted in what area. He ordered a high-quality map from the International Cartographic Publishing Company (ICPC). Since the map has a large scale, it does not fit onto a single page and it has to be split into several rectangular tiles.

Even with a fixed tile size (determined by a page size) and map scale, the number of tiles may still differ by adjusting the position of the tile grid. Your task is to find the minimal number of tiles necessary to cover the whole region of Freddy’s garden.



Let’s have a look at an example. The figure on the left shows 14 map tiles covering a region. By adjusting the grid position a little bit, we may cover the same region with only 10 tiles, without changing their size or orientation.

Note that the tiles must be part of a rectangular grid aligned with the x-axis and y-axis. That is, they touch each other only with their whole sides and cannot be rotated.


Input


Output

For each test case, print one integer number — the minimal number of tiles necessary to cover all pixels represented by “X”.


Sample Input
3 3 2 2
XXX
XXX
XXX
3 3 2 2
XX.
XXX
XXX
17 32 5 9
........XXXXXXXX................
........XXXXXXXX................
........XXXXXXXX................
........XXXXXXXXX...............
........XXXXXXXXXXXXXXX.........
........XXXXXXXXXXXXXXXXXXXX....
........XXXXXXXXXXXXXXXXXXXXX...
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..
..XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
....XXXXXXXXXXXXXXXXXXXXXXXXXXX.
......XXXXXXXXXXXXXXXXXXXXXXXXX.
........XX..XXXXXXXXXXXXXXXXX...
.............XXXXXXXXXXXXXX.....
...............XXXXXXXXX........
................XXXXXXX.........
.................XXXXX..........
....................XXX.........
Sample Output
4
3
10

给一个大的矩形 里面有X或者. 要用小矩形把这些X进行覆盖 求最少的小矩形的个数

以小矩形为单位 记录矩形内包含的X的情况 

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

void read(int &x)
{
    char ch;
    x=0;
    while(ch=getchar(),ch!=' '&&ch!='\n')
    {
        x=x*10+ch-'0';
    }
}

int a,b,c,d;
char map[1200][1200];
int data[1200][1200];
int cntr[1200][1200],cntc[1200][1200];

int get_num(int rr,int cc)
{
    int ret=0;
    for(int i=rr;i<a+c;i+=c)
    {
//        cout<<i<<endl;
        for(int j=cc;j<b+d;j+=d)
        {
            if(cntc[i][j]>0)
                ret++;
        }
    }
//    bug;
    return ret;
}

int main()
{
//    fread;

    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
    {
        getchar();
        for(int i=0;i<a;i++)
            scanf("%s",map[i]);
        for(int i=0;i<a;i++)
            for(int j=0;j<b;j++)
                data[i][j]=(map[i][j]=='X');
        for(int i=0;i<a+c;i++)
        {
            int cnt=0;
            for(int j=0;j<b+d;j++)
            {
                if(i<a&&j<b&&data[i][j])
                    cnt++;
                if(i<a&&j>=d&&data[i][j-d])
                    cnt--;
                cntr[i][j]=cnt;
            }
        }
        for(int j=0;j<b+d;j++)
        {
            int cnt=0;
            for(int i=0;i<a+c;i++)
            {
                cnt+=cntr[i][j];
                if(i>=c)
                    cnt-=cntr[i-c][j];
                cntc[i][j]=cnt;
            }
        }
//        for(int i=0;i<a+c;i++)
//        {
//            for(int j=0;j<b+d;j++)
//                cout<<cntc[i][j]<<" ";
//            cout<<endl;
//        }
        int ans=1200*1200;
        for(int i=0;i<c;i++)
            for(int j=0;j<d;j++)
                ans=min(ans,get_num(i,j));
        printf("%d\n",ans);
    }
    return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值