Java-POJ1009-Edge Detection(未完成,有C++代码)
RLE编码,还不会,先搬运一下大佬的代码,理解之后再用Java自己实现
#include <map>
#include <vector>
#include <cstdlib>
#include <iostream>
using namespace std;
static int around[][]= {{-,-},{-,},{-,},{,-},{,},{,-},{,},{,}};
map<int,int>::iterator a_It,b_It;
map<int,int> a,b;
vector<int> s;
int getValue(int index) {
int value=;
for(a_It = a.begin(); a_It != a.end(); a_It++) {
if(index<a_It->first) break;
value=a_It->second;
}
return value;
}
int getMax(int index,int width,int count) {
int center=getValue(index);
int h=index/width;
int max=;
for(int i=; i<; i++) {
int sub=index+around[i][]*width+around[i][];
if(h+around[i][]==sub/width && sub>= && sub<count) {
int a=getValue(sub);
max=abs(center-a)>max?abs(center-a):max;
}
}
return max;
}
void process(int width,int count) {
for(int i=; i < s.size(); i++) {
int index=s.at(i);
b.insert(pair<int,int>(index,getMax(index,width,count)));
}
}
int main() {
int width;
while(cin>>width && cout<<width<<endl && width) {
a.clear(),b.clear(),s.clear();
int v,l,count=;
while(cin>>v>>l && l) { //v有可能为0
a.insert(pair<int,int>(count,v));
count+=l;
}
for(a_It = a.begin(); a_It != a.end(); a_It++) {
for(int i=-; i<; i++) {
for(int j=-; j<; j++) {
int index=a_It->first+i*width+j;
if(index>= && index <count)
s.push_back(index);
}
}
}
s.push_back(width);
s.push_back(count-width);
process(width,count); b_It = b.begin();
int s=b_It->first;
int val=b_It->second;
b_It++;
for(; b_It != b.end(); b_It++) {
if(b_It->second != val) {
cout<<val<<" "<<b_It->first-s<<endl;
s=b_It->first;
val=b_It->second;
}
}
cout<<val<<" "<<count-s<<endl;
cout<<"0 0"<<endl;
}
return ;
}
Java-POJ1009-Edge Detection(未完成,有C++代码)的更多相关文章
- POJ1009 Edge Detection
题目来源:http://poj.org/problem?id=1009 题目大意: 某图像公司用run length encoding(RLE)的方式记录和存储了大量的图像.程序的目标是读入压缩后的图 ...
- 计算机视觉中的边缘检测Edge Detection in Computer Vision
计算机视觉中的边缘检测 边缘检测是计算机视觉中最重要的概念之一.这是一个很直观的概念,在一个图像上运行图像检测应该只输出边缘,与素描比较相似.我的目标不仅是清晰地解释边缘检测是怎样工作的,同时也提 ...
- 【数字图像分析】基于Python实现 Canny Edge Detection(Canny 边缘检测算法)
Canny 边缘检测算法 Steps: 高斯滤波平滑 计算梯度大小和方向 非极大值抑制 双阈值检测和连接 代码结构: Canny Edge Detection | Gaussian_Smoothing ...
- Image Processing and Analysis_8_Edge Detection:Edge Detection Revisited ——2004
此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...
- Edge Detection
Edge Detection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22604 Accepted: 5311 ...
- 轮廓检测论文解读 | Richer Convolutional Features for Edge Detection | CVPR | 2017
有什么问题可以加作者微信讨论,cyx645016617 上千人的粉丝群已经成立,氛围超好.为大家提供一个遇到问题有可能得到答案的平台. 0 概述 论文名称:"Richer Convoluti ...
- Edge detection using LoG
intensity梯度值分布跟图片的大小有关, 比如将一张小图片放大后会变得很模糊, 原先清晰的edge, 即大的梯度值变得模糊. 但是原有的边缘通常还是肉眼可分辨的. 但用Sobel 算子可能就检测 ...
- Java中替换HTML标签的方法代码
这篇文章主要介绍了Java中替换HTML标签的方法代码,需要的朋友可以参考下 replaceAll("\\&[a-zA-Z]{0,9};", "").r ...
- java mail实现Email的发送,完整代码
java mail实现Email的发送,完整代码 1.对应用程序配置邮件会话 首先, 导入jar <dependencies> <dependency> <groupId ...
随机推荐
- Android之碎片Fragment
Fragment是个特别的存在,有点像报纸上的专栏,看起来只占据页面的一小块,但是这一小块有自己的生命周期,可以自行其是,仿佛独立王国,并且这一小块的特性无论在哪个页面,给一个位置就行,添加以后不影响 ...
- mnist识别优化——使用新的fashion mnist进行模型训练
今天通过论坛偶然知道,在mnist之后,还出现了一个旨在代替经典mnist数据集的Fashion MNIST,同mnist一样,它也是被用作深度学习程序的“hello world”,而且也是由70k张 ...
- Spring Boot源码(一):去除web.xml
访问https://spring.io/ spring boot中: public class MyWebApplicationInitializer implements WebApplicatio ...
- 集合使用 Iterator 删除元素
针对常见的数据集合,比如 ArrayList 列表,对其进行遍历,删除其中符合条件的某个元素,使用 iterator 迭代器进行迭代,代码如下: public class PracticeContro ...
- CCS 5.5下载地址http://www.dianyuan.com/bbs/1492792.html
http://www.dianyuan.com/bbs/1492792.html https://pan.baidu.com/s/1eQtIRK2?errno=0&errmsg=Auth%20 ...
- Android_AsyncTask异步类
·AsyncTask是一个轻量级的异步抽象类 ·Android程序刚启动时,会同时启动一个像一个的主线程,这个主线程主要负责处理与UI有关的事件,有时也被称为UI线程,Android app中必须遵循 ...
- Conference deadlines
1. NLP/IR/DM/ML Conference Deadlines(Updating) Two Principles of Deadlines:1. All deadlines converge ...
- Yarn报错:Could not find any valid local directory for nmPrivate/
原因: yarn.nodemanager.local-dirs和hadoop的hadoop.tmp.dir参数对应文件位置不一致 解决办法: 将hdfs-site.xml中hadoop.tmp.dir ...
- HDU1548 奇怪的电梯(bfs求最少)
There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 ...
- Win7最后一天,微软开始慌了!
就在昨天(2020年1月14日),服役十年的Win 7正式退出了微软舞台,从2009推出到2019,这十年也是很多90后的青春. 当然微软官方也做了送别,当然其目的也是为了推广Win10! 甚至面对痛 ...