WOJ1012-Think And Count
来源:互联网 发布:rimworld mac版下载 编辑:程序博客网 时间:2024/05/22 06:38
You are given a chessboard made up of N squares by M squares. 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.
输入格式
There are multiple test cases. Each test case begins with two integer N,M (1 <= N , M<= 2000), the board size. The following N lines, each with M
characters, have only two valid character values:
b - representing a black square;
w - representing a white square.
Process to the end of file.
输出格式
For each test case in the input, output the number of white rectangles a line.
样例输入
2 3bbbwww2 2bwwb
样例输出
62
#include <stdio.h>#include <string.h>int main(){ char in[2001]; long sign[2001], i, min, sum[2001], pre[2001], j, k, n, m, s, p; long long out; while (scanf("%ld %ld\n", &n, &m) != EOF) { for (i = 1; i <= m; i++) sign[i] = 0; for (s = 1, out = 0; s <= n; s++) { gets(in); for (i = 0; i < m; i++)//记录第i列到s行连续出现的白方块数,滚动数组1,处理单列上的白方块总数 { if (in[i] == 'w') sign[i + 1]++; else sign[i + 1] = 0; } for (i = 1, sign[0] = pre[0] = 0; i <= m; i++) { if (sign[i] >= sign[i - 1])//如果比前列的白方块数多,可以直接加入 { sum[i] = sum[i - 1] + sign[i];//滚动数组2,记录前i列的白方块总数 pre[i] = 0; } else { pre[i] = pre[i - 1] + 1; p = i - pre[i]; while (p > 0 && sign[p - 1] >= sign[i])//找出比这列sign[]小的列 p = p - pre[p - 1] - 1; if (p <= 0)//这列sign[]值最小 { sum[i] = sign[i] * i; pre[i] = 0; } else//p列sign[]值最小 { sum[i] = sign[i] * (i - p + 1) + sum[p - 1]; pre[i] = i - p - 1; } } out += sum[i]; } } printf("%lld\n", out); } return 0;}
阅读全文
0 0
- WOJ1012-Think And Count
- count(1) and count(*)
- think and do~
- Stop and Think about
- stop and think
- Think Globally and Act Locally
- delegate and event i think
- Think in Man and Woman
- day116 java and think(20140707)
- LeetCode: Count and Say
- [LeetCode]Count and Say
- LeetCode Count and Say
- [Leetcode] Count and Say
- Count and Say
- Leetcode: Count and Say
- [LeetCode] Count and Say
- LeetCode Count and Say
- Count and Say
- android 线程池使用全解
- PAT (Basic Level) Practise (中文) 1008. 数组元素循环右移问题 (20)
- 运算符 的介绍(%取余 和+连接)
- 安装jdk后的环境变量配置及其相关问题的解决
- centos7 修改mysql5.7默认端口后启动异常
- WOJ1012-Think And Count
- 设计模式之单例模式
- JS日期的处理工具类
- vue.js移动端app实战3:从一个购物车入门vue
- 美团点评编程笔试题
- gitlab安装与配置
- behavirtree 安装需要的库
- C++ Primer Plus第五章课后编程答案
- javabean与map互转