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. |
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;
}