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: ...
随机推荐
- STL_std::iterator
1. VC6里面 看到,std::iterator 就是一个指针,但是 vs2010中貌似不是这样(感觉像是一个类...具体是啥还不太确定...)... 2.
- java入门书籍很少介绍的java知识
1.java中数组的长度可以用.length来确定 2.java中的Arrays类可以对数组进行轻松的操作 (1).包名:import java.util.Arrays (2).Arrays.sort ...
- 深度学习框架Keras安装
环境:Windows 10 64位 版本!版本!版本!不要下载最新版本的! 一点要按照这个来!安装顺序也最好不要错! 首先安装DirectX SDK工具包 ,这是链接:https://www.micr ...
- Vultr新推出3.5美元/月套餐,并且支持微信支付了
先前Vultr重新推出了2.5美元/月的套餐,但是不支持IPv4,所以不那么受国内朋友的欢迎,迫于压力,这不最近就推出了3.5美元/月的套餐了,这个套餐是支持IPv4的,有需要的朋友可以上车了,htt ...
- python怎样压缩和解压缩ZIP文件
https://zhidao.baidu.com/question/1498409764366387259.html
- English trip -- VC(情景课)3 B Bamily members
xu言: 今天,好困啊 -__-. . zZ 早点睡吧...适当的休息,才能更好的学习 Vocabulary focus husband wife uncle aunt brother sister ...
- EF学习-获取实体框架01
实体框架由 EF 设计器(包含在 Visual Studio 中)和 EF Runtime(在 NuGet 上提供)组成. EF 设计器包含在 Visual Studio 中 最新版本的实体框架设计器 ...
- java final修饰变量时的一种情况
有如下一种场景. 1.在文件PaymentConfig.java中存在如下变量public static final desc="描述" 2.类Test.java中使用了desc变 ...
- Android设计模式之工厂模式
定义 工厂模式是我们最常用的实例化对象模式了,是用工厂方法代替new操作的一种模式.著名的Jive论坛 ,就大量使用了工厂模式,工厂模式在Java程序系统可以说是随处可见.因为工厂模式就相当于创建实例 ...
- 『PyTorch』第十六弹_hook技术
由于pytorch会自动舍弃图计算的中间结果,所以想要获取这些数值就需要使用钩子函数. 钩子函数包括Variable的钩子和nn.Module钩子,用法相似. 一.register_hook impo ...