1011 -- RLE解码

来源:互联网 发布:懒角落 淘宝 编辑:程序博客网 时间:2024/05/15 06:44

RLE解码

Time Limit:1000MS  Memory Limit:132768K
Total Submit:224 Accepted:61

Description

在计算机中,图像通常是用矩阵表示的,矩阵中的每一个元素表示了图像中在相应位置上的像素值。而为了节约空间,图像文件一般都不是直接存储在外存中,而是进行压缩后再存储在硬盘上的。在众多的图像压缩算法中,RLE压缩算法是一种使用频率很高的算法,它的原理也简单,就是是将一串连续的相同数据转化为特定的格式达到压缩的目的。如果有一幅5*5图像的内容是:

1 1 1 2 2
2 2 2 4 8
8 8 1 3 3
3 3 3 3 9
0 0 0 0 0

那么,用RLE压缩后的表示如下:

1 3
2 5
4 1
8 3
1 1
3 6
9 1

你的任务是,将压缩后的图像解压。

Input

输入的信息描述了一幅压缩后的图片,第一行是一个整数,代表着这幅图片的宽度,再接下来就是RLE数据了。
RLE数据由若干行组成,每一行的形式为:x y,
其中,x,y整数,并且都小于10000;当x和y都为0时, 表示输入结束。

Output

压缩前的图像,用矩阵表示,在矩阵中,同一行中相邻的两个数据用一个空格分隔。

Sample Input

51 32 54 18 31 13 69 1

Sample Output

1 1 1 2 22 2 2 4 88 8 1 3 33 3 3 3 90 0 0 0 0

Source

ahstu@ICPC03

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1011 {    class Program {        static void Main(string[] args) {            int n = int.Parse(Console.ReadLine());            int[] ans = new int[n * n + n + 10];            string s;            int k = 1;            while ((s = Console.ReadLine()) != null) {                string[] ss = s.Split();                int a = int.Parse(ss[0]);                int b = int.Parse(ss[1]);                for (int i = 0 ; i < b ; i++)                    ans[k++] = a;            }            for (int i = 1 ; i <= n * n ; i++) {                Console.Write(ans[i] + " ");                if (i % n == 0)                    Console.WriteLine();            }            //Console.ReadLine();        }    }}


0 0
原创粉丝点击