图像有用区域1
来源:互联网 发布:linux telnet连接失败 编辑:程序博客网 时间:2024/04/29 19:24
package 搜索;
import java.util.Scanner;
/*
* 黑色外涂黑
* 0外面的涂0
*/
public class 图像有用区域1 {
static int w;
static int h;
static int arr[][];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
w = sc.nextInt();
h = sc.nextInt();
arr = new int[h][w];
int i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
arr[i][j] = sc.nextInt();
}
}
operation();
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
if (arr[i][j] <= 0)
System.out.print(0 + " ");
else
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
private static void operation() {
int i, j;
// 从行出发,为什么要用非-1了,如果更改为0的话,下面的列遍历的时候遇到了0截止了,就导致结果错误
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}
for (i = 0; i < h; i++) {
for (j = w - 1; j >= 0; j--) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}
// 从列出发
for (j = 0; j < w; j++) {
for (i = 0; i < h; i++) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}//这里要从最后一行开始,扫描列
for (j = w - 1; j >= 0; j--) {
for (i = h - 1; i >= 0; i--) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}
}
}
import java.util.Scanner;
/*
* 黑色外涂黑
* 0外面的涂0
*/
public class 图像有用区域1 {
static int w;
static int h;
static int arr[][];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while (n-- > 0) {
w = sc.nextInt();
h = sc.nextInt();
arr = new int[h][w];
int i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
arr[i][j] = sc.nextInt();
}
}
operation();
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
if (arr[i][j] <= 0)
System.out.print(0 + " ");
else
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
private static void operation() {
int i, j;
// 从行出发,为什么要用非-1了,如果更改为0的话,下面的列遍历的时候遇到了0截止了,就导致结果错误
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}
for (i = 0; i < h; i++) {
for (j = w - 1; j >= 0; j--) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}
// 从列出发
for (j = 0; j < w; j++) {
for (i = 0; i < h; i++) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}//这里要从最后一行开始,扫描列
for (j = w - 1; j >= 0; j--) {
for (i = h - 1; i >= 0; i--) {
if (arr[i][j] == 0)
break;
arr[i][j] = -1;
}
}
}
}
0 0
- 图像有用区域1
- 图像有用区域
- NYOJ92-图像有用区域
- NYOJ 图像有用区域
- 图像有用区域
- 图像有用区域
- 图像有用区域
- 图像有用区域nyoj92
- acm_92图像有用区域
- 图像有用区域 bfs
- 图像有用区域
- nyoj--图像有用区域
- 图像有用区域
- 图像有用区域
- NYOJ92图像有用区域
- 图像有用区域
- 图像有用区域 【BFS】
- 图像有用区域
- Android中的状态选择器
- 安装xshell5时报程序集组件错误80070002
- Python数据分析之pandas学习
- 微信小程序开发者工具快捷键
- Hadoop HA高可用集群搭建
- 图像有用区域1
- SpringMVC入门之八:使用Apache Tiles视图定义布局
- 设计模式(4)-单例模式
- 图像有用区域_撞墙法
- [2015-12-29]position详解
- 支付宝被骗怎么办?
- 吝啬的国度_数组存储
- mongoDB使用方法
- 值得推荐的C/C++框架和库