White Rectangles[HDU1510]
White Rectangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 732 Accepted Submission(s): 368
Problem Description
You are given a chessboard made up of N squares by N squares with equal size. Some of the squares are colored black, and the others are colored white. Please write a program to calculate the number of rectangles which are completely made up of white squares.
Input
There are multiple test cases. Each test case begins with an integer N (1 <= N <= 100), the board size. The following N lines, each with N characters, have only two valid character values:
# - (sharp) representing a black square;
. - (point) representing a white square.
Process to the end of file.
Output
For each test case in the input, your program must output the number of white rectangles, as shown in the sample output.
Sample Input
2
.#
..
4
..#.
##.#
.#..
.#.#
Sample Output
5
15
Author
JIANG, Ming
Source
ZOJ Monthly, January 2004
Recommend
xhd
Enrich my knowledge again.In English ,left corner means the corner on the left and up side of a rectangle,and bottom left means the left and down side of a rectangle,and right side as well.It seems that the word "corner" contains the significance of up side.
Enumerate the left corner of the rectangles ,just count it.
#include<stdio.h>
#include<string.h>
int f[][];
char ch[][];
int main()
{
int n,i,j;
while (scanf("%d",&n)!=EOF)
{
for (i=;i<=n;i++) scanf("%s",&ch[i][]);
memset(f,,sizeof(f));
int ans=;
for (i=;i<=n;i++)
for (j=n;j>=;j--)
if (ch[i][j]=='.') f[i][j]=f[i][j+]+;
for (i=;i<=n;i++)
for (j=;j<=n;j++)
{
int maxlen=f[i][j],v=;
while (maxlen)
{
ans+=maxlen;
v++;
if (f[i+v][j]<maxlen) maxlen=f[i+v][j];
}
}
printf("%d\n",ans);
}
return ;
}
White Rectangles[HDU1510]的更多相关文章
- HDU1510 White rectangles
White Rectangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU1510 White rectangles( 乱搞 O(n^3) )题解
思路: 友谊赛的时候一直想到了,但是没想出来怎么遍历才能找到所有矩阵,卡住了. 这里讲一下完整思路:我们用一个num[i][j]表示第i行第j列每一列连续的白色格子数量,然后我们定义一个MIN,并且每 ...
- 【HDOJ】1510 White Rectangles
这个题目很好,变形的题目也很多.简单DP. /* 1510 */ #include <cstdio> #include <cstring> #include <cstdl ...
- zoj 2067 White Rectangles
这题解决的算法处理,真的很难想清楚!!尤其是最后的正矩形如何处理.不过终于看懂了 #include<stdio.h> #include<stdlib.h> #include&l ...
- PS网页设计教程XXIV——从头设计一个漂亮的网站
作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...
- Gazebo機器人仿真學習探索筆記(三)機器人模型
gazebo_models:https://bitbucket.org/osrf/gazebo_models 模型庫下載,可以參考如下命令: ~/Rob_Soft/Gazebo7$ hg clone ...
- 【图像处理】Haar-like特征
特征提取的原理.代码等: 如果是白黑白,是减去一个黑的还是2个黑的,网上有不同的说法:应该需要看原论文了. 论文原文 The sum of the pixels which lie within th ...
- Viola–Jones object detection framework--Rapid Object Detection using a Boosted Cascade of Simple Features中文翻译 及 matlab实现(见文末链接)
ACCEPTED CONFERENCE ON COMPUTER VISION AND PATTERN RECOGNITION 2001 Rapid Object Detection using a B ...
- woj1012 Thingk and Count DP好题
title: woj1012 Thingk and Count DP好题 date: 2020-03-12 categories: acm tags: [acm,dp,woj] 难题,dp好题,几何题 ...
随机推荐
- 在Mysql中如何显示所有用户?
这是一个mysql初学者经常问到的一个问题,今天我们就带大家看看是如何在Mysql中显示所有用户的.通常我们在mysql中使用SHOW DATABASES可以显示所有的数据库,SHOW TABLES将 ...
- linux下软件安装的方法
linux下软件的安装与卸载 第一章 linux下安装软件,如何知道软件安装位置 注:一般的软件的默认安装目录在 jdk-1_6_0_14-linux-i586-rpm.bin ←修改为 ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- Android程序启动加载动画实现
package com.example.bmob_test.ui;//程序启动动画,图片颜色由浅到深,方法一 import com.example.bmob_test.LogActivity; imp ...
- linux awk 内置函数详细介绍(实例)
这节详细介绍awk内置函数,主要分以下3种类似:算数函数.字符串函数.其它一般函数.时间函数 一.算术函数: 以下算术函数执行与 C 语言中名称相同的子例程相同的操作: 函数名 说明 atan2( y ...
- RPM软件包管理的查询功能
以后大家升级rpm包的时候,不要用Uvh了! 我推荐用Fvh 前者会把没有安装过得包也给装上,后者只会更新已经安装的包 总结:未安装的加上小写p,已安装的不需要加p 查询q rpm {- ...
- 如何使用setup.py文件
setup.py文件的使用:% python setup.py build #编译% python setup.py install #安装% python setup.py sdist ...
- 【Linux】为啥查某个进程的线程,查出来的所有线程的pid不一样啊
楼上说的linux线程和进程是一样的,这个说法是错误的. 看了楼主的问题,感觉楼主是被PID给弄混了,线程进程都会有自己的ID,这个ID就叫做PID,PID是不特指进程ID,线程ID也可以叫做PID. ...
- 【转】Eclipse中查看jar包中的源码
(简单的方式:通过jd-gui来进行反编译,最简单!,参考我的另一篇博文, 地址:http://www.cnblogs.com/gmq-sh/p/4277991.html) Java Decompil ...
- 玩转ubuntu FAQ
一.用wubi安装ubuntu的时候自动重新下载 1.双击ubuntu.ios让windows加载这个镜像 2.断开网络 二.安装其他程序时提示Error: Dependency is not sat ...