TJU Problem 1090 City hall
注:对于每一横行的数据读取,一定小心不要用int型,而应该是char型或string型。
原题:
1090. City hall
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 4874 Accepted Runs: 2395
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的更多相关文章
- 天大 ACM 1090. City hall
此题的关键就在你是如何选择来计算需要加进去的砖块,是从小的height开始还是从大的height开始.本题是新建一个数组用来存储从最大的(最大的height)砖头开始的砖头数.代码中“for(int ...
- TJU Problem 2101 Bullseye
注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...
- TJU Problem 2548 Celebrity jeopardy
下次不要被长题目吓到,其实不一定难. 先看输入输出,再揣测题意. 原文: 2548. Celebrity jeopardy Time Limit: 1.0 Seconds Memory Lim ...
- TJU Problem 2857 Digit Sorting
原题: 2857. Digit Sorting Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 3234 Accepted ...
- TJU Problem 1015 Gridland
最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 做这题时,千万不要被那个图给吓着了,其实这题就是道简 ...
- TJU Problem 1065 Factorial
注意数据范围,十位数以上就可以考虑long long 了,断点调试也十分重要. 原题: 1065. Factorial Time Limit: 1.0 Seconds Memory Limit ...
- TJU Problem 1100 Pi
注: 1. 对于double计算,一定要小心,必要时把与double计算相关的所有都变成double型. 2. for (int i = 0; i < N; i++) //N 不 ...
- TJU Problem 2520 Quicksum
注意: for (int i = 1; i <= aaa.length(); i++) 其中是“ i <= ",注意等号. 原题: 2520. Quicksum Time L ...
- TJU Problem 1644 Reverse Text
注意: int N; cin >> N; cin.ignore(); 同于 int N; scanf("%d\n",&N); 另:关于 cin 与 scanf: ...
随机推荐
- 使用innerHTML时要注意的一点
为某个元素添加内容时,使用的是document.getElementsByClassName,由于只有一个元素拥有这样的ClassName,就直接这样用,document.getElementsByC ...
- Codeforces 534B - Covered Path
534B - Covered Path 思路:贪心,每一秒取尽可能大并且可以达到的速度. 画张图吧,不解释了: 代码: #include<bits/stdc++.h> using name ...
- ASCII 和 Unicode 编码的由来
大话数据结构上的说明: 网络博文的说明:
- 关于 [TNS-12516 TNS:listener could not find instance with matching protocol stack ]
Title: Intermittent TNS-12516 or TNS-12519 Errors Connecting Via Net Symptom(s) ~~~~~~~~~~ Client co ...
- (Gorails)vuejs系列视频: Webpacker/vue-resource(不再为官方推荐)。
频:https://gorails.com/episodes/using-vuejs-for-nested-forms-part-1?autoplay=1 在嵌套表格上使用vue.js. 在appli ...
- 『Python』pycharm常用设置
学习一下pycharm的快捷操作,提升速度,也提升舒适度,笑. 常用快捷键 ctrl + d :复制粘贴本行到下一行 ctrl + y :删除本行 ctrl + 鼠标点击 :跳转 ctrl + / : ...
- python-day21--序列化模块模块
什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化 序列化的目的: 1.以某种存储形式使自定义对象持久化: 2.将对象从一个地方传递到另一个地方. 3.使程序更具维护性. ...
- JS-图片控制-动画管理模块
animateManage.js ;(function(window,document,undefined){ var _aniQueue = [], //动画队列 --- ani:动画,Queue: ...
- python 使用yield进行数据的流式处理
demo:从文件中取包含字符“a”的5行数据做一次批处理!!! # coding: utf-8 import time def cat(f): for line in f: yield line de ...
- 关于向后台请求数据(get请求,无参数传递),返回html代码(实际需要返回的是json数据)的解决方案
this.$http.get(apis.schoolVideo, { headers: { 'X-Requested-With': 'XMLHttpRequest' } }) 待续