ACM —— 1009 Edge Detection

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

解题代码:

package acm1009;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static int mWidth, mHight;
	static int[][] pairs = new int[1009][2];
	static HashMap<Integer, Integer> outMap = new HashMap<Integer, Integer>();
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		while ((mWidth = stdin.nextInt()) != 0) {
			int num = 0;
			int totleLen = 0;
			outMap.clear();
			while (!(((pairs[num][0] = stdin.nextInt()) == 0)&((pairs[num][1] = stdin.nextInt()) == 0))) {
				totleLen += pairs[num++][1];
			}
			mHight = totleLen/mWidth;
			findEdges(num);
			outputImage(totleLen);
		}
		System.out.println("0");
	}
	
	private static void outputImage(int totleLen) {
		System.out.println(mWidth);
		Object[] keySet = outMap.keySet().toArray();
		Arrays.sort(keySet);
		int tempKey = Integer.parseInt(keySet[0].toString());
		int temp = outMap.get(tempKey);
		for (Object k : keySet) {
			int key = Integer.parseInt(k.toString());
			if (outMap.get(key) == temp) {
				continue;
			}
			System.out.println(temp + " " + (key -tempKey));
			temp = outMap.get(key);
			tempKey = key;
		}
		System.out.println(temp + " " + (totleLen -tempKey));
		System.out.println("0 0");
	}

	private static void findEdges(int num) {
		int pos = 0;
		int x,y;
		for (int p = 0; p <= num; p++) {
			x = pos/mWidth;
			y = pos%mWidth;
			for (int i = x-1; i <= x+1; i++) {
				if (i < 0|| i >= mHight) {
					continue;
				}
				for (int j = y-1; j <=y+1; j++) {
					if (j < 0||j >= mWidth) {
						continue;
					}
					int currPos = i*mWidth + j;
					outMap.put(currPos, getMaxValue(currPos));
				}
			}
			pos += pairs[p][1];
		}
	}
	
	private static Integer getMaxValue(int currPos) {
		int num=getnum(currPos),ret=0;
		   
	    int row=currPos/mWidth;
	    int col=currPos%mWidth;
	   
	    for (int i=row-1;i<=row+1;i++) {
			if (i < 0|| i >= mHight) {
				continue;
			}
	        for (int j=col-1;j<=col+1;j++)
	        {
	            int tpos= i*mWidth+j;
	            if (j<0||j>=mWidth|| tpos==currPos)
	                continue;
	               
	            int tmp=getnum(tpos);
	            if (Math.abs(tmp-num)>ret)ret=Math.abs(tmp-num);
	        }
	    }
	    return ret;
	}

	private static int getnum(int currPos) {
	    int p=0,i=0;
	    while (p<=currPos)
	        p+=pairs[i++][1];
	       
	    return pairs[i-1][0];
	}

}


注意* 跳跃式计算,第一个点和最后一个点要单算,不然会WA!

 

北京大学ACM Problems 1009Edge Detection Edge Detection Time Limit:1000MS Memory Limit:10000K Total Submissions:25273 Accepted:6065 Description IONU Satellite Imaging, Inc. records and stores very large images using run length encoding. You are to write a program that read... 阅读详情

相关推荐

【信息科学与工程学】【通信工程】第八十六篇 通信网络设备及通信网络组网的所有学科知识01

编号001类型网络虚拟化与覆盖技术网络领域数据中心网络子领域大二层网络 / 网络虚拟化核心数学方程式/算法模型核心算法:VXLAN封装与解封装。关键在于24位VNI(虚拟网络标识符)到物理网络的三层IP地址的映射。封装:收到原始以太帧后,为其添加 VXLAN 头部(含 VNI)、外层 UDP 头(目的端口 4789)、外层 IP 头(源 IP 为本地 VTEP IP,目的 IP 为对端 VTEP IP)以及外层 MAC 头。解封装:对端 收到报文后,剥离外层头部,根据内层帧的目的 MAC 和 VNI 进行二

weixin_49199313的博客 643

Awesome-Edge-Detection-Papers:边缘轮廓边界检测文件和工具箱的集合

真棒边缘检测纸 边缘检测论文和相应的源代码/演示程序(也称为轮廓检测或边界检测)的集合。 随时创建PR或问题。 (首选“拉式请求”) 大纲 0.边缘检测相关数据集 简称 原始纸 来源 介绍 TPAMI 2011 经典边缘检测数据集。 CVPR 2013 边缘来自带注释的分割蒙版的边界。 视觉研究2016 带边界注释。 CVPR 2020 边缘来自带注释的线框。 1.基于深度学习的方法 1.1常规边缘检测 简称 纸 来源 代码/项目链接 数码光盘 ACM MM 2020年 德西尼德 WACV 2020 BDCN CVPR 2019 RCN CAIP 2019 线路板 ECCV 2018 AMH网 NIPS 2017 RCF CVPR 2017 CED CVPR 2017 COB ECCV 2016 RDS CVPR 2016 HFL ICCV 2015 HE

