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. wpa_supplicant 移植及 linux 命令行模式配置无线上网

    本文涉及内容为linux 命令行模式配置无线上网 及 wpa_supplicant 移植到开发板的过程,仅供参考. 1.源码下载 wpa_supplicant 源码下载地址 :http://hosta ...

  2. poj 1845 Sumdiv 约数和定理

    Sumdiv 题目连接: http://poj.org/problem?id=1845 Description Consider two natural numbers A and B. Let S ...

  3. cdoj 1141 酱神寻宝 状压dp

    酱神寻宝 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1141 Descri ...

  4. [Jobdu] 题目1527:首尾相连数组的最大子数组和

    题目描述: 给定一个由N个整数元素组成的数组arr,数组中有正数也有负数,这个数组不是一般的数组,其首尾是相连的.数组中一个或多个连续元素可以组成一个子数组,其中存在这样的子数组arr[i],…arr ...

  5. 识货的拿走:Android游戏框架解读之总体结构

    Android游戏开发的框架图无偿奉上.

  6. 搭建一个全栈式的HTML5移动应用框架(纯干货,亲!)

    打开HTML5的技术网站,满屏的“5个推荐的JavaScript框架”.“10个移动应用框架”,全都是你妹的框架, 但是,你知道这些框架是干毛用的吗?来吧,我们来梳理一下吧 目前HTML5涉及的框架大 ...

  7. Cocos2d-html5 笔记2: director

    今天看了cocos2d-html5代码里面的Director. 最简单的框架 先抛开cocos2d的框架不说,对于一个游戏来说,基本的逻辑框架还是很简单的,首先初始化的时候注册mouse, touch ...

  8. Linux开机执行顺序

      1. 加载 BIOS 的硬件信息,并取得第一个开机装置的代号: 2. 读取第一个开机装置的 MBR 的 boot Loader (亦即是 lilo, grub 等等) 的开机信息: 3. 加载 K ...

  9. Lucene的DocFieldProcessor类

    DocFieldProcessor类的任务1 按顺序存储所有的field和对应的fieldinfo2 为当前这篇doc的field按照fieldname来建立hash索引3 调用InvertedDoc ...

  10. IPC——信号

    Linux进程间通信——使用信号 一.什么是信号 用过Windows的我们都知道,当我们无法正常结束一个程序时,可以用任务管理器强制结束这个进程,但这其实是怎么实现的呢?同样的功能在Linux上是通过 ...