题目大意:边缘检测
IONU卫星成像公司,公司记录和储存非常大的图片使用行程编码,你需要编写一个程序读取被压缩的图像,发现图像的边缘,描述如下,并且输出另一个发现的边缘压缩图像。
一个简单的边缘检测算法设置输出像素的值是它最大的差的绝对值与周围像素的,观看下面的图像

图像包含2-10^9个像素点,所有的像素值都在(0-255)之间,不过为了方便存储,使用相同的数字压缩到一起方式,比如上面图像第一行有4个15可以写成15 4,计算出来最终的图像,也是用压缩的方式写出来
分析:很明显不能够把图像还原,太占内存了,也没有办法计算,再想想吧........
发现可法通过判断上下是否属于同一集合来做,但是首位需要单独考虑,试试吧
8个小时,真心很麻烦啊,不过对了,嘎嘎,好爽
#include<iostream>
#include<queue>
#include<cmath>
#include<algorithm>
#include<string.h>
using namespace std; #define maxn 1005
#define INF 0xfffffff int dir[9][2] = {
    {-1,-1},{-1, 0},{-1, 1},
    { 0,-1},{ 0, 0},{ 0, 1},
    { 1,-1},{ 1, 0},{ 1, 1}
}; struct Set
{
    int L, R;
    int vl, cnt;
}a[maxn]; struct node
{
    int vl, cnt;
}; struct SQLine
{
    int Up, Down;
}; int FindSet(int L, int R, int e);           //查找e在第几个区间
int MaxAbs(int k, int wide, int Len, int n);                //与四周相比最大的绝对值
int FindLocation(int L, int R, int wide, int l, int r);   //查找与e相等的最右边的位置
node Fill(int k, int wide, int cnt, int Len, int n);        //填充
int OK(int x, int y, int wide, int Len);    //判断xy坐标是否合法 int main()
{
    int wide;     while(cin >> wide)
    {
        int n=1;
        node s;
        queue<node> Q;         if(wide == 0)
        {
            cout << "0" <<endl;
            continue;
        }
        a[0].L = -INF, a[0].R = -1;
        while(cin >> a[n].vl >> a[n].cnt, a[n].vl+a[n].cnt)
        {
            a[n].L = a[n-1].R+1;
            a[n].R = a[n-1].R+a[n].cnt;
            n++;
        }
        a[n].L = a[n-1].R+1, a[n].R=INF;
        int k=0, End = a[n-1].R;
        while(k <= End)
        {
            int indexK = FindSet(0, n, k);             int Len = FindLocation(k, a[indexK].R, wide, 0, n);             Q.push(Fill(k++, wide, 1, End/wide+1, n));             if(Len - k == 0)
                Q.push(Fill(k++, wide, 1, End/wide+1, n));
            else if(Len - k > 0)
            {
                Q.push(Fill(k, wide, Len-k, End/wide+1, n));
                Q.push(Fill(Len, wide, 1, End/wide+1, n));
                k = Len+1;
            }
        }
        s.cnt = s.vl = 0;
        Q.push(s);
        s = Q.front();
        s.cnt = 0;         cout << wide <<endl;         while(Q.size())
        {
            node q = Q.front();Q.pop();
            if(s.vl == q.vl)
                s.cnt += q.cnt;             if(s.vl != q.vl || Q.size() == 0)
            {
                cout<< s.vl << ' ' << s.cnt <<endl;
                s = q;
            }             if(Q.size() == 0)
                cout << "0 0" <<endl;
        }
    }     return 0;
} int FindSet(int L, int R, int e)           //查找e在第几个区间
{
    while(L<=R)
    {
        int Mid = (L+R) / 2;         if(e >= a[Mid].L && e <= a[Mid].R)
            return Mid;
        else if(e < a[Mid].L)
            R = Mid-1;
        else
            L = Mid+1;
    }     return 0;
}
int MaxAbs(int k, int wide, int Len, int n)                //与四周相比最大的绝对值
{
    int i, x = k/wide, y=k%wide;
    int MaxNum=0;
    int t = FindSet(0, n, k);     for(i=0; i<9; i++)
    {
        int nx = x+dir[i][0];
        int ny = y+dir[i][1];         if(OK(nx, ny, wide, Len))
        {
            int j = nx * wide + ny;
            j = FindSet(0, n, j);
            MaxNum = max(MaxNum, abs(a[t].vl - a[j].vl));
        }
    }     return MaxNum;
}
int OK(int x, int y, int wide, int Len)   //判断xy坐标是否合法
{
    if(x>=0&&x<Len && y>=0&&y<wide)
        return 1;
    return 0;
}
int FindLocation(int L, int R, int wide, int l, int r)   //查找与e相等的最右边的位置
{
    int Mid, up=FindSet(l, r, L-wide), down=FindSet(l, r, L+wide);
    int ans = L;     while(L <= R)
    {
        Mid = (L+R) / 2;         int i=FindSet(l, r, Mid-wide), j=FindSet(l, r, Mid+wide);         if(up == i && down == j)
            L = Mid+1, ans=Mid;
        else
            R = Mid-1;
    }     return ans;
}
node Fill(int k, int wide, int cnt, int Len, int n)        //填充
{
    node s;     s.vl = MaxAbs(k, wide, Len, n);
    s.cnt = cnt;     return s;

}

