注:对于每一横行的数据读取,一定小心不要用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. 查找SQL Server 自增ID值不连续记录

    在很多的时候,我们会在数据库的表中设置一个字段:ID,这个ID是一个IDENTITY,也就是说这是一个自增ID.当并发量很大并且这个字段不是主键的时候,就有可能会让这个值重复:或者在某些情况(例如插入 ...

  2. URLConnection和HttpClient使用入门

    本讲内容:URLConnection和HttpClient使用入门 在 Android中除了使用WebView控件访问网络以外,还有用代码方式访问网络的方法,代码方式有时候会显得更加灵活.本讲会介绍使 ...

  3. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

  4. C#开发框架学习

    C# 开源框架(整理) Json.NET http://json.codeplex.com/ Json.Net 是一个读写Json效率比较高的.Net框架.Json.Net 使得在.Net环境下使用J ...

  5. golang martini 源码阅读笔记之inject

    martini是go语言写的一个超级轻量的web开源框架,具体源码可在github搜索找到.13年那会开始接触go语言时有稍微看过这个框架,由于之后没有继续使用go就慢慢忽略了,最近由于手头项目可能会 ...

  6. 『Collections』namedtuple_具名元组

    namedtuple()类 需要两个参数,参数一为nametupe名称,参数二为字段一般为序列(多个字段) Python中存储系列数据,比较常见的数据类型有list,除此之外,还有tuple数据类型. ...

  7. 关于最短路的想法&&问题

    今天本想水几道floyd却被坑了:注意考虑<重边>!!!!!!!!!!!!!!! 小心图里出现的重边,如果不处理的话,必然WA!构图时一定要仔细!

  8. JavaScript学习总结(六)——JavaScript判断数据类型总结

    最近做项目中遇到了一些关于javascript数据类型的判断处理,上网找了一下资料,并且亲自验证了各种数据类型的判断,在此做一个总结吧! 一.JS中的数据类型 1.数值型(Number):包括整数.浮 ...

  9. Netty高性能编程备忘录(上)

    http://calvin1978.blogcn.com/articles/netty-performance.html 网上赞扬Netty高性能的文章不要太多,但如何利用Netty写出高性能网络应用 ...

  10. js上传图片前预览方法(支持预览多个图片)

    运用js实现上传图片前的预览(支持多张图片),实现的例子如下: 1.源码例子: 1)Js脚本页面 <!doctype html> <html> <head> < ...