POJ1009-Edge Detection

北大POJ1009-Edge Detection 解题报告+AC代码

北大oj1009——Edge Detection

Edge Detection | Time Limit: 1000MS | | Memory Limit: 10000K | Description IONU Satellite Imaging, Inc. records and stores very large images using run length encoding. You are to write a program tha...

m0_37609239的博客 298

POJ 1009 解题报告 Edge Detection

1009是痛苦的一题啊。游程编码问题。 先说思路:只处理变化的点。产生变化的点会影响周围的8个点的编码。没有产生变化的点的编码值与前一天相同。当然,有几个特殊情况需要注意。 先上代码: #include #include #include using namespace std; typedef class Point { public: int iFirst; int i

Today is a gift 5876

POJ_1009_Edge Detection

/* ----------思路简述---------- 输入图像 输出图像 1、1、1 → 2、2、2 1、3、3 → 2、2、2 3、3、3 → 2、2、0 图像的改变位置为临近中间3的周围7个点及中间3本身; 事实上,“输出图像的重复序列的起点”只可能在“原图像的重复序列的起点”的相邻点及该点本身; 所

HOH_mizukun的博客 559

PKU ACM 1009 Edge Detection 边缘提取算法

题目链接:Edge Detection 边缘提取算法   题目描述: 对输入图像进行边缘提取,算法是分别计算当前像素和周围8个像素之间的差,最大值就是提取后的像素值。 输入图像和输出图像都按照游程编码存储。 主要思路: 不能计算每个像素的值,会导致TL。其实,只在

咔嚓!~咔嚓!~ 1599

北大ACM(POJ1009-Edge Detection)

Question:http://poj.org/problem?id=1009问题点:RLE编码。 1 Memory: 648K Time: 547MS 2 Language: C++ Result: Accepted 3 4 #include <iostream> 5 #include <cstdlib> ...

aenv6574的博客 173

北大ACM 1009题—Edge Detection

Edge Detection Time Limit:1000MS Memory Limit:10000K Total Submissions:15307 Accepted:3445 Description IONU Satellite Imaging, Inc. records and stores very larg...

weixin_30258901的博客 257

POJ 1009 Edge Detection(模拟)

Edge Detection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17586   Accepted: 4020 Description IONU Satellite Imaging, Inc. records and stores very larg

风尘_浪子 1070

杭电ACM1009

题目: Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room con...

QLSDXF的博客 424

杭电OJ——ACM 1009.FatMouse‘ Trade

肥老鼠换东西,m磅猫食,n间房子,每个房间有J[i]磅JavaBean,对应一个猫守卫需要F[i]磅猫食,可以按比率获取JavaBean,怎样才能获得最大数量的JavaBean。

peng_YuJun的博客 872

HDU 1175(搜索题,BFS)

连连看<br />Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 2678    Accepted Submission(s): 608<br /><br />Problem Description“连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条

-- bird -- 1153

连连看

Problem Description “连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子),而且线的转折次数不超过两次,那么这两个棋子就可以在棋盘上消去。不好意思,由于我以前没有玩过连连看,咨询了同学的意见,连线不能从外面绕过去的,但事实上这是错的。现在已经酿成大祸,就只能将

my dream is possible 1173

[POJ][1009]Edge Detection

Description IONU Satellite Imaging, Inc. records and stores very large images using run length encoding. You are to write a program that reads a compressed image, finds the edges in the image, as d

软件工程学森 2793

HDU-1033-Edge(C++ && 简单模拟 && 题意恶心)

Edge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2314    Accepted Submission(s): 1477 Problem Description For products that are

保持对编程的热情! 1766

POJ 1009 Edge Detection(图像边缘检测)

Description 给出一张数字图,对于每个像素点求出这个点与其周围所有点差的绝对值的最大值 Input 多组输入,每组数据第一行为一个整数n(n Output 对于每组输入,在求出每个像素点与其周围点差的绝对值后按输入格式输出,即第一行为n,中间为每个数字连续段的数值和长度,以0 0结束每组输出,以0结束全部输出 Sample Input

ZSQ 2690
上一篇: ACM —— 1008 Maya Calendar
下一篇: ACM —— 1010 STAMPS
WYYZ5
博客等级 码龄16年 19粉丝 55原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值