注:对于每一横行的数据读取,一定小心不要用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. 转载:理解RESTful架构

    http://www.ruanyifeng.com/blog/2011/09/restful.html 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件" ...

  2. windows与kali双系统安装基本教程

    以前写过一篇在虚拟机中安装kali的基本教程的文章,那时候的kali还是1.0时代,现如今已经kali2.0了,在虚拟机中运行kali还是会受到性能的影响,所以还是装到自己电脑上跑起来最爽.当然如果你 ...

  3. VcCallC#_01

    1.C# 代码: using System; using System.Collections.Generic; //using System.Linq; using System.Text; //u ...

  4. jsjl_for_ubuntu12.04

    1. VC++代码: #include <stdio.h> #include <windows.h> #include <wchar.h> void MoveMou ...

  5. 30分钟带你了解Springboot与Mybatis整合最佳实践

    前言:Springboot怎么使用想必也无需我多言,Mybitas作为实用性极强的ORM框架也深受广大开发人员喜爱,有关如何整合它们的文章在网络上随处可见.但是今天我会从实战的角度出发,谈谈我对二者结 ...

  6. Codeforces 847H - Load Testing

    847H - Load Testing 思路:dp. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  7. mac 下安装mongodb

    转载自https://segmentfault.com/a/1190000002547229 概念 MongoDB 是一个跨平台的,面向文档的数据库,提供高性能,高可用性和可扩展性方便. MongoD ...

  8. EF学习-获取实体框架01

    实体框架由 EF 设计器(包含在 Visual Studio 中)和 EF Runtime(在 NuGet 上提供)组成. EF 设计器包含在 Visual Studio 中 最新版本的实体框架设计器 ...

  9. 使用Maven + Jetty时,如何不锁定js css 静态资源

    Jetty会使用内存映射文件来缓存静态文件,包括js,css文件. 在Windows下,使用内存映射文件会导致文件被锁定,所以当Jetty启动的时候无法在编辑器对js或者css文件进行编辑. 解决办法 ...

  10. python-day47--pymysql模块

    一.安装导入 #安装 pip3 install pymysql 二.使用 1 .基本使用 import pymysql # 链接,拿到游标 conn=pymysql.connect(host='loc ...