poj1009的更多相关文章

  1. 【poj1009】 Edge Detection

    http://poj.org/problem?id=1009 (题目链接) 不得不说,poj上的水题还是质量非常高的= =,竟然让本大爷写了一下午. 转自:http://blog.sina.com.c ...

  2. POJ1009 Edge Detection

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

  3. 北大poj- 1009

    Edge Detection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22835   Accepted: 5398 D ...

  4. poj 算法 分类

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 最近AC题:2528   更新时间:2011.09.22  ...

  5. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  6. 北大ACM试题分类+部分解题报告链接

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

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

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

  8. 北大ACM - POJ试题分类

    1.入门水题 可用于练手与增强自信 POJ-1003POJ-1004 POJ-1005 POJ-1207 POJ-3299 POJ-2159 POJ-1083POJ-3094 2.初级 2.1. 基本 ...

  9. poj1000-1009小结

    poj1000-1009小结 poj1000-1009小结 poj1000 AB poj1001 Exponentiation poj1002 poj1003 poj1004 Financial Ma ...

随机推荐

  1. IE6 png兼容问题

    1.IE6 png  <!--[if IE 6]>  <script src="../js/png.js" type="text/javascript& ...

  2. jdk配置环境变量(windows)

    1.配置环境变量:右击"我的电脑"-->"高级"-->"环境变量"1)在系统变量里新建"JAVA_HOME" ...

  3. SGU 195. New Year Bonus Grant

    时间限制:0.75s 空间限制:4M 题意: 在一颗树(最多500000个节点)中,可以对节点染色,但是一个节点染了色后,它的父节点和兄弟节点都不能再染了,求最大的染色节点数,并输出所有染色节点. S ...

  4. 使用BeanUtils组件

    使用BeanUtils组件 前提 1:导入commons-beanutils-1.8.3.jar        //根据  本人使用的是1.8.3的版本 2:导入日志包      //就是loggin ...

  5. 极光推送 api ios参数问题

    这是首个app项目,推送用的是极光推送jpush 由于用官方文档出现接收多条的问题,在网上找到一套封装好的,非常感觉这位开发者 //推送.指定人error_reporting(E_ALL^E_NOTI ...

  6. angular post发送请求和GET发送请求,服务器端接收不到信息的问题

    参数可能因为编码原因,服务器端无法接收到传递的值, 这时需要用到补丁来解决这个问题 1,下载一个http.patch.js文件,放入YII框架中的js/ng文件架内 2angularjs 创建模型部分 ...

  7. 2基本概念--python深度机器学习

    参考彭亮老师的视频教程:转载请注明出处及彭亮老师原创 视频教程: http://pan.baidu.com/s/1kVNe5EJ 基本概念:训练集,测试集,特征值,监督学习,非监督学习,半监督学习,分 ...

  8. VS自带的功能:性能和诊断

    先看一眼代码: using System; using System.Collections.Generic; using XCode; using XCode.Configuration; usin ...

  9. hbase 0.96 单机伪分布式配置文件及遇到的问题 find命令

    http://www.apache.org/dyn/closer.cgi/hbase/ 国外的站点下载速度慢,可以考虑国内的镜像网站~ 前面已经部署好了hadoop2.2.0单机伪分布式.必须先安装h ...

  10. hadoop2.2.0 单机伪分布式(含64位hadoop编译) 及 eclipse hadoop开发环境搭建

    hadoop中文镜像地址:http://mirrors.hust.edu.cn/apache/hadoop/core/hadoop-2.2.0/ 第一步,下载 wget 'http://archive ...