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. [cocos2dx]怎样将Android手机游戏移植到电视?

    近期智能电视很火,我也买了一个小米电视,看片效果不错,网络也还算给力.可是,玩游戏比較蛋疼,要用遥控器,下了一个捕鱼达人试玩了一把,要用方向键控制大炮的方向和远近,再用确定键发射炮弹,根本没法玩... ...

  2. VS 统计代码行数

    使用正则表达式 :    ^:b*[^:b#/]+.*$ 简单说明如下: ^:行头 $:行尾 +:一个或多个 *:0个或多个 :b:表示空白,匹配空格或者制表符 # 表示后面是include,/表示注 ...

  3. POJ 2376 Cleaning Shifts 贪心

    Cleaning Shifts 题目连接: http://poj.org/problem?id=2376 Description Farmer John is assigning some of hi ...

  4. Understanding Linux Kernel version 3 读书笔记

    P30, preemptive  kernel .kernel threading 和Multithreaded application support没太好理解,我想如果设计个多线程的程序来运行运行 ...

  5. C 语言指针怎么理解?

    对于程序员来说内存可以简化成这样一种东西:&lt;img src="https://pic1.zhimg.com/4d060c3f67c22cd4b07273db00f64708_b ...

  6. 使用mysqladmin ext 了解MySQL运行状态 转

    https://yq.aliyun.com/articles/11210?spm=0.0.0.0.HpobXF 1. 使用-r/-i参数 使用mysqladmin extended-status命令可 ...

  7. 终端I/O之综述

    终端I/O有两种不同的工作模式: 规范模式输入处理(Canonical mode input processing).在这种模式中,终端输入以行为单位进行处理.对于每个读要求,终端驱动程序最多返回一行 ...

  8. 分享10款常用的jQuery焦点图插件

    爱编程一直在收集整理编程相关的知识和解决方案,今天小编为大家带来10款非常常用的jquery焦点图插件. 1.jQuery可自动播放动画的焦点图插件 之前我们已经分享过很多非常实用的jQuery焦点图 ...

  9. Android 之 权限 uses-permission 设置

    Manifest.permission 官方API说明: http://developer.android.com/reference/android/Manifest.permission.html ...

  10. C#基础--局部类型Partial

    局部类型 原本来在同一个命名(namespace)空间下  是不允许相同的类(class)名存在的  但是partial关键字可以允许在同一个namespace下有想通过的类名存在 写法 下面的两个不 ...