SDUT 2235顺序表应用2:多余元素删除之建表算法

本文介绍了一种在原顺序表空间基础上去除重复元素的算法,实现了将非纯表转化为纯表的过程,通过优化输入判断避免了不必要的循环,降低了时间复杂度。

顺序表应用2:多余元素删除之建表算法

Time Limit: 3MS Memory Limit: 600KB
Problem Description
一个长度不超过10000数据的顺序表,可能存在着一些值相同的“多余”数据元素(类型为整型),编写一个程序将“多余”的数据元素从顺序表中删除,使该表由一个“非纯表”(值相同的元素在表中可能有多个)变成一个“纯表”(值相同的元素在表中只保留第一个)。
要求:
       1、必须先定义线性表的结构与操作函数,在主函数中借助该定义与操作函数调用实现问题功能;
       2、本题的目标是熟悉在顺序表原表空间基础上建新表的算法,要在原顺序表空间的基础上完成完成删除,建表过程不得开辟新的表空间;
       3、不得采用原表元素移位删除的方式。
Input
 第一行输入整数n,代表下面有n行输入;
之后输入n行,每行先输入整数m,之后输入m个数据,代表对应顺序表的每个元素。
Output
  输出有n行,为每个顺序表删除多余元素后的结果
Example Input
4
5 6 9 6 8 9
3 5 5 5
5 9 8 7 6 5
10 1 2 3 4 5 5 4 2 1 3
Example Output
6 9 8
5
9 8 7 6 5
1 2 3 4 5
Hint
本题跟3324题目要求一样,但是要求的时间复杂度更低,所以可以将删除问题改为输入时判断是否有重复的问题,如果重复则不将数字放入顺序表内,这样可以减少一层循环,从而降低时间复杂度。
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
//typedef int ElemType;
typedef struct
{
    int data[10005];
    int length;
}node;
void create(node *&L,int n)
{
    int cnt=0,num,flag;
    L=(node *)malloc(sizeof(node));
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num);
        flag=1;
        for(int j=0;j<cnt;j++)//要注意该循环下限为当前顺序表的长度
        {

            if(L->data[j]==num)
            {
                flag=0;
                break;
            }
        }
        if(flag==1)
        {
            L->data[cnt]=num;
            cnt++;
        }
    }
    L->length=cnt;
}
int main()
{
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        node *L;
        scanf("%d",&n);
        create(L,n);
        for(int i=0;i<L->length-1;i++)
            printf("%d ",L->data[i]);
        printf("%d\n",L->data[L->length-1]);
    }
    return 0;
}


The MSC313E is a highly integrated SOC. Based on ARM Cortex-A7, the MSC313E integrates Image Signal Processor (ISP), Color Engine, Video (H.265/H.264/MJPEG) Encoders and other useful peripherals for IP camera applications. A typical utilization of the MSC313E application processor is demonstrated in the following block diagram. The complete system includes a camera module (CMOS sensor), a connectivity module (WiFi or Ethernet), and a non-volatile storage (NOR flash or SD card). The ISP and Color Engine handle images captured from the camera sensor, and the video stream is composed of lots ages. There are pre- and po - video processing stages. The pre-video processing rotates images, reduces noises, enhances signals and translates color domains. The post-video processing corrects lens distortion, adjusts color quality, and generates multiple video streams with different resolutions. Multimedia Encoders can compress those video streams with different compressing standards at the same time. The well compressed video/audio streams could be streamed or stored in the cloud server through Wi-Fi or Ethernet or stored in a local SD Card. The NOR flash is usually reserved for operating system and application software. Moreover, other peripherals like SAR/Audio ADC, UARTs and SPI are supported to realize applications with maximal flexibility. Besides, the MSC313E supports secure booting and personalization authentication mechanism for securing system. The AES/DES/3DES cipher engines could also help encrypt the compressed video/audio streams to protect privacy.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值