Question:http://poj.org/problem?id=1009
问题点:RLE编码。
 Memory: 648K        Time: 547MS
Language: C++ Result: Accepted #include <iostream>
#include <cstdlib>
#include <map>
#include <vector>
using namespace std; map<int,int> mp;
map<int,int> omp;
map<int, int>::iterator mp_Iter;
map<int, int>::iterator omp_Iter;
vector<int> st;
static int around[][]={{-,-},{-,},{-,},{,-},{,},{,-},{,},{,}};
int getValue(int index)
{
int value=;
for(mp_Iter = mp.begin(); mp_Iter != mp.end(); mp_Iter++)
{
if(index<mp_Iter->first) break;
value=mp_Iter->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 < st.size(); i++)
{
int index=st.at(i);
omp.insert(pair<int,int>(index,getMax(index,width,count)));
}
}
int main()
{
int width;
while(cin>>width && cout<<width<<endl && width)
{
mp.clear();
omp.clear();
st.clear();
int v,l,count=;
while(cin>>v>>l && l){//v有可能为0
mp.insert(pair<int,int>(count,v));
count+=l;
}
for(mp_Iter = mp.begin(); mp_Iter != mp.end(); mp_Iter++)
{
for(int i=-;i<;i++)
{
for(int j=-;j<;j++)
{
int index=mp_Iter->first+i*width+j;
if(index>= && index <count)
st.push_back(index);
}
}
}
st.push_back(width);
st.push_back(count-width);
process(width,count); omp_Iter = omp.begin();
int st=omp_Iter->first;
int val=omp_Iter->second;
omp_Iter++;
for(;omp_Iter != omp.end(); omp_Iter++)
{
if(omp_Iter->second != val)
{
cout<<val<<" "<<omp_Iter->first-st<<endl;
st=omp_Iter->first;
val=omp_Iter->second;
}
}
cout<<val<<" "<<count-st<<endl;
cout<<"0 0"<<endl;
}
return ;
}

 

北大ACM(POJ1009-Edge Detection)的更多相关文章

  1. POJ1009 Edge Detection

    题目来源:http://poj.org/problem?id=1009 题目大意: 某图像公司用run length encoding(RLE)的方式记录和存储了大量的图像.程序的目标是读入压缩后的图 ...

  2. 北大ACM - POJ试题分类(转自EXP)

    北大ACM - POJ试题分类 -- By EXP 2017-12-03 转载请注明出处: by EXP http://exp-blog.com/2018/06/28/pid-38/ 相关推荐文: 旧 ...

  3. Edge detection using LoG

    intensity梯度值分布跟图片的大小有关, 比如将一张小图片放大后会变得很模糊, 原先清晰的edge, 即大的梯度值变得模糊. 但是原有的边缘通常还是肉眼可分辨的. 但用Sobel 算子可能就检测 ...

  4. 北大 ACM 分类 汇总

    1.搜索 //回溯 2.DP(动态规划) 3.贪心 北大ACM题分类2009-01-27 1 4.图论 //Dijkstra.最小生成树.网络流 5.数论 //解模线性方程 6.计算几何 //凸壳.同 ...

  5. 计算机视觉中的边缘检测Edge Detection in Computer Vision

    计算机视觉中的边缘检测   边缘检测是计算机视觉中最重要的概念之一.这是一个很直观的概念,在一个图像上运行图像检测应该只输出边缘,与素描比较相似.我的目标不仅是清晰地解释边缘检测是怎样工作的,同时也提 ...

  6. 【数字图像分析】基于Python实现 Canny Edge Detection(Canny 边缘检测算法)

    Canny 边缘检测算法 Steps: 高斯滤波平滑 计算梯度大小和方向 非极大值抑制 双阈值检测和连接 代码结构: Canny Edge Detection | Gaussian_Smoothing ...

  7. Image Processing and Analysis_21_Scale Space:Edge Detection and Ridge Detection with Automatic Scale Selection——1998

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  8. Image Processing and Analysis_8_Edge Detection:Edge Detection Revisited ——2004

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  9. Image Processing and Analysis_8_Edge Detection:Local Scale Control for Edge Detection and Blur Estimation——1998

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  10. Image Processing and Analysis_8_Edge Detection: Optimal edge detection in two-dimensional images ——1996

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

随机推荐

  1. C++组合问题

    求一个组合,如C(16,3),我们可以通过公式求出这有多少个数,但怎么把这些数表示出来呢? 代码: #include<iostream> #include<stdio.h> # ...

  2. os.getcwd()

    1.os.getcwd():获取当前工作目录,也就是在哪个目录下运行这个程序.举例来说:假设F:\aaa\bbb\ccc目录下有个文件 TestDir.py,打印当前工作目录.进入windows命令行 ...

  3. jqery和js如何判断checkbox是否选中

    jquery: <div id="divId" class="divTable"> <div class="tableBody&qu ...

  4. MVC网站发布常见问题

    直接发布的时候生成的bin会漏掉一些文件,从而导致网站无法访问: 解决方法:发布之后,再在本地运行一下网站,然后将运行后生成的bin文件夹下的文件拷贝到发布的文件夹目录下进行覆盖,就可以了

  5. linux C高手成长过程---书籍推荐

    建议学习路径: 首先先学学编辑器,vim, emacs什么的都行. 然后学make file文件,只要知道一点就行,这样就可以准备编程序了. 然后看看<C程序设计语言>K&R,这样 ...

  6. 《计算机问题求解》总结——2014年CCF计算机课程改革导教班(2014.07.11)

    一:引言     "心想事成".这是自己获得导教班学习机会的最佳概括.2013年年末学习李晓明老师的<人群与网络>课程:随后网络认识烟台大学贺利坚老师,了解到2013年 ...

  7. 网站性能扩展案例:每天30-50亿请求,300K QPS是如何炼成的

    Reduce Data广告服务网站(http://reducedata.com)如何扩展到每天300K QPS请求?分享经验如下: 1. 为大规模而设计,广告服务平台从一开始增长就很惊人,因此,系统开 ...

  8. LFS7.4编译笔记(2)

    上一篇我们已经搭建好了临时系统,这一篇我们就开始正式构建我们的最终LFS系统. 首先切换到root,准备虚拟内核文件系统并挂载: su - export LFS=/mnt/lfs mkdir -pv ...

  9. 【JavaScript】Javascript中的函数声明和函数表达式

    Javascript有很多有趣的用法,在Google Code Search里能找到不少,举一个例子: <script> ~function() { alert("hello, ...

  10. Mingw:在Linux系统下编译Windows的程序

    Ubuntu下可以直接安装: sudo apt-get install mingw32 mingw32-binutils mingw32-runtime 安装后编译程序可以: i586-mingw32 ...