Combinatorics——HDUOJ 1510
来源:互联网 发布:高级人体建模软件 编辑:程序博客网 时间:2024/05/21 09:45
原题:
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
1 2
112233445566778899 998877665544332211Sample Output
2
.#
..
4
..#.
##. #
.#..
.#.#
解题思路:
- 循环遍历延伸,直接暴力检测(HOJ在这道题上的测试数据有点水)
代码:
#include<stdio.h>#include <iostream>using namespace std;char W[101][101];int SUM;void Calculate(short N){ short i, j, k, l, temp; for(i = 1; i <= N; i++) for (j = 1; j <= N; j++){ temp = N; if(W[i][j] == '#')continue; SUM++;//此块为白块 for (k = j; k <= N; k++){ if(k != j){ if (W[i][k] == '#')break; SUM++; } for (l = i + 1; l <= temp; l++){ if (W[l][k] == '#') { temp = l - 1; break; } SUM++; } } }}int main(){ short N, i, j; while (scanf("%d",&N)!=EOF) { memset(W, '0', sizeof(W)); SUM = 0; for (i = 1; i <= N; i++)//行 for (j = 1; j <= N; j++)//列 cin >> W[i][j];//无需考虑清空缓存 Calculate(N); printf("%d\n", SUM); }}
- Combinatorics——HDUOJ 1510
- Combinatorics——HDUOJ 1027
- Combinatorics——HDUOJ 1085
- Combinatorics——HDUOJ 1100
- Combinatorics——HDUOJ 1171
- Combinatorics——HDUOJ 1261
- Combinatorics——HDUOJ 1398
- Combinatorics——HDUOJ 1028
- Combinatorics——HDUOJ 1294
- Combinatorics——HDUOJ 1465
- Combinatorics——HDUOJ 1492
- Combinatorics——HDUOJ 1521
- Combinatorics——HDUOJ 2110
- hduoj 4196 ——Remoteland
- BigNums——HDUOJ 1002
- BigNums——HDUOJ 1042
- BigNums——HDUOJ 1047
- BigNums——HDUOJ 1063
- 从浏览器地址栏输入URL到页面加载完成的过程中都发生了那些事情?
- mysql5.7官网直译SQL语句优化--嵌套连接的优化
- 查看哪个sql使用临时段比较多
- 【UI】SnackBar使用
- 理解ResNet结构与TensorFlow代码分析
- Combinatorics——HDUOJ 1510
- 决策树算法代码实现及注释(代码来自于机器学习实战)
- 原来灭火器要这样用
- bufferknife框架的配置方式
- python科学计算之numpy——ufunc函数
- CentOS7安装mysql
- 无限轮播 viewpager
- spark与scala版本问题
- VirtualBox虚拟机网络设置(四种方式)