记录编号 |
121167 |
评测结果 |
AAAAAAAAAA |
题目名称 |
剪切矩形 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.289 s |
提交时间 |
2014-09-18 17:22:05 |
内存使用 |
20.74 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define scnaf scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
const int MAXN=1010;
int row,col;
int Up[MAXN][MAXN],Left[MAXN][MAXN],S[MAXN][MAXN],Min[MAXN][MAXN],Max[MAXN][MAXN];
char pic[MAXN][MAXN];
LL res=0;
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="rectangle";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d%d",&row,&col);row--;col--;
cin.ignore(10,10);
For(i,0,row)
cin.getline(pic[i],2333);
memset(Left,0,sizeof(Left));
memset(Up,0,sizeof(Up));
For(i,0,col)
if (pic[0][i]=='.')
{
Up[0][i]=1;
Left[0][i]=i==0?1:Left[0][i-1]+1;
res+=Left[0][i];
S[0][i]=Min[0][i]=Max[0][i]=Left[0][i];
}
For(i,1,row)
For(j,0,col)
if (pic[i][j]=='.')
{
Left[i][j]=j==0?1:Left[i][j-1]+1;
S[i][j]=S[i-1][j]+Left[i][j];//S[i][j]表示1..i行第j列所有left和。
Min[i][j]=Min[i-1][j];
Max[i][j]=Max[i-1][j];
if (Left[i][j]<Min[i][j])
{
Min[i][j]=Left[i][j];
S[i][j]=Left[i][j]*(i+1);
}
else if (Left[i][j]<Max[i][j])
{
S[i][j]=0;
int nr=i;
while (nr>=0&&Left[i][j]<Max[nr][j])
{
S[i][j]+=Left[i][j];
nr--;
}
if (nr>=0)
S[i][j]+=S[nr][j];
}
res+=S[i][j];
Max[i][j]=(Max[i][j],Left[i][j]);
}
pritnf("%lld\n",res);
#ifdef DEBUG
clock_t End_Time=clock();
printf("\n\nTime Used: %.4lf Ms\n",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif
return 0;
}
//================fuction code====================