poj 1009 Edge Detection
来源:互联网 发布:南风知我意txt下载七微 编辑:程序博客网 时间:2024/04/29 23:07
Edge Detection
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 15597
Accepted: 3518
Description
IONU SatelliteImaging, 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 inthe image, as described below, and outputs another compressed image of thedetected edges.
A simple edge detection algorithm sets an output pixel's value to be themaximum absolute value of the differences between it and all its surroundingpixels in the input image. Consider the input image below:
The upper leftpixel in the output image is the maximum of the values |15-15|,|15-100|, and|15-100|, which is 85. The pixel in the 4th row, 2nd column is computed as themaximum of |175-100|, |175-100|, |175-100|, |175-175|, |175-25|,|175-175|,|175-175|, and |175-25|, which is 150.
Images contain 2 to 1,000,000,000 (109) pixels. All images areencoded using run length encoding (RLE). This is a sequence of pairs,containing pixel value (0-255) and run length (1-109). Input imageshave at most 1,000 of these pairs. Successive pairs have different pixelvalues. All lines in an image contain the same number of pixels.
Input
Input consists ofinformation for one or more images. Each image starts with the width, inpixels, of each image line. This is followed by the RLE pairs, one pair perline. A line with 0 0 indicates the end of the data for that image. An imagewidth of 0 indicates there are no more images to process. The first image inthe example input encodes the 5x7 input image above.
Output
Output is a seriesof edge-detected images, in the same format as the input images, except thatthere may be more than 1,000 RLE pairs.
Sample Input
7
15 4
100 15
25 2
175 2
25 5
175 2
25 5
0 0
10
35 500000000
200 500000000
0 0
3
255 1
10 1
255 2
10 1
255 2
10 1
255 1
0 0
0
Sample Output
7
85 5
0 2
85 5
75 10
150 2
75 3
0 2
150 2
0 4
0 0
10
0 499999990
165 20
0 499999990
0 0
3
245 9
0 0
0
Hint
A brute forcesolution that attempts to compute an output value for every individual pixelwill likely fail due to space or time constraints.
Source
Mid-Central USA 2000
Edge Detection
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 15597
Accepted: 3518
Description
IONU 卫星图像股份有限公司。利用行程编码记录并保存着大量的图片。你的任务是编写一个程序,读取一个压缩图片的边缘数据,如下,然后输出另一个压缩图片的边缘检测。
一种简单的边缘检测算法,求得一个像素点与周围点做差的最大值。考虑下面的输入图像:
左上角像素输出值是|15-15|,|15-100|, 和|15-100|的最大值85,。像素在第四行第二列输出值是|175-100|,|175-100|, |175-100|, |175-175|, |175-25|, |175-175|,|175-175|, 和 |175-25|的最大值,是150.图像包括2到1,000,000,000 (109)个像素。所有的图片的编码格式都是行程编码(RLE)。这是一对序列,包括像素值(0-255)和行程(1-109).输入图片有至少1000对。连续对有不同的像素值,图像中的每条线包含相同的像素值。Input
舒鸿儒包含一个或者多个图片信息。每个图片第一行输入是图片宽度。接下来输入的是RLE对,一对占一行。以0 0作为一幅图片的完结。一幅图片以0作为宽度则所有输入完毕。第一个示例的图片是一个5*7的图片。
Output
输出是一系列的边缘检测的图片,与输入图片同格式,RLE对不会超过1000对。
Sample Input
7
15 4
100 15
25 2
175 2
25 5
175 2
25 5
0 0
10
35 500000000
200 500000000
0 0
3
255 1
10 1
255 2
10 1
255 2
10 1
255 1
0 0
0
Sample Output
7
85 5
0 2
85 5
75 10
150 2
75 3
0 2
150 2
0 4
0 0
10
0 499999990
165 20
0 499999990
0 0
3
245 9
0 0
0
Hint
爆搜会mle,tle
Source
Mid-Central USA 2000
这道题....咳咳,真心蛋疼,参考了http://blog.csdn.net/lyy289065406/article/details/6648671这里的程序,然后参考了http://liangsun.org/posts/poj-1009-edge-detection-report/这里的证明,这个方法真心好,不过据说慢慢模拟的方法可以0ms.......不过那写起来太累了......俺偷懒了,偷过头了,基本就参考人家程序了,然后还出各种错误。
本来想法也就是每一个突变点周围九个点都算一下编码,然后排个序,排序结果也是突变位置后面减前面。但是没想到最后一个数据也要考虑,这就导致偶尔需要算左下角那两个点....于是少个等号死了好几回......证明方法是反证,挺好懂的.......
代码,基本跟参考的那里差不多了.....写出来才发现......:
#include<iostream>#include<cmath>#include<algorithm>#include <stdio.h>#include <string.h>int Pnum;int total;int impair[1111][2];int outpair[8888][2];int width;int getvalue(int pos);int Coder(int pos);void qsort_my(int l, int h, int outpair[1111][2]);int main(void){// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);int k = 0;while(scanf("%d", &width) && width){ k = total = 0;while(scanf("%d%d", &impair[k][0], &impair[k][1]) && impair[k][1]) {total += impair[k][1];k++;}//for (int i = 0;i < k ; i++) printf("impair[0]:%d, impair[1]%d\n", impair[i][0], impair[i][1]);printf("%d\n", width);// printf("total:%d\n", total);int pos = 1;Pnum = k;k = 0;for (int i = 0;i <=Pnum ;i ++){int row = (pos - 1) / width;int column = (pos - 1) % width;for (int j = row - 1; j <= row + 1; j ++)for (int t = column - 1; t <= column + 1; t++){int npos = j * width + t;if (j < 0 || t < 0 || t >= width || npos >= total)continue;outpair[k][1] = npos + 1;outpair[k++][0] = Coder(npos + 1);} pos += impair[i][1];// printf("pos = %d", pos);}// printf("%d\n", k); qsort_my(0, k, outpair);// for (int i = 0;i < k ;i ++)// {// printf("outp:%d, outn:%d\n", outpair[i][0], outpair[i][1]);// } int kiss = 1; int i; for (i = 0;i < k-1;i ++) { if (outpair[i+1][0] != outpair[i][0]) { printf("%d %d\n", outpair[i][0], outpair[i+1][1] - kiss); kiss = outpair[i+1][1]; } } printf("%d %d\n", outpair[i][0], total - kiss+1); printf("0 0\n");} printf("0\n");}void qsort_my(int l, int h, int outpair[1111][2]){ if (h < l + 2) return; int e = h, p = l; while(l < h) { while(++l < e && outpair[l][1] <= outpair[p][1]); while(--h > p && outpair[h][1] >= outpair[p][1]); if (l < h) { int temp = outpair[l][0]; outpair[l][0] = outpair[h][0]; outpair[h][0] = temp; temp = outpair[l][1]; outpair[l][1] = outpair[h][1]; outpair[h][1] = temp; } } int temp = outpair[h][0]; outpair[h][0] = outpair[p][0]; outpair[p][0] = temp; temp = outpair[h][1]; outpair[h][1] = outpair[p][1]; outpair[p][1] = temp; qsort_my(p, h, outpair); qsort_my(l, e, outpair);}int getvalue(int pos){int p = 0, i = 0;while( p < pos){p += impair[i++][1];}return impair[i-1][0];}int Coder(int pos){int value = getvalue(pos);// printf("value:%d", value);int maxabs = 0;int row = (pos - 1) / width;int column = (pos - 1) % width;for (int i = row - 1; i <= row + 1;i ++)for (int j = column - 1; j <= column + 1;j ++){int npos = width * i + j;if (i < 0 || j < 0 || j >= width || npos >= total || npos == pos - 1) continue;int Ccode = getvalue(npos+1);// printf("pos:%d, value:%d, Ccode:%d\n", pos, value, Ccode);if (maxabs < abs(value - Ccode))maxabs = abs(value - Ccode);} return maxabs;}
- POJ 1009 Edge Detection
- poj 1009 Edge Detection
- poj 1009 Edge Detection
- POJ 1009 Edge Detection
- POJ-1009-Edge Detection
- [POJ][1009]Edge Detection
- POJ 1009: Edge Detection
- POJ 1009 Edge Detection
- POJ 1009--Edge Detection
- POJ 1009Edge Detection
- POJ 1009 Edge Detection
- POJ 1009--Edge Detection
- POJ 1009 Edge Detection
- poj 1009 Edge Detection (未完成)
- poj 1009 Edge Detection 模拟
- POJ 1009 Edge Detection 笔记
- POJ 1009 解题报告 Edge Detection
- POJ 1009 Edge Detection解题报告
- HDU 4603
- 删除数据库中所有存储过程和函数的sql语句
- Unique Paths II
- 设计模式C++描述----21.解释器(Iterpreter)模式
- 带有静态方法的类(java中的math类)
- poj 1009 Edge Detection
- 通过UNC路径 方式访问的,怎么删出保存的密码?
- ubuntu下配置静态IP上网
- iOS模拟器中添加图片
- Vim超实用集锦
- 【商业源码】生日大放送
- linux下安装jsoncpp
- 使用Dropbox提高个人数据管理效率
- [二叉树专题]:递归求解二叉树的高度