注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型。

原题:

1090.   City hall


Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 4874   Accepted Runs: 2395

Because of its age, the City Hall has suffered damage to one of
its walls. A matrix with M rows and N columns represents the
encoded image of that wall, where 1 represents an intact wall and 0 represents a
damaged wall (like in Figure-1).

1110000111

1100001111

1000000011

1111101111

1110000111

Figure-1

To repair the wall, the workers will place some blocks vertically into the damaged area. They can use blocks with a fixed width of 1 and different heights of {1, 2, ..., M}.

For a given image of the City Hall's wall, your task is to determine how many blocks of different heights are needed to fill in the damaged area of the wall, and to use the least amount of blocks.

Input

There is only one test case. The case starts with a line containing two integers M and N (1 ≤ M, N ≤ 200). Each of the following M lines contains a string with length of N, which consists of "1" s and/or "0" s. These M lines represent the wall.

Output

You should output how many blocks of different heights are needed. Use separate lines of the following format:

k Ck

where k∈{1,2, ..., M} means the height of the block, and Ck means the amount of blocks of height k that are needed. You should not output the lines where Ck = 0. The order of lines is in the ascending order of k.

Sample Input

5 10
1110000111
1100001111
1000000011
1111101111
1110000111

Sample Output

1 7
2 1
3 2
5 1

Source: Asia - Beijing
2004 Practice

 

源代码:

 #include <iostream>
using namespace std; char board[][];
int x, y, m, sum = ;
int book[]; int find(int x, int y) {
if (board[x][y] == '') {
return sum;
}
else if (board[x][y] == '') {
sum++;
board[x][y] = '';
find (x+, y);
}
} int main() {
int n; cin >> m >> n;
for (int i = ; i < m + ; i++) book[i] = ;
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
board[i][j] = '';
for (int i = ; i < m; i++)
for (int j = ; j < n; j++)
cin >> board[i][j]; for (int i = ; i < m; i++) {
for (int j = ; j < n; j++) {
if (board[i][j] != '') {
int res = find(i, j);
sum = ;
//cout << res << endl;
book[res]++;
}
}
} for (int i = ; i <= m; i++) {
if (book[i] != ) {
int a = book[i];
cout << i << " " << a << endl;
}
} return ;
}

TJU Problem 1090 City hall的更多相关文章

  1. 天大 ACM 1090. City hall

    此题的关键就在你是如何选择来计算需要加进去的砖块,是从小的height开始还是从大的height开始.本题是新建一个数组用来存储从最大的(最大的height)砖头开始的砖头数.代码中“for(int ...

  2. TJU Problem 2101 Bullseye

    注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...

  3. TJU Problem 2548 Celebrity jeopardy

    下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548.   Celebrity jeopardy Time Limit: 1.0 Seconds   Memory Lim ...

  4. TJU Problem 2857 Digit Sorting

    原题: 2857.   Digit Sorting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 3234   Accepted ...

  5. TJU Problem 1015 Gridland

    最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 做这题时,千万不要被那个图给吓着了,其实这题就是道简 ...

  6. TJU Problem 1065 Factorial

    注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065.   Factorial Time Limit: 1.0 Seconds   Memory Limit ...

  7. TJU Problem 1100 Pi

    注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++)         //N 不 ...

  8. TJU Problem 2520 Quicksum

    注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520.   Quicksum Time L ...

  9. TJU Problem 1644 Reverse Text

    注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: ...

随机推荐

  1. WCF 客户端调用服务操作的两种方法

    本节的主要内容:1.通过代理类的方式调用服务操作.2.通过通道的方式调用服务操作.3.代码下载 一.通过代理类的方式调用服务操作(两种方式添加代理类) 1.手动编写代理类,如下: 客户端契约: usi ...

  2. Java的八种基本类型:(按字节来分)

    Java的八种基本类型:(按字节来分) boolean   布尔型   1个字节 8bit(8位) byte     字节类型   1个字节 char     字符类型   2个字节 short    ...

  3. ubuntu 常用设置

    ●1 问题:使用virt-manager创建虚拟机时,Virtual network 'default':NAT(Inactive) 解决方法:1,查看网络状态sudo virsh net-list ...

  4. HDU 2569 彼岸

    彼岸 思路:动态规划.因为不能有连续三个不同的颜色,所以只要看最后三个就可以了. 设dp[n]为长度为n到达彼岸的方案数. ①当第n-2个颜色和第n-1个颜色相同时,第n个位置可以取任意一种颜色,dp ...

  5. python3 操作windows的粘贴板(读取和传值)

    #!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = "loki" import win32con import wi ...

  6. poj2686 状压dp入门

    状压dp第一题:很多东西没看懂,慢慢来,状压dp主要运用了位运算,二进制处理 集合{0,1,2,3,....,n-1}的子集可以用下面的方法编码成整数 像这样,一些集合运算就可以用如下的方法来操作: ...

  7. JavaWeb重定向和转发

    if (user != null && passWord.equals(user.getPassWord())) { // 登录成功 // response.sendRedirect( ...

  8. Oracle12c中性能优化&amp;功能增强新特性之全局索引DROP和TRUNCATE 分区的异步维护

    Oracle 12c中,通过延迟相关索引的维护可以优化某些DROP和TRUNCATE分区命令的性能,同时,保持全局索引为有效. 1.   设置 下面的例子演示带全局索引的表创建和加载数据的过程. -- ...

  9. pip install flask 安装失败

    地址:http://www.zhihu.com/question/21492455

  10. c++理解析构函数

    析构函数有2种方式调用,一个是主动调用delete,另一个是根据RAII的规则,在对象的生命周期结束时自动析构.第一点没什么好说的,就简单讲下第二点. 对象的生命周期不等于是程序的生命周期,一般我们所 